From 834c321e821ae6876aeccfa00e5b09584c939c69 Mon Sep 17 00:00:00 2001 From: Manuel Thalmann Date: Sat, 7 Dec 2024 17:35:31 +0100 Subject: [PATCH] Move the script to the `fileSystems` module --- lib/modules/fileSystems.nix | 22 +++++++++++++++++++++- lib/modules/partition/disks.nix | 29 ----------------------------- 2 files changed, 21 insertions(+), 30 deletions(-) diff --git a/lib/modules/fileSystems.nix b/lib/modules/fileSystems.nix index c036abcd..d10d279c 100644 --- a/lib/modules/fileSystems.nix +++ b/lib/modules/fileSystems.nix @@ -1,6 +1,7 @@ { lib, config, ... }: let inherit (lib) types mkOption; + cfg = config.valhalla.fileSystems; in { imports = [ ./partition/disks.nix @@ -20,7 +21,26 @@ in { config = { valhalla = { 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} + ''; }; }; }; diff --git a/lib/modules/partition/disks.nix b/lib/modules/partition/disks.nix index 17b5561f..b629df83 100644 --- a/lib/modules/partition/disks.nix +++ b/lib/modules/partition/disks.nix @@ -314,35 +314,6 @@ in 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} - ''; - }; }; }; };