Add a separate option for mounts

This commit is contained in:
Manuel Thalmann 2024-12-07 19:11:41 +01:00
parent 3790fd267e
commit f1ed876cc1
2 changed files with 122 additions and 61 deletions

View file

@ -2,14 +2,53 @@
let let
inherit (lib) types mkOption; inherit (lib) types mkOption;
cfg = config.valhalla.fileSystems; cfg = config.valhalla.fileSystems;
in {
mountType = types.submodule (
{ config, name, ... }: {
options = {
device = mkOption {
type = types.nullOr types.str;
description = "The device to mount.";
default = null;
};
mountPoint = mkOption {
type = types.str;
description = "The path to mount the device to.";
default = name;
};
fsType = mkOption {
type = types.nullOr types.str;
description = "The file system type of the mount.";
default = null;
};
options = mkOption {
type = types.listOf types.str;
description = "The options of the mount.";
default = [ ];
};
};
}
);
in
{
imports = [ imports = [
./fileSystems/btrfs.nix
./fileSystems/disks.nix ./fileSystems/disks.nix
]; ];
options = { options = {
valhalla = { valhalla = {
fileSystems = { fileSystems = {
mounts = mkOption {
type = types.attrsOf mountType;
description = "The devices to mount.";
default = { };
};
script = mkOption { script = mkOption {
type = types.str; type = types.str;
description = "The script for preparing the system's mounts."; description = "The script for preparing the system's mounts.";
@ -21,9 +60,11 @@ in {
config = { config = {
valhalla = { valhalla = {
fileSystems = { fileSystems = {
script = let script =
let
devices = (builtins.attrValues cfg.diskSetup.devices); devices = (builtins.attrValues cfg.diskSetup.devices);
in '' in
''
#!/bin/bash #!/bin/bash
set -o errexit set -o errexit
${cfg.diskSetup.scripts.init} ${cfg.diskSetup.scripts.init}

View file

@ -4,6 +4,7 @@ let
fs = import ./fs.nix; fs = import ./fs.nix;
cfg = config.valhalla.fileSystems;
deviceListVarName = "myDevices"; deviceListVarName = "myDevices";
isSwap = partition: builtins.elem partition.type [ fs.swap 19 ]; isSwap = partition: builtins.elem partition.type [ fs.swap 19 ];
@ -333,10 +334,28 @@ in
config = { config = {
valhalla = { valhalla = {
fileSystems.diskSetup = { fileSystems = {
mounts = (lib.attrsets.concatMapAttrs
(
name: device:
lib.attrsets.concatMapAttrs
(
name: partition:
if partition.mountPoint != null then {
${partition.mountPoint} = {
device = "/dev/disk/by-label/${partition.label}";
fsType = partition.format;
options = partition.mountOptions;
};
} else { }
)
device.partitions
)
cfg.diskSetup.devices);
diskSetup = {
scripts = scripts =
let let
cfg = config.valhalla.fileSystems;
inherit (cfg) rootDir; inherit (cfg) rootDir;
inherit (lib.strings) normalizePath; inherit (lib.strings) normalizePath;
partPath = part: "/dev/disk/by-label/${part.label}"; partPath = part: "/dev/disk/by-label/${part.label}";
@ -378,4 +397,5 @@ in
}; };
}; };
}; };
};
} }