Move the script to the fileSystems module

This commit is contained in:
Manuel Thalmann 2024-12-07 17:35:31 +01:00
parent d2d99a4b43
commit 834c321e82
2 changed files with 21 additions and 30 deletions

View file

@ -1,6 +1,7 @@
{ lib, config, ... }: { lib, config, ... }:
let let
inherit (lib) types mkOption; inherit (lib) types mkOption;
cfg = config.valhalla.fileSystems;
in { in {
imports = [ imports = [
./partition/disks.nix ./partition/disks.nix
@ -20,7 +21,26 @@ in {
config = { config = {
valhalla = { valhalla = {
fileSystems = { fileSystems = {
script = config.valhalla.fileSystems.diskSetup.script; script = let
disks = (builtins.attrValues cfg.diskSetup.disks);
in ''
#!/bin/bash
set -o errexit
${cfg.diskSetup.scripts.init}
${lib.strings.concatLines (lib.optionals ((builtins.length disks) > 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 disks)))
+ (if (builtins.length disks) > 1 then " and " else "") + (lib.lists.last disks).deviceVariable + ''"'')
''
if ! fish ${./partition/confirm.fish} "Are you sure you want to continue?" "n"; then
exit 1
fi
''
])}
${cfg.diskSetup.scripts.partition}
${cfg.diskSetup.scripts.mount}
'';
}; };
}; };
}; };

View file

@ -314,35 +314,6 @@ in
description = "The script for mounting the partitioned disks."; description = "The script for mounting the partitioned disks.";
}; };
}; };
script = mkOption {
type = types.str;
description = "The script for partitioning the system's disks.";
default =
let
cfg = config.valhalla.fileSystems.diskSetup;
inherit (cfg) scripts;
disks = (builtins.attrValues cfg.disks);
in
''
#!/bin/bash
set -o errexit
${scripts.init}
${lib.strings.concatLines (lib.optionals ((builtins.length disks) > 0) [
''echo "$(tput setaf 3)==== WARNING ====$(tput sgr0)"''
(''echo "Continuing this script will alter the partitions of ''
+ (lib.strings.concatStringsSep ", " (builtins.map (_: "${_.deviceVariable}") (lib.lists.init disks)))
+ (if (builtins.length disks) > 1 then " and " else "") + (lib.lists.last disks).deviceVariable + ''"'')
''
if ! fish ${./confirm.fish} "Are you sure you want to continue?" "n"; then
exit 1
fi
''
])}
${scripts.partition}
${scripts.mount}
'';
};
}; };
}; };
}; };