From a9a6ed08f167f14084454843101ba1598e8d2624 Mon Sep 17 00:00:00 2001 From: Andre Date: Tue, 2 Jul 2024 18:15:37 -0400 Subject: [PATCH] Modules: replace Disko module with homegrown filesystems module --- bin/install-nixos.sh | 2 +- flake.lock | 27 +------ flake.nix | 8 -- hosts/Dimaga/hardware-configuration.nix | 50 +++--------- modules/apps/media.nix | 1 + modules/system/disko.nix | 103 ------------------------ modules/system/filesystem.nix | 93 +++++++++++++++++++++ 7 files changed, 110 insertions(+), 174 deletions(-) delete mode 100644 modules/system/disko.nix create mode 100644 modules/system/filesystem.nix diff --git a/bin/install-nixos.sh b/bin/install-nixos.sh index bfc1ded..2a058da 100755 --- a/bin/install-nixos.sh +++ b/bin/install-nixos.sh @@ -30,7 +30,7 @@ mount -o subvol=@ $root_drive /mnt mkdir -p /mnt/{boot,home,var/log,nix,swap} mount $boot_drive /mnt/boot mount -o subvol=@home $root_drive /mnt/home -mount -o subvol=@log $root_drive /var/log +mount -o subvol=@log $root_drive /mnt/var/log mount -o subvol=@nix $root_drive /mnt/nix mount -o subvol=@swap $root_drive /mnt/swap diff --git a/flake.lock b/flake.lock index 419b318..fd2e9dc 100644 --- a/flake.lock +++ b/flake.lock @@ -21,26 +21,6 @@ "type": "github" } }, - "disko": { - "inputs": { - "nixpkgs": [ - "nixpkgs" - ] - }, - "locked": { - "lastModified": 1719864345, - "narHash": "sha256-e4Pw+30vFAxuvkSTaTypd9zYemB/QlWcH186dsGT+Ms=", - "owner": "nix-community", - "repo": "disko", - "rev": "544a80a69d6e2da04e4df7ec8210a858de8c7533", - "type": "github" - }, - "original": { - "owner": "nix-community", - "repo": "disko", - "type": "github" - } - }, "flake-compat": { "flake": false, "locked": { @@ -158,11 +138,11 @@ ] }, "locked": { - "lastModified": 1719827439, - "narHash": "sha256-tneHOIv1lEavZ0vQ+rgz67LPNCgOZVByYki3OkSshFU=", + "lastModified": 1719992360, + "narHash": "sha256-SRq0ZRkqagqpMGVf4z9q9CIWRbPYjO7FTqSJyWh7nes=", "owner": "nix-community", "repo": "home-manager", - "rev": "59ce796b2563e19821361abbe2067c3bb4143a7d", + "rev": "36e2f9da91ce8b63a549a47688ae60d47c50de4b", "type": "github" }, "original": { @@ -359,7 +339,6 @@ }, "root": { "inputs": { - "disko": "disko", "home-manager": "home-manager", "lanzaboote": "lanzaboote", "lix-module": "lix-module", diff --git a/flake.nix b/flake.nix index 245f373..e275374 100644 --- a/flake.nix +++ b/flake.nix @@ -37,18 +37,11 @@ url = "git+file:./nix-secrets"; flake = false; }; - - # Disko support https://github.com/nix-community/disko - disko = { - url = "github:nix-community/disko"; - inputs.nixpkgs.follows = "nixpkgs"; - }; }; outputs = inputs@{ self, - disko, home-manager, lanzaboote, lix-module, @@ -70,7 +63,6 @@ defaultModules = [ ./modules/autoimport.nix (import nix-secrets) - disko.nixosModules.disko lix-module.nixosModules.default lanzaboote.nixosModules.lanzaboote nix-flatpak.nixosModules.nix-flatpak diff --git a/hosts/Dimaga/hardware-configuration.nix b/hosts/Dimaga/hardware-configuration.nix index b77a92a..cafec83 100644 --- a/hosts/Dimaga/hardware-configuration.nix +++ b/hosts/Dimaga/hardware-configuration.nix @@ -7,12 +7,7 @@ }: let - luksPartition = "/dev/disk/by-uuid/dfb4fc8f-e82b-43a1-91c1-a77acb6337cb"; - luksDevice = "9fdc521b-a037-4070-af47-f54da03675e4"; - standardMountOpts = [ - "compress=zstd" - "noatime" - ]; + luksUUID = "9fdc521b-a037-4070-af47-f54da03675e4"; in { imports = [ (modulesPath + "/installer/scan/not-detected.nix") ]; @@ -26,8 +21,8 @@ in "sd_mod" "sdhci_pci" ]; - luks.devices."luks-${luksDevice}" = { - device = "/dev/disk/by-uuid/${luksDevice}"; + luks.devices."luks-${luksUUID}" = { + device = "/dev/disk/by-uuid/${luksUUID}"; crypttabExtraOpts = [ "tpm2-device=auto" ]; # Enable TPM auto-unlocking }; }; @@ -35,40 +30,19 @@ in extraModulePackages = [ ]; }; - fileSystems = { - "/" = { - device = luksPartition; - fsType = "btrfs"; - options = [ "subvol=@" ] ++ standardMountOpts; + # Configure the main filesystem. + aux.system.filesystem.btrfs = { + enable = true; + devices = { + boot = "/dev/disk/by-uuid/FC20-D155"; + btrfs = "/dev/disk/by-uuid/${luksUUID}"; }; - "/home" = { - device = luksPartition; - fsType = "btrfs"; - options = [ "subvol=@home" ] ++ standardMountOpts; - }; - "/nix" = { - device = luksPartition; - fsType = "btrfs"; - options = [ "subvol=@nix" ] ++ standardMountOpts; - }; - "/swap" = { - device = luksPartition; - fsType = "btrfs"; - options = [ "subvol=@swap" ]; - }; - "/boot" = { - device = "/dev/disk/by-uuid/FC20-D155"; - fsType = "vfat"; + swapFile = { + enable = true; + size = 16384; }; }; - swapDevices = [ - { - device = "/swap/swapfile"; - size = 16384; - } - ]; - # 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 # still possible to use this option, but it's recommended to use it in conjunction diff --git a/modules/apps/media.nix b/modules/apps/media.nix index 31b2dae..a46a9d8 100644 --- a/modules/apps/media.nix +++ b/modules/apps/media.nix @@ -15,6 +15,7 @@ with lib; packages = [ "com.calibre_ebook.calibre" "com.github.unrud.VideoDownloader" + "io.freetubeapp.FreeTube" "io.github.celluloid_player.Celluloid" "org.kde.krita" "org.kde.KStyle.Adwaita//5.15-23.08" # Retrieved from https://docs.flatpak.org/en/latest/desktop-integration.html diff --git a/modules/system/disko.nix b/modules/system/disko.nix deleted file mode 100644 index 134897d..0000000 --- a/modules/system/disko.nix +++ /dev/null @@ -1,103 +0,0 @@ -{ lib, config, ... }: -let - cfg = config.aux.system.disko; - - standardMountOpts = [ - "compress=zstd" - "noatime" - ]; -in -{ - options = { - aux.system.disko = { - enable = lib.mkEnableOption (lib.mdDoc "Enables Disko for disk & partition management."); - primaryDiskID = lib.mkOption { - type = lib.types.str; - description = "The ID of the disk to manage using Disko. If possible, use the World Wide Name (WWN), e.g `/dev/disk/by-id/nvme-eui.*`"; - default = ""; - }; - swapFile = { - enable = lib.mkEnableOption (lib.mdDoc "Enables the creation of swap files."); - size = lib.mkOption { - type = lib.types.str; - description = "The size of the swap file to create (defaults to 8G, or 8 gigabytes)."; - default = "8G"; - }; - }; - }; - }; - - config = lib.mkIf cfg.enable { - # Check for blank values - assertions = [ - { - assertion = (cfg.primaryDiskID != ""); - message = "aux.system.disko.primaryDiskID is not set. Please enter a valid disk ID."; - } - ]; - # Disk management - disko.enableConfig = true; - disko.devices = { - disk = { - main = { - type = "disk"; - device = "/dev/disk/by-id/${cfg.primaryDiskID}"; - 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 config.aux.system.bootloader.tpm2.enable [ "tpm2-device=auto" ]; - }; - content = { - type = "btrfs"; - extraArgs = [ "-f" ]; # Override existing partitions. - # Unless otherwise specified, the subvolume name equals the mount name. - subvolumes = { - "/root" = { - mountpoint = "/"; - mountOptions = standardMountOpts; - }; - "/home" = { - mountOptions = standardMountOpts; - }; - "/nix" = { - mountOptions = standardMountOpts; - }; - "/swap" = lib.mkIf cfg.swapFile.enable { - mountpoint = "/.swap"; - swap.swapfile.size = cfg.swapFile.size; - }; - "/log" = { - mountpoint = "/var/log"; - mountOptions = standardMountOpts; - }; - }; - }; - }; - }; - }; - }; - }; - }; - }; - }; -} diff --git a/modules/system/filesystem.nix b/modules/system/filesystem.nix new file mode 100644 index 0000000..cab579c --- /dev/null +++ b/modules/system/filesystem.nix @@ -0,0 +1,93 @@ +{ lib, config, ... }: +let + cfg = config.aux.system.filesystem.btrfs; + + standardMountOpts = [ + "compress=zstd" + "discard=async" + "noatime" + ]; +in +{ + options = { + aux.system.filesystem.btrfs = { + enable = lib.mkEnableOption (lib.mdDoc "Enables standard BTRFS subvolumes and parameters."); + devices = { + boot = lib.mkOption { + type = lib.types.str; + description = "The ID of your boot partition. Use /dev/disk/by-uuid for best results."; + default = ""; + }; + btrfs = lib.mkOption { + type = lib.types.str; + description = "The ID of your BTRFS partition. Use /dev/disk/by-uuid for best results."; + default = ""; + }; + }; + swapFile = { + enable = lib.mkEnableOption (lib.mdDoc "Enables the creation of a swap file."); + size = lib.mkOption { + type = lib.types.int; + description = "The size of the swap file to create in MB (defaults to 8192, or ~8 gigabytes)."; + default = 8192; + }; + }; + }; + }; + + config = lib.mkIf cfg.enable { + + # Check for blank parameters + assertions = [ + { + assertion = cfg.devices.btrfs != ""; + message = "Please specify a BTRFS partition to use as a filesystem."; + } + { + assertion = cfg.devices.boot != ""; + message = "Please specify a boot partition to use as a filesystem."; + } + ]; + fileSystems = + { + "/" = { + device = cfg.devices.btrfs; + fsType = "btrfs"; + options = [ "subvol=@" ] ++ standardMountOpts; + }; + "/boot" = { + device = cfg.devices.boot; + fsType = "vfat"; + }; + "/home" = { + device = cfg.devices.btrfs; + fsType = "btrfs"; + options = [ "subvol=@home" ] ++ standardMountOpts; + }; + "/var/log" = { + device = cfg.devices.btrfs; + fsType = "btrfs"; + options = [ "subvol=@log" ] ++ standardMountOpts; + }; + "/nix" = { + device = cfg.devices.btrfs; + fsType = "btrfs"; + options = [ "subvol=@nix" ] ++ standardMountOpts; + }; + } + // lib.optionalAttrs cfg.swapFile.enable { + "/swap" = { + device = cfg.devices.btrfs; + fsType = "btrfs"; + options = [ "subvol=@swap" ]; + }; + }; + + swapDevices = lib.mkIf cfg.swapFile.enable [ + { + device = "/swap/swapfile"; + size = cfg.swapFile.size; + } + ]; + }; +}