cli: Fix "attribute missing" error when using flake

The final config's attributes have different names than those defined in
./default.nix, so this failed previously.
This commit is contained in:
Felix Uhl authored and mergify[bot] committed 2024-11-16 08:40:38 +00:00
1 parent eaa51560df
commit cb64993826
1 file changed
+41 -17
+41 -17
View File
@@ -14,46 +14,70 @@ let
inherit lib; inherit lib;
}; };
hasDiskoFile = diskoFile != null;
diskoAttr = diskoAttr =
if noDeps then (if noDeps then
{ (if hasDiskoFile then
destroy = "_cliDestroyNoDeps"; {
format = "_cliFormatNoDeps"; destroy = "_cliDestroyNoDeps";
mount = "_cliMountNoDeps"; format = "_cliFormatNoDeps";
mount = "_cliMountNoDeps";
"format,mount" = "_cliFormatMountNoDeps"; "format,mount" = "_cliFormatMountNoDeps";
"destroy,format,mount" = "_cliDestroyFormatMountNoDeps"; "destroy,format,mount" = "_cliDestroyFormatMountNoDeps";
}
else
{
destroy = "destroyNoDeps";
format = "formatNoDeps";
mount = "mountNoDeps";
"format,mount" = "formatMountNoDeps";
"destroy,format,mount" = "destroyFormatMountNoDeps";
}) // {
# legacy aliases # legacy aliases
disko = "diskoScriptNoDeps"; disko = "diskoScriptNoDeps";
create = "createScriptNoDeps"; create = "createScriptNoDeps";
zap_create_mount = "diskoScriptNoDeps"; zap_create_mount = "diskoScriptNoDeps";
}.${mode} }
else else
{ (if hasDiskoFile then
destroy = "_cliDestroy"; {
format = "_cliFormat"; destroy = "_cliDestroy";
mount = "_cliMount"; format = "_cliFormat";
mount = "_cliMount";
"format,mount" = "_cliFormatMount"; "format,mount" = "_cliFormatMount";
"destroy,format,mount" = "_cliDestroyFormatMount"; "destroy,format,mount" = "_cliDestroyFormatMount";
}
else
{
destroy = "destroy";
format = "format";
mount = "munt";
"format,mount" = "formatMount";
"destroy,format,mount" = "destroyFormatMount";
}) // {
# legacy aliases # legacy aliases
disko = "diskoScript"; disko = "diskoScript";
create = "createScript"; create = "createScript";
zap_create_mount = "diskoScript"; zap_create_mount = "diskoScript";
}.${mode}; }
).${mode};
hasDiskoConfigFlake = hasDiskoConfigFlake =
diskoFile != null || lib.hasAttrByPath [ "diskoConfigurations" flakeAttr ] (builtins.getFlake flake); hasDiskoFile || lib.hasAttrByPath [ "diskoConfigurations" flakeAttr ] (builtins.getFlake flake);
hasDiskoModuleFlake = hasDiskoModuleFlake =
lib.hasAttrByPath [ "nixosConfigurations" flakeAttr "config" "disko" "devices" ] (builtins.getFlake flake); lib.hasAttrByPath [ "nixosConfigurations" flakeAttr "config" "disko" "devices" ] (builtins.getFlake flake);
diskFormat = diskFormat =
let let
diskoConfig = diskoConfig =
if diskoFile != null then if hasDiskoFile then
import diskoFile import diskoFile
else else
(builtins.getFlake flake).diskoConfigurations.${flakeAttr}; (builtins.getFlake flake).diskoConfigurations.${flakeAttr};