PortValhalla/lib/modules/fileSystems.nix

47 lines
1.3 KiB
Nix

{ lib, config, ... }:
let
inherit (lib) types mkOption;
cfg = config.valhalla.fileSystems;
in {
imports = [
./fileSystems/disks.nix
];
options = {
valhalla = {
fileSystems = {
script = mkOption {
type = types.str;
description = "The script for preparing the system's mounts.";
};
};
};
};
config = {
valhalla = {
fileSystems = {
script = let
devices = (builtins.attrValues cfg.diskSetup.devices);
in ''
#!/bin/bash
set -o errexit
${cfg.diskSetup.scripts.init}
${lib.strings.concatLines (lib.optionals ((builtins.length devices) > 0) [
''echo $(tput setaf 3)=== WARNING ====$(jtput sgr0)"''
(''echo "Continuing this script will alter the partitions of ''
+ (lib.strings.concatStringsSep ", " (builtins.map (_: "${_.deviceVariable}") (lib.lists.init devices)))
+ (if (builtins.length devices) > 1 then " and " else "") + (lib.lists.last devices).deviceVariable + ''"'')
''
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}
'';
};
};
};
}