From ce13e03ef1d818d851f90a46f7cf530ce9dbfb6e Mon Sep 17 00:00:00 2001 From: Manuel Thalmann Date: Sat, 7 Dec 2024 12:24:10 +0100 Subject: [PATCH] Restructure partition config --- lib/modules/fileSystems.nix | 27 ++++++++++++++ lib/modules/partition/disks.nix | 37 +++++++++++--------- lib/modules/valhalla.nix | 1 + profiles/machines/manuel/DerGeret/config.nix | 2 +- profiles/machines/manuel/Generic/config.nix | 4 +-- profiles/machines/manuel/server.nix | 4 +-- 6 files changed, 53 insertions(+), 22 deletions(-) create mode 100644 lib/modules/fileSystems.nix diff --git a/lib/modules/fileSystems.nix b/lib/modules/fileSystems.nix new file mode 100644 index 00000000..c036abcd --- /dev/null +++ b/lib/modules/fileSystems.nix @@ -0,0 +1,27 @@ +{ lib, config, ... }: +let + inherit (lib) types mkOption; +in { + imports = [ + ./partition/disks.nix + ]; + + options = { + valhalla = { + fileSystems = { + script = mkOption { + type = types.str; + description = "The script for preparing the system's mounts."; + }; + }; + }; + }; + + config = { + valhalla = { + fileSystems = { + script = config.valhalla.fileSystems.diskSetup.script; + }; + }; + }; +} diff --git a/lib/modules/partition/disks.nix b/lib/modules/partition/disks.nix index 19d66830..ce726fb7 100644 --- a/lib/modules/partition/disks.nix +++ b/lib/modules/partition/disks.nix @@ -291,27 +291,29 @@ in { options = { valhalla = { - partition = { + fileSystems = { rootDir = mkOption { type = types.str; description = "The root of the installation directory to mount disks into."; default = "/mnt"; }; - os = mkOption { - type = mkDiskType true; - description = "The partition layout of the OS disk."; - }; + diskSetup = { + osDisk = mkOption { + type = mkDiskType true; + description = "The partition layout of the OS disk."; + }; - disks = mkOption { - type = types.attrsOf (mkDiskType false); - description = "The additional disks to format."; - default = { }; - }; + disks = mkOption { + type = types.attrsOf (mkDiskType false); + description = "The additional disks to format."; + default = { }; + }; - script = mkOption { - type = types.str; - description = "The script for partitioning the system's disks."; + script = mkOption { + type = types.str; + description = "The script for partitioning the system's disks."; + }; }; }; }; @@ -319,14 +321,15 @@ in config = { valhalla = { - partition = { + fileSystems.diskSetup = { script = lib.mkDefault ( let - cfg = config.valhalla.partition; - inherit (cfg) os rootDir; + cfg = config.valhalla.fileSystems; + inherit (cfg) rootDir; + inherit (cfg.diskSetup) osDisk; inherit (lib.strings) normalizePath; partPath = part: "/dev/disk/by-label/${part.label}"; - disks = ([ os ] ++ (builtins.attrValues cfg.disks)); + disks = ([ osDisk ] ++ (builtins.attrValues cfg.diskSetup.disks)); partitions = (builtins.concatMap (_: (builtins.attrValues _.partitions)) disks); mountScript = lib.strings.concatLines (builtins.concatMap diff --git a/lib/modules/valhalla.nix b/lib/modules/valhalla.nix index 9007c820..be9c12aa 100644 --- a/lib/modules/valhalla.nix +++ b/lib/modules/valhalla.nix @@ -2,6 +2,7 @@ let inherit (lib) mkOption types; in { imports = [ + ./fileSystems.nix ./hardware.nix ./i18n.nix ./os.nix diff --git a/profiles/machines/manuel/DerGeret/config.nix b/profiles/machines/manuel/DerGeret/config.nix index 335eb710..01422c85 100644 --- a/profiles/machines/manuel/DerGeret/config.nix +++ b/profiles/machines/manuel/DerGeret/config.nix @@ -25,7 +25,7 @@ }; }; - partition.os.partitions = { + fileSystems.diskSetup.osDisk.partitions = { # Keep Windows' boot partition Boot.keepExisting = true; diff --git a/profiles/machines/manuel/Generic/config.nix b/profiles/machines/manuel/Generic/config.nix index ad4b0cc2..379a72b9 100644 --- a/profiles/machines/manuel/Generic/config.nix +++ b/profiles/machines/manuel/Generic/config.nix @@ -5,8 +5,8 @@ in { config = { valhalla = { - partition = { - os = { + fileSystems.diskSetup = { + osDisk = { partitions = { Boot = { index = 1; diff --git a/profiles/machines/manuel/server.nix b/profiles/machines/manuel/server.nix index 1a8df6aa..b245d3bf 100644 --- a/profiles/machines/manuel/server.nix +++ b/profiles/machines/manuel/server.nix @@ -5,8 +5,8 @@ in { config = { valhalla = { - partition = { - os = { + fileSystems.diskSetup = { + osDisk = { partitions = { Boot = { index = 1;