Create mount script in fileSystems module

This commit is contained in:
Manuel Thalmann 2024-12-07 19:28:42 +01:00
parent f1ed876cc1
commit 9caedac094
2 changed files with 30 additions and 31 deletions

View file

@ -41,8 +41,13 @@ in
options = {
valhalla = {
fileSystems = {
rootDir = mkOption {
type = types.str;
description = "The root of the installation directory to mount disks into.";
default = "/mnt";
};
mounts = mkOption {
type = types.attrsOf mountType;
description = "The devices to mount.";
@ -63,6 +68,25 @@ in
script =
let
devices = (builtins.attrValues cfg.diskSetup.devices);
mountScript = lib.strings.concatLines (
(builtins.concatMap
(
_: [
"partprobe 2> /dev/null || true"
"udevadm trigger"
(builtins.concatStringsSep " " (
[ "sudo" "mount" "--mkdir" ] ++
(lib.optionals (_.fsType == "ntfs") [ "-t" "ntfs3" ]) ++
[
(builtins.concatStringsSep " " (builtins.map (_: "-o ${_}") _.options))
(_.device)
(lib.strings.normalizePath "/${cfg.diskSetup.rootDir}/${_.mountPoint}")
]
))
]
)
(builtins.attrValues cfg.mounts))
);
in
''
#!/bin/bash
@ -80,7 +104,8 @@ in
''
])}
${cfg.diskSetup.scripts.partition}
${cfg.diskSetup.scripts.mount}
${mountScript}
${cfg.diskSetup.scripts.swap}
'';
};
};

View file

@ -298,12 +298,6 @@ in
options = {
valhalla = {
fileSystems = {
rootDir = mkOption {
type = types.str;
description = "The root of the installation directory to mount disks into.";
default = "/mnt";
};
diskSetup = {
devices = mkOption {
type = types.attrsOf (mkDeviceType);
@ -322,9 +316,9 @@ in
description = "The script for partitioning the disks.";
};
mount = mkOption {
swap = mkOption {
type = types.str;
description = "The script for mounting the partitioned disks.";
description = "The script for enabling swap devices.";
};
};
};
@ -356,8 +350,6 @@ in
diskSetup = {
scripts =
let
inherit (cfg) rootDir;
inherit (lib.strings) normalizePath;
partPath = part: "/dev/disk/by-label/${part.label}";
disks = ((builtins.attrValues cfg.diskSetup.devices));
partitions = (builtins.concatMap (_: (builtins.attrValues _.partitions)) disks);
@ -365,25 +357,7 @@ in
{
init = lib.strings.concatLines (builtins.map (_: _.scripts.init) disks);
partition = lib.strings.concatLines (builtins.map (_: _.scripts.partition) disks);
mount = lib.strings.concatLines (
(builtins.concatMap
(
_: [
probeScript
(builtins.concatStringsSep " " (
[ "sudo" "mount" "--mkdir" ] ++
(lib.optionals (_.format == "ntfs") [ "-t" "ntfs3" ]) ++
[
(builtins.concatStringsSep " " (builtins.map (_: "-o ${_}") _.mountOptions))
(partPath _)
(normalizePath "/${rootDir}/${_.mountPoint}")
]
))
]
)
(lib.lists.sortOn
(_: normalizePath "/${_.mountPoint}")
(builtins.filter (_: _.mountPoint != null) partitions))) ++
swap = lib.strings.concatLines (
(builtins.map
(
_: ''