From fc4607ec20ae60907a7b980f146566b41e320b71 Mon Sep 17 00:00:00 2001 From: Christoph Cullmann Date: Wed, 29 May 2024 21:07:09 +0200 Subject: [PATCH] prepare for ZFS --- common.nix | 46 +++++++++------------------------ mini/configuration.nix | 8 +++--- neko/configuration.nix | 8 +++--- neko/hardware-configuration.nix | 5 ---- neko/install.txt | 7 +++++ 5 files changed, 27 insertions(+), 47 deletions(-) diff --git a/common.nix b/common.nix index fedcc6e..98c2200 100644 --- a/common.nix +++ b/common.nix @@ -25,8 +25,9 @@ in # (e.g. man configuration.nix or on https://nixos.org/nixos/options.html). system.stateVersion = "23.05"; # Did you read the comment? - # use the latest kernel - boot.kernelPackages = pkgs.linuxPackages_latest; + # use the latest kernel with ZFS support and enable that file system + boot.kernelPackages = config.boot.zfs.package.latestCompatibleLinuxPackages; + boot.supportedFilesystems = [ "zfs" ]; # Use the systemd-boot EFI boot loader. boot.loader.systemd-boot.enable = true; @@ -38,18 +39,21 @@ in # we want to be able to do a memtest boot.loader.systemd-boot.memtest86.enable = true; + # use systemd early + boot.initrd.systemd.enable = true; + # setup the console stuff early console.earlySetup = true; # swap to RAM zramSwap.enable = true; - # root file system from encrypted disk + # root file system in RAM fileSystems."/" = - { device = "/dev/mapper/crypt-system"; - fsType = "btrfs"; + { device = "none"; + fsType = "tmpfs"; neededForBoot = true; - options = [ "subvol=root" "noatime" "nodiratime" ]; + options = [ "defaults" "size=8G" "mode=755" ]; }; # nix store file system from encrypted disk @@ -95,32 +99,6 @@ in depends = [ "/data" ]; }; - # impermanence root setup - boot.initrd.postDeviceCommands = pkgs.lib.mkAfter '' - mkdir /btrfs_tmp - mount /dev/mapper/crypt-system /btrfs_tmp - if [[ -e /btrfs_tmp/root ]]; then - mkdir -p /btrfs_tmp/old_roots - timestamp=$(date --date="@$(stat -c %Y /btrfs_tmp/root)" "+%Y-%m-%-d_%H:%M:%S") - mv /btrfs_tmp/root "/btrfs_tmp/old_roots/$timestamp" - fi - - delete_subvolume_recursively() { - IFS=$'\n' - for i in $(btrfs subvolume list -o "$1" | cut -f 9- -d ' '); do - delete_subvolume_recursively "/btrfs_tmp/$i" - done - btrfs subvolume delete "$1" - } - - for i in $(find /btrfs_tmp/old_roots/ -maxdepth 1 -mtime +7); do - delete_subvolume_recursively "$i" - done - - btrfs subvolume create /btrfs_tmp/root - umount /btrfs_tmp - ''; - # keep some stuff persistent environment.persistence."/nix/persistent" = { hideMounts = true; @@ -554,8 +532,8 @@ in # aliases shellAliases = { # system build/update/cleanup - update = "sudo nixos-rebuild switch"; - upgrade = "sudo nixos-rebuild switch --upgrade"; + update = "sudo nixos-rebuild boot"; + upgrade = "sudo nixos-rebuild boot --upgrade"; gc = "sudo nix-collect-garbage --delete-older-than 7d"; verify = "sudo nix --extra-experimental-features nix-command store verify --all"; optimize = "sudo nix --extra-experimental-features nix-command store optimise"; diff --git a/mini/configuration.nix b/mini/configuration.nix index 44881cc..23f103c 100644 --- a/mini/configuration.nix +++ b/mini/configuration.nix @@ -17,10 +17,10 @@ # amd graphics hardware.opengl.extraPackages = with pkgs; [ amdvlk rocm-opencl-icd rocm-opencl-runtime ]; - # our hostname + # our hostname and an ID for ZFS networking.hostName = "mini"; + networking.hostId = "e925ccfb"; - # use NetworkManager - networking.useDHCP = false; - networking.networkmanager.enable = true; + # classic dhcpcd + networking.networkmanager.enable = false; } diff --git a/neko/configuration.nix b/neko/configuration.nix index 6e8d8e0..7c42433 100644 --- a/neko/configuration.nix +++ b/neko/configuration.nix @@ -17,10 +17,10 @@ # intel graphics hardware.opengl.extraPackages = with pkgs; [ intel-media-driver intel-compute-runtime ]; - # our hostname + # our hostname and an ID for ZFS networking.hostName = "neko"; + networking.hostId = "cf5a5ee6"; - # use NetworkManager - networking.useDHCP = false; - networking.networkmanager.enable = true; + # classic dhcpcd + networking.networkmanager.enable = false; } diff --git a/neko/hardware-configuration.nix b/neko/hardware-configuration.nix index 62c1669..50fa14c 100644 --- a/neko/hardware-configuration.nix +++ b/neko/hardware-configuration.nix @@ -10,11 +10,6 @@ boot.initrd.kernelModules = [ "i915" ]; boot.kernelModules = [ "kvm-intel" ]; - # use the right soundcard - boot.extraModprobeConfig = '' - options snd_hda_intel enable=0,1 - ''; - # don't check for split locks, for KVM and Co. boot.kernelParams = [ "split_lock_detect=off" ]; diff --git a/neko/install.txt b/neko/install.txt index 646f1ef..66da359 100644 --- a/neko/install.txt +++ b/neko/install.txt @@ -21,6 +21,13 @@ nix --extra-experimental-features flakes --extra-experimental-features nix-comma sudo dd if=result/iso/nixos-24.05.20240108.317484b-x86_64-linux.iso of=/dev/sda bs=4M conv=fsync +# good ZFS links + +https://openzfs.github.io/openzfs-docs/Getting%20Started/NixOS/Root%20on%20ZFS.html +https://carjorvaz.com/posts/installing-nixos-with-root-on-tmpfs-and-encrypted-zfs-on-a-netcup-vps/ +https://astrid.tech/2021/12/17/0/two-disk-encrypted-zfs/ +https://mzhang.io/posts/2022-05-09-installing-nixos-on-encrypted-zfs/ + # # enable ssh for root #