diff --git a/lib/modules/partition.nix b/lib/modules/partition.nix index 96f6ede9..a6d670d9 100644 --- a/lib/modules/partition.nix +++ b/lib/modules/partition.nix @@ -209,6 +209,18 @@ description = "A script for printing the size to the console."; internal = true; }; + + useSwap = mkOption { + type = types.bool; + description = "A value indicating whether this partition should be used as swap."; + default = isSwap config; + }; + + mountPoint = mkOption { + type = types.nullOr types.str; + description = "The mountpoint of the partition."; + default = null; + }; }; config = { @@ -225,6 +237,12 @@ in { options = { partition = { + 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."; @@ -270,11 +288,32 @@ script = let - inherit (config.partition) - os - disks - ; - in lib.strings.concatLines (builtins.map (_: _.script) ([os] ++ (builtins.attrValues disks))); + inherit (config.partition) os rootDir; + inherit (lib.strings) normalizePath; + + partPath = part: "/dev/disk/by-label/${part.label}"; + disks = ([os] ++ (builtins.attrValues config.partition.disks)); + partitions = (builtins.concatMap (_: (builtins.attrValues _.partitions)) disks); + + mountScript = lib.strings.concatLines ( + builtins.map + (_: builtins.concatStringsSep " " [ + "mount" + (partPath _) + (normalizePath "/${rootDir}/${_.mountPoint}") + ]) + (builtins.filter (_: _.mountPoint != null) partitions)); + + swapScript = lib.strings.concatLines ( + builtins.map + (_: "swapon ${partPath _}") + (builtins.filter (_: _.useSwap) partitions)); + in lib.strings.concatLines ( + (builtins.map (_: _.script) disks) ++ [ + mountScript + swapScript + ] + ); }; }; }