From e16ae12c16a91a0ef7a84d7e0d1c45917b17f7dd Mon Sep 17 00:00:00 2001 From: Andre Date: Sun, 2 Jun 2024 14:16:44 -0400 Subject: [PATCH] More attempts to get Disko working --- hosts/Haven/hardware-configuration.nix | 40 +++------ hosts/Khanda/hardware-configuration.nix | 84 +++--------------- hosts/Shura/hardware-configuration.nix | 102 +++------------------ modules/base/disko.nix | 112 ++++++++++++++++++++++++ modules/base/system.nix | 2 +- 5 files changed, 148 insertions(+), 192 deletions(-) create mode 100644 modules/base/disko.nix diff --git a/hosts/Haven/hardware-configuration.nix b/hosts/Haven/hardware-configuration.nix index 57a62b7..c001076 100644 --- a/hosts/Haven/hardware-configuration.nix +++ b/hosts/Haven/hardware-configuration.nix @@ -9,6 +9,17 @@ { imports = [ (modulesPath + "/installer/scan/not-detected.nix") ]; + # Format and configure the disk using Disko + host.base.disko = { + enable = false; + primaryDisk = "nvme0n1"; + enableTPM = true; + swapFile = { + enable = true; + size = "16G"; + }; + }; + boot = { supportedFilesystems = [ "btrfs" ]; kernelModules = [ "kvm-amd" ]; @@ -38,35 +49,6 @@ }; }; - fileSystems = { - "/" = { - device = "/dev/disk/by-uuid/2c76c660-3573-4622-8771-f23fa7ee302a"; - fsType = "btrfs"; - options = [ "subvol=@,compress=zstd" ]; - }; - "/home" = { - device = "/dev/disk/by-uuid/2c76c660-3573-4622-8771-f23fa7ee302a"; - fsType = "btrfs"; - options = [ "subvol=@home,compress=zstd" ]; - }; - "/swap" = { - device = "/dev/disk/by-uuid/2c76c660-3573-4622-8771-f23fa7ee302a"; - fsType = "btrfs"; - options = [ "subvol=@swap" ]; - }; - "/boot" = { - device = "/dev/disk/by-uuid/0120-A755"; - fsType = "vfat"; - }; - }; - - swapDevices = [ - { - device = "/swap/swapfile"; - size = 16384; - } - ]; - networking = { useDHCP = lib.mkDefault true; hostName = "Haven"; diff --git a/hosts/Khanda/hardware-configuration.nix b/hosts/Khanda/hardware-configuration.nix index f638a83..b0ceead 100644 --- a/hosts/Khanda/hardware-configuration.nix +++ b/hosts/Khanda/hardware-configuration.nix @@ -9,11 +9,22 @@ { imports = [ (modulesPath + "/installer/scan/not-detected.nix") ]; + # Format and configure the disk using Disko + host.base.disko = { + enable = false; + primaryDisk = "nvme0n1"; + enableTPM = true; + swapFile = { + enable = true; + size = "16G"; + }; + }; + boot = { initrd = { # Enable systemd for TPM auto-unlocking systemd.enable = true; - + availableKernelModules = [ "surface_aggregator" "surface_aggregator_registry" @@ -81,75 +92,6 @@ surface-control.enable = true; }; - # NOTE: Use a default kernel to skip full kernel rebuilds + # Uncomment this to use the default kernel and skip rebuilding the kernel # boot.kernelPackages = lib.mkForce pkgs.linuxPackages_latest; - - # Disk management - disko.enableConfig = true; # Disable while testing - disko.devices = { - disk = { - nvme0n1 = { - type = "disk"; - device = "/dev/disk/by-id/nvme-MZ9L4256HCJQ-00BMV-SAMSUNG_S69VNE0X195093"; - content = { - type = "gpt"; - partitions = { - ESP = { - priority = 1; - name = "ESP"; - label = "boot"; - size = "1G"; - type = "EF00"; - content = { - type = "filesystem"; - format = "vfat"; - mountpoint = "/boot"; - }; - }; - luks = { - size = "100%"; - label = "nixos"; - content = { - type = "luks"; - name = "cryptroot"; - settings = { - allowDiscards = true; - crypttabExtraOpts = ["tpm2-device=auto"]; - }; - content = { - type = "btrfs"; - extraArgs = [ "-f" ]; # Override existing partition - # Subvolumes must set a mountpoint in order to be mounted, - # unless their parent is mounted - subvolumes = { - # Subvolume name is different from mountpoint - "/root" = { - mountOptions = [ "compress=zstd" "noatime" ]; - mountpoint = "/"; - }; - "/home" = { - mountOptions = [ "compress=zstd" "noatime" ]; - mountpoint = "/home"; - }; - "/nix" = { - mountOptions = [ "compress=zstd" "noatime" ]; - mountpoint = "/nix"; - }; - "/swap" = { - mountpoint = "/.swap"; - swap.swapfile.size = "8G"; - }; - "/log" = { - mountpoint = "/var/log"; - mountOptions = ["compress=zstd" "noatime"]; - }; - }; - }; - }; - }; - }; - }; - }; - }; - }; } diff --git a/hosts/Shura/hardware-configuration.nix b/hosts/Shura/hardware-configuration.nix index d6f49de..d55210a 100644 --- a/hosts/Shura/hardware-configuration.nix +++ b/hosts/Shura/hardware-configuration.nix @@ -9,6 +9,17 @@ { imports = [ (modulesPath + "/installer/scan/not-detected.nix") ]; + # Format and configure the disk using Disko + host.base.disko = { + enable = false; + primaryDisk = "nvme0n1"; + enableTPM = true; + swapFile = { + enable = true; + size = "16G"; + }; + }; + # Configure the kernel. boot = { # First, install the latest Zen kernel @@ -44,28 +55,6 @@ kernelModules = [ "kvm-amd" ]; }; - fileSystems = { - "/" = { - device = "/dev/disk/by-uuid/b801fbea-4cb5-4255-bea9-a2ce77d1a1b7"; - fsType = "btrfs"; - options = [ "subvol=@,compress=zstd" ]; - }; - "/home" = { - device = "/dev/disk/by-uuid/b801fbea-4cb5-4255-bea9-a2ce77d1a1b7"; - fsType = "btrfs"; - options = [ "subvol=@home,compress=zstd" ]; - }; - "/swap" = { - device = "/dev/disk/by-uuid/b801fbea-4cb5-4255-bea9-a2ce77d1a1b7"; - fsType = "btrfs"; - options = [ "subvol=@swap" ]; - }; - "/boot" = { - device = "/dev/disk/by-uuid/AFCB-D880"; - fsType = "vfat"; - }; - }; - networking = { # Enables DHCP on each ethernet and wireless interface. In case of scripted networking # (the default) this is the recommended approach. When using systemd-networkd it's @@ -79,73 +68,4 @@ }; nixpkgs.hostPlatform = lib.mkDefault "x86_64-linux"; - - # Disk management - disko.enableConfig = false; # Disable while testing - disko.devices = { - disk = { - nvme0n1 = { - type = "disk"; - device = ""; - content = { - type = "gpt"; - partitions = { - ESP = { - priority = 1; - name = "ESP"; - label = "boot"; - size = "1G"; - type = "EF00"; - content = { - type = "filesystem"; - format = "vfat"; - mountpoint = "/boot"; - }; - }; - luks = { - size = "100%"; - label = "nixos"; - content = { - type = "luks"; - name = "cryptroot"; - settings = { - allowDiscards = true; - crypttabExtraOpts = ["tpm2-device=auto"]; - }; - content = { - type = "btrfs"; - extraArgs = [ "-f" ]; # Override existing partition - # Subvolumes must set a mountpoint in order to be mounted, - # unless their parent is mounted - subvolumes = { - # Subvolume name is different from mountpoint - "/root" = { - mountOptions = [ "compress=zstd" "noatime" ]; - mountpoint = "/"; - }; - "/home" = { - mountOptions = [ "compress=zstd" "noatime" ]; - mountpoint = "/home"; - }; - "/nix" = { - mountOptions = [ "compress=zstd" "noatime" ]; - mountpoint = "/nix"; - }; - "/swap" = { - mountpoint = "/.swap"; - swap.swapfile.size = "16G"; - }; - "/log" = { - mountpoint = "/var/log"; - mountOptions = ["compress=zstd" "noatime"]; - }; - }; - }; - }; - }; - }; - }; - }; - }; - }; } diff --git a/modules/base/disko.nix b/modules/base/disko.nix new file mode 100644 index 0000000..8df34d3 --- /dev/null +++ b/modules/base/disko.nix @@ -0,0 +1,112 @@ +{ lib, config, ... }: +let + cfg = config.host.base.disko; +in +{ + options = { + host.base.disko = { + enable = lib.mkEnableOption (lib.mdDoc "Enables Disko for disk & partition management."); + primaryDisk = lib.mkOption { + type = lib.types.attrs; + description = "The disk to format using Disko."; + default = { + name = "nvme0n1"; + id = ""; + }; + }; + enableTPM = lib.mkOption { + type = lib.types.bool; + description = "Enables TPM2 support."; + default = true; + }; + swapFile = lib.mkOption { + type = lib.types.attrs; + description = "Swap file enabling and configuration."; + default = { + enable = true; + size = "8G"; + }; + }; + }; + }; + + config = lib.mkIf cfg.enable { + # Disk management + disko.enableConfig = true; + disko.devices = { + disk = { + main = { + type = "disk"; + device = "/dev/disk/by-id/${cfg.primaryDisk.id}"; + content = { + type = "gpt"; + partitions = { + ESP = { + priority = 1; + name = "ESP"; + label = "boot"; + size = "1G"; + type = "EF00"; + content = { + type = "filesystem"; + format = "vfat"; + mountpoint = "/boot"; + }; + }; + luks = { + size = "100%"; + label = "nixos"; + content = { + type = "luks"; + name = "cryptroot"; + settings = { + allowDiscards = true; + crypttabExtraOpts = lib.mkIf cfg.enableTPM [ "tpm2-device=auto" ]; + }; + content = { + type = "btrfs"; + extraArgs = [ "-f" ]; # Override existing partition + subvolumes = { + "/root" = { + mountOptions = [ + "compress=zstd" + "noatime" + ]; + mountpoint = "/"; + }; + "/home" = { + mountOptions = [ + "compress=zstd" + "noatime" + ]; + mountpoint = "/home"; + }; + "/nix" = { + mountOptions = [ + "compress=zstd" + "noatime" + ]; + mountpoint = "/nix"; + }; + "/swap" = lib.mkIf cfg.swapFile.enable { + mountpoint = "/.swap"; + swap.swapfile.size = cfg.swapFile.size; + }; + "/log" = { + mountpoint = "/var/log"; + mountOptions = [ + "compress=zstd" + "noatime" + ]; + }; + }; + }; + }; + }; + }; + }; + }; + }; + }; + }; +} diff --git a/modules/base/system.nix b/modules/base/system.nix index 50afc76..b2054d5 100644 --- a/modules/base/system.nix +++ b/modules/base/system.nix @@ -39,7 +39,7 @@ fwupd.enable = true; # Autoscrub BTRFS partitions - btrfs.autoScrub = lib.mkIf (config.fileSystems."/".fsType == "btrfs") { + btrfs.autoScrub = { enable = true; interval = "weekly"; fileSystems = [ "/" ];