PortValhalla/lib/modules/fileSystems.nix

48 lines
1.3 KiB
Nix
Raw Normal View History

2024-12-07 11:24:10 +00:00
{ lib, config, ... }:
let
inherit (lib) types mkOption;
cfg = config.valhalla.fileSystems;
2024-12-07 11:24:10 +00:00
in {
imports = [
2024-12-07 17:36:19 +00:00
./fileSystems/disks.nix
2024-12-07 11:24:10 +00:00
];
options = {
valhalla = {
fileSystems = {
script = mkOption {
type = types.str;
description = "The script for preparing the system's mounts.";
};
};
};
};
config = {
valhalla = {
fileSystems = {
script = let
2024-12-07 16:43:53 +00:00
devices = (builtins.attrValues cfg.diskSetup.devices);
in ''
#!/bin/bash
set -o errexit
${cfg.diskSetup.scripts.init}
2024-12-07 16:43:53 +00:00
${lib.strings.concatLines (lib.optionals ((builtins.length devices) > 0) [
''echo "$(tput setaf 3)=== WARNING ====$(tput sgr0)"''
(''echo "Continuing this script will alter the partitions of ''
2024-12-07 16:43:53 +00:00
+ (lib.strings.concatStringsSep ", " (builtins.map (_: "${_.deviceVariable}") (lib.lists.init devices)))
+ (if (builtins.length devices) > 1 then " and " else "") + (lib.lists.last devices).deviceVariable + ''"'')
''
2024-12-07 17:36:19 +00:00
if ! fish ${./fileSystems/confirm.fish} "Are you sure you want to continue?" "n"; then
exit 1
fi
''
])}
${cfg.diskSetup.scripts.partition}
${cfg.diskSetup.scripts.mount}
'';
2024-12-07 11:24:10 +00:00
};
};
};
}