module: throw if no disks are defined

This commit is contained in:
Michael Hoang 2024-09-18 18:54:37 +07:00
parent 706a1722f6
commit c5853dcb32
2 changed files with 66 additions and 57 deletions

View file

@ -388,7 +388,11 @@ let
description = ''
The scripts generated by disko
'';
default = { pkgs, checked ? false }: {
default = { pkgs, checked ? false }:
let
throwIfNoDisksDetected = _: v: if devices.disk == { } then throw "No disks defined, did you forget to import your disko config?" else v;
in
mapAttrs throwIfNoDisksDetected {
destroyScript = (diskoLib.writeCheckedBash { inherit pkgs checked; }) "disko-destroy" ''
export PATH=${lib.makeBinPath (with pkgs; [
util-linux

View file

@ -200,7 +200,11 @@ in
eval-config = import (pkgs.path + "/nixos/lib/eval-config.nix");
};
system.build = (cfg.devices._scripts { inherit pkgs; checked = cfg.checkScripts; }) // {
system.build = (cfg.devices._scripts { inherit pkgs; checked = cfg.checkScripts; }) // (
let
throwIfNoDisksDetected = _: v: if cfg.devices.disk == { } then throw "No disks defined, did you forget to import your disko config?" else v;
in
lib.mapAttrs throwIfNoDisksDetected {
# we keep these old outputs for compatibility
disko = builtins.trace "the .disko output is deprecated, please use .diskoScript instead" (cfg.devices._scripts { inherit pkgs; }).diskoScript;
diskoNoDeps = builtins.trace "the .diskoNoDeps output is deprecated, please use .diskoScriptNoDeps instead" (cfg.devices._scripts { inherit pkgs; }).diskoScriptNoDeps;
@ -216,7 +220,8 @@ in
};
vmWithDisko = lib.mkDefault config.virtualisation.vmVariantWithDisko.system.build.vmWithDisko;
};
}
);
# we need to specify the keys here, so we don't get an infinite recursion error
# Remember to add config keys here if they are added to types