Add a separate option for mounts

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

View file

@ -2,14 +2,53 @@
let
inherit (lib) types mkOption;
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 = [
./fileSystems/btrfs.nix
./fileSystems/disks.nix
];
options = {
valhalla = {
fileSystems = {
mounts = mkOption {
type = types.attrsOf mountType;
description = "The devices to mount.";
default = { };
};
script = mkOption {
type = types.str;
description = "The script for preparing the system's mounts.";
@ -21,9 +60,11 @@ in {
config = {
valhalla = {
fileSystems = {
script = let
script =
let
devices = (builtins.attrValues cfg.diskSetup.devices);
in ''
in
''
#!/bin/bash
set -o errexit
${cfg.diskSetup.scripts.init}

View file

@ -4,6 +4,7 @@ let
fs = import ./fs.nix;
cfg = config.valhalla.fileSystems;
deviceListVarName = "myDevices";
isSwap = partition: builtins.elem partition.type [ fs.swap 19 ];
@ -333,10 +334,28 @@ in
config = {
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 =
let
cfg = config.valhalla.fileSystems;
inherit (cfg) rootDir;
inherit (lib.strings) normalizePath;
partPath = part: "/dev/disk/by-label/${part.label}";
@ -378,4 +397,5 @@ in
};
};
};
};
}