From 0fce2524d72ea884673e20c3dceaf8d7f1271b8a Mon Sep 17 00:00:00 2001 From: Gerg-L Date: Thu, 9 Mar 2023 19:41:59 -0500 Subject: [PATCH] disko setup for gerg-desktop Thanks Lily! --- systems/gerg-desktop/default.nix | 3 +- systems/gerg-desktop/disko.nix | 210 ++++++++++++++++++++++++++ systems/gerg-desktop/zfs.nix | 52 +++++++ systems/gerg-desktop/zfs/default.nix | 122 --------------- systems/gerg-desktop/zfs/mount.sh | 19 --- systems/gerg-desktop/zfs/zfs_setup.sh | 105 ------------- 6 files changed, 264 insertions(+), 247 deletions(-) create mode 100644 systems/gerg-desktop/disko.nix create mode 100644 systems/gerg-desktop/zfs.nix delete mode 100644 systems/gerg-desktop/zfs/default.nix delete mode 100644 systems/gerg-desktop/zfs/mount.sh delete mode 100644 systems/gerg-desktop/zfs/zfs_setup.sh diff --git a/systems/gerg-desktop/default.nix b/systems/gerg-desktop/default.nix index 656efb2..43edf95 100644 --- a/systems/gerg-desktop/default.nix +++ b/systems/gerg-desktop/default.nix @@ -10,8 +10,9 @@ inputs: { (import ./vfio.nix inputs) (import ./parrot.nix inputs) (import ./spicetify.nix inputs) - (import ./zfs inputs) + (import ./zfs.nix inputs) (import ./containers inputs) + (import ./disko.nix inputs) ]; system.stateVersion = "unstable"; diff --git a/systems/gerg-desktop/disko.nix b/systems/gerg-desktop/disko.nix new file mode 100644 index 0000000..1af439b --- /dev/null +++ b/systems/gerg-desktop/disko.nix @@ -0,0 +1,210 @@ +_: { + disko.devices = { + disk = { + nvme0 = { + type = "disk"; + device = "/dev/disk/by-id/nvme-SHPP41-500GM_SSB4N6719101A4N22"; + content = { + type = "table"; + format = "gpt"; + partitions = [ + { + name = "boot"; + type = "partition"; + start = "0"; + end = "1M"; + part-type = "primary"; + flags = ["bios_grub"]; + } + { + name = "ESP"; + type = "partition"; + start = "1M"; + end = "1G"; + bootable = true; + content = { + type = "filesystem"; + format = "vfat"; + mountpoint = "/boot/efis/nvme-SHPP41-500GM_SSB4N6719101A4N22"; + }; + } + { + name = "zfsboot"; + type = "partition"; + start = "1G"; + end = "5G"; + content = { + type = "zfs"; + pool = "bpool"; + }; + } + { + name = "swap"; + type = "partition"; + start = "5G"; + end = "21G"; + content = { + type = "swap"; + randomEncryption = true; + }; + } + { + name = "zfsroot"; + type = "partition"; + start = "21G"; + end = "100%"; + content = { + type = "zfs"; + pool = "rpool"; + }; + } + ]; + }; + }; + nvme1 = { + type = "disk"; + device = "/dev/disk/by-id/nvme-SHPP41-500GM_SSB4N6719101A4N0E"; + content = { + type = "table"; + format = "gpt"; + partitions = [ + { + name = "BIOS"; + type = "partition"; + start = "0"; + end = "1M"; + part-type = "primary"; + flags = ["bios_grub"]; + } + { + name = "ESP"; + type = "partition"; + start = "1M"; + end = "1G"; + bootable = true; + content = { + type = "filesystem"; + format = "vfat"; + mountpoint = "/boot/efis/nvme-SHPP41-500GM_SSB4N6719101A4N0E"; + }; + } + { + name = "zfsboot"; + type = "partition"; + start = "1G"; + end = "5G"; + content = { + type = "zfs"; + pool = "bpool"; + }; + } + { + name = "swap"; + type = "partition"; + start = "5G"; + end = "21G"; + content = { + type = "swap"; + randomEncryption = true; + }; + } + { + name = "zfsroot"; + type = "partition"; + start = "21G"; + end = "100%"; + content = { + type = "zfs"; + pool = "rpool"; + }; + } + ]; + }; + }; + }; + zpool = { + rpool = { + type = "zpool"; + mode = "mirror"; + rootFsOptions = { + acltype = "posixacl"; + canmount = "off"; + compression = "zstd"; + dnodesize = "auto"; + normalization = "formD"; + relatime = "true"; + xattr = "sa"; + }; + options = { + ashift = "12"; + autotrim = "on"; + }; + datasets = { + "nixos" = { + zfs_type = "filesystem"; + options = { + canmount = "off"; + encryption = "on"; + keyformat = "passphrase"; + keylocation = "prompt"; + }; + }; + + "nixos/root" = { + zfs_type = "filesystem"; + options.mountpoint = "legacy"; + mountpoint = "/"; + }; + + "nixos/home" = { + zfs_type = "filesystem"; + options.mountpoint = "legacy"; + mountpoint = "/home"; + }; + "nixos/var" = { + zfs_type = "filesystem"; + options.mountpoint = "legacy"; + mountpoint = "/var"; + }; + "nixos/var/log" = { + zfs_type = "filesystem"; + options.mountpoint = "legacy"; + mountpoint = "/var/log"; + }; + "nixos/var/lib" = { + zfs_type = "filesystem"; + options.mountpoint = "legacy"; + mountpoint = "/var/lib"; + }; + }; + }; + bpool = { + type = "zpool"; + mode = "mirror"; + rootFsOptions = { + acltype = "posixacl"; + canmount = "off"; + compression = "lz4"; + devices = "off"; + normalization = "formD"; + relatime = "on"; + xattr = "sa"; + mountpoint = "/boot"; + }; + + options = { + compatibility = "grub2"; + ashift = "12"; + autotrim = "on"; + }; + datasets = { + "nixos/root" = { + zfs_type = "filesystem"; + options.mountpoint = "legacy"; + mountpoint = "/boot"; + }; + }; + }; + }; + }; +} diff --git a/systems/gerg-desktop/zfs.nix b/systems/gerg-desktop/zfs.nix new file mode 100644 index 0000000..b6058f8 --- /dev/null +++ b/systems/gerg-desktop/zfs.nix @@ -0,0 +1,52 @@ +_: { + config, + lib, + ... +}: { + boot = { + zfs = { + devNodes = "/dev/disk/by-id/"; + forceImportAll = true; + }; + kernelPackages = config.boot.zfs.package.latestCompatibleLinuxPackages; + kernelParams = ["nohibernate" "zfs.zfs_arc_max=17179869184"]; + supportedFilesystems = ["zfs" "vfat"]; + initrd = { + kernelModules = ["dm_mod"]; + availableKernelModules = ["hid_generic"]; + }; + plymouth.enable = false; + loader = { + timeout = lib.mkForce 10; + generationsDir.copyKernels = true; + + #override defaults + systemd-boot.enable = false; + efi.canTouchEfiVariables = false; + + grub = { + enable = true; + efiInstallAsRemovable = true; + version = 2; + copyKernels = true; + efiSupport = true; + zfsSupport = true; + mirroredBoots = [ + { + path = "/boot/efis/nvme-SHPP41-500GM_SSB4N6719101A4N0E"; + devices = ["/dev/disk/by-id/nvme-SHPP41-500GM_SSB4N6719101A4N0E"]; + } + { + path = "/boot/efis/nvme-SHPP41-500GM_SSB4N6719101A4N22"; + devices = ["/dev/disk/by-id/nvme-SHPP41-500GM_SSB4N6719101A4N22"]; + } + ]; + }; + }; + }; + systemd.services.zfs-mount.enable = false; + services.zfs = { + autoScrub.enable = true; + trim.enable = true; + }; +} diff --git a/systems/gerg-desktop/zfs/default.nix b/systems/gerg-desktop/zfs/default.nix deleted file mode 100644 index d4ac548..0000000 --- a/systems/gerg-desktop/zfs/default.nix +++ /dev/null @@ -1,122 +0,0 @@ -_: {config, ...}: { - boot = { - zfs.devNodes = "/dev/disk/by-id/"; - kernelPackages = config.boot.zfs.package.latestCompatibleLinuxPackages; - kernelParams = ["nohibernate" "zfs.zfs_arc_max=17179869184"]; - supportedFilesystems = ["zfs" "vfat"]; - initrd = { - kernelModules = ["dm_mod"]; - availableKernelModules = ["hid_generic"]; - }; - plymouth.enable = false; - loader = { - generationsDir.copyKernels = true; - - #override defaults - systemd-boot.enable = false; - efi.canTouchEfiVariables = false; - - grub = { - enable = true; - efiInstallAsRemovable = true; - version = 2; - copyKernels = true; - efiSupport = true; - zfsSupport = true; - mirroredBoots = [ - { - path = "/boot/efis/nvme-SHPP41-500GM_SSB4N6719101A4N0E"; - devices = ["/dev/disk/by-id/nvme-SHPP41-500GM_SSB4N6719101A4N0E"]; - } - { - path = "/boot/efis/nvme-SHPP41-500GM_SSB4N6719101A4N22"; - devices = ["/dev/disk/by-id/nvme-SHPP41-500GM_SSB4N6719101A4N22"]; - } - ]; - }; - }; - }; - systemd.services.zfs-mount.enable = false; - services.zfs = { - autoScrub.enable = true; - trim.enable = true; - }; - fileSystems = { - "/" = { - device = "rpool/nixos/root"; - fsType = "zfs"; - options = ["X-mount.mkdir"]; - }; - - "/home" = { - device = "rpool/nixos/home"; - fsType = "zfs"; - options = ["X-mount.mkdir"]; - }; - - "/var" = { - device = "rpool/nixos/var"; - fsType = "zfs"; - options = ["X-mount.mkdir"]; - }; - - "/var/lib" = { - device = "rpool/nixos/var/lib"; - fsType = "zfs"; - options = ["X-mount.mkdir"]; - }; - - "/var/log" = { - device = "rpool/nixos/var/log"; - fsType = "zfs"; - options = ["X-mount.mkdir"]; - }; - - "/boot" = { - device = "bpool/nixos/root"; - fsType = "zfs"; - options = ["X-mount.mkdir"]; - }; - - "/boot/efis/nvme-SHPP41-500GM_SSB4N6719101A4N0E" = { - device = "/dev/disk/by-id/nvme-SHPP41-500GM_SSB4N6719101A4N0E-part2"; - fsType = "vfat"; - options = [ - "X-mount.mkdir" - "x-systemd.idle-timout=1min" - "x-systemd.automount" - "noauto" - "nofail" - ]; - }; - "/boot/efis/nvme-SHPP41-500GM_SSB4N6719101A4N22" = { - device = "/dev/disk/by-id/nvme-SHPP41-500GM_SSB4N6719101A4N22-part2"; - fsType = "vfat"; - options = [ - "X-mount.mkdir" - "x-systemd.idle-timout=1min" - "x-systemd.automount" - "noauto" - "nofail" - ]; - }; - }; - swapDevices = [ - { - device = "/dev/disk/by-id/nvme-SHPP41-500GM_SSB4N6719101A4N0E-part4"; - discardPolicy = "both"; - randomEncryption = { - enable = true; - allowDiscards = true; - }; - } - { - device = "/dev/disk/by-id/nvme-SHPP41-500GM_SSB4N6719101A4N22-part4"; - discardPolicy = "both"; - randomEncryption = { - enable = true; - allowDiscards = true; - }; - } - ]; -} diff --git a/systems/gerg-desktop/zfs/mount.sh b/systems/gerg-desktop/zfs/mount.sh deleted file mode 100644 index 2334cc4..0000000 --- a/systems/gerg-desktop/zfs/mount.sh +++ /dev/null @@ -1,19 +0,0 @@ -#!/bin/sh -DISK='/dev/disk/by-id/nvme-SHPP41-500GM_SSB4N6719101A4N22 /dev/disk/by-id/nvme-SHPP41-500GM_SSB4N6719101A4N0E' -set -e -zpool import -f rpool -zpool import -f bpool -zfs load-key rpool/nixos -mount -t zfs rpool/nixos/root /mnt/ - -mount -t zfs rpool/nixos/home /mnt/home - -mount -t zfs rpool/nixos/var /mnt/var -mount -t zfs rpool/nixos/var/lib /mnt/var/lib -mount -t zfs rpool/nixos/var/log /mnt/var/log - -mount -t zfs bpool/nixos/root /mnt/boot - -for i in ${DISK}; do - mount -t vfat ${i}-part2 /mnt/boot/efis/${i##*/} -done diff --git a/systems/gerg-desktop/zfs/zfs_setup.sh b/systems/gerg-desktop/zfs/zfs_setup.sh deleted file mode 100644 index 959bc70..0000000 --- a/systems/gerg-desktop/zfs/zfs_setup.sh +++ /dev/null @@ -1,105 +0,0 @@ -#!/bin/sh -DISK='/dev/disk/by-id/nvme-SHPP41-500GM_SSB4N6719101A4N22 /dev/disk/by-id/nvme-SHPP41-500GM_SSB4N6719101A4N0E' - -INST_PARTSIZE_SWAP=16 -INST_PARTSIZE_RPOOL= - -set -e - -for i in ${DISK}; do - -blkdiscard -f $i - -sgdisk --zap-all $i -sgdisk -a1 -n1:24K:+1000K -t1:EF02 $i -sgdisk -n2:01M:+1G -t2:EF00 $i -sgdisk -n3:0:+4G -t3:BE00 $i -sgdisk -n4:0:+${INST_PARTSIZE_SWAP}G -t4:8200 $i - -if test -z $INST_PARTSIZE_RPOOL; then - sgdisk -n5:0:0 -t5:BF00 $i -else - sgdisk -n5:0:+${INST_PARTSIZE_RPOOL}G -t5:BF00 $i -fi - -sync && udevadm settle && sleep 3 - -cryptsetup open --type plain --key-file /dev/random $i-part4 ${i##*/}-part4 -mkswap /dev/mapper/${i##*/}-part4 -swapon /dev/mapper/${i##*/}-part4 -done - -zpool create \ --o compatibility=grub2 \ --o ashift=12 \ --o autotrim=on \ --O acltype=posixacl \ --O canmount=off \ --O compression=lz4 \ --O devices=off \ --O normalization=formD \ --O relatime=on \ --O xattr=sa \ --O mountpoint=/boot \ --R /mnt \ -bpool \ -mirror \ -$(for i in ${DISK}; do - printf "$i-part3 "; - done) - -zpool create \ --o ashift=12 \ --o autotrim=on \ --R /mnt \ --O acltype=posixacl \ --O canmount=off \ --O compression=zstd \ --O dnodesize=auto \ --O normalization=formD \ --O relatime=on \ --O xattr=sa \ --O mountpoint=/ \ -rpool \ -mirror \ -$(for i in ${DISK}; do - printf "$i-part5 "; - done) - -zfs create \ --o canmount=off \ --o mountpoint=none \ --o encryption=on \ --o keylocation=prompt \ --o keyformat=passphrase \ -rpool/nixos - -zfs create -o mountpoint=legacy rpool/nixos/root -mount -t zfs rpool/nixos/root /mnt/ - -zfs create -o mountpoint=legacy rpool/nixos/home -mkdir /mnt/home -mount -t zfs rpool/nixos/home /mnt/home - -zfs create -o mountpoint=legacy rpool/nixos/var -mkdir /mnt/var -mount -t zfs rpool/nixos/var /mnt/var -zfs create -o mountpoint=legacy rpool/nixos/var/lib -mkdir /mnt/var/lib -mount -t zfs rpool/nixos/var/lib /mnt/var/lib -zfs create -o mountpoint=legacy rpool/nixos/var/log -mkdir /mnt/var/log -mount -t zfs rpool/nixos/var/log /mnt/var/log - -zfs create -o mountpoint=none bpool/nixos -zfs create -o mountpoint=legacy bpool/nixos/root -mkdir /mnt/boot -mount -t zfs bpool/nixos/root /mnt/boot -zfs create -o mountpoint=legacy rpool/nixos/empty -zfs snapshot rpool/nixos/empty@start - -for i in ${DISK}; do - mkfs.vfat -n EFI ${i}-part2 - mkdir -p /mnt/boot/efis/${i##*/} - mount -t vfat ${i}-part2 /mnt/boot/efis/${i##*/} -done