From cb64993826fa7a477490be6ccb38ba1fa1e18fa8 Mon Sep 17 00:00:00 2001 From: Felix Uhl Date: Thu, 14 Nov 2024 00:11:46 +0100 Subject: [PATCH] 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. --- cli.nix | 58 ++++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 41 insertions(+), 17 deletions(-) diff --git a/cli.nix b/cli.nix index 10341d0..bc78f9a 100644 --- a/cli.nix +++ b/cli.nix @@ -14,46 +14,70 @@ let inherit lib; }; + hasDiskoFile = diskoFile != null; + diskoAttr = - if noDeps then - { - destroy = "_cliDestroyNoDeps"; - format = "_cliFormatNoDeps"; - mount = "_cliMountNoDeps"; + (if noDeps then + (if hasDiskoFile then + { + destroy = "_cliDestroyNoDeps"; + format = "_cliFormatNoDeps"; + mount = "_cliMountNoDeps"; - "format,mount" = "_cliFormatMountNoDeps"; - "destroy,format,mount" = "_cliDestroyFormatMountNoDeps"; + "format,mount" = "_cliFormatMountNoDeps"; + "destroy,format,mount" = "_cliDestroyFormatMountNoDeps"; + } + else + { + destroy = "destroyNoDeps"; + format = "formatNoDeps"; + mount = "mountNoDeps"; + "format,mount" = "formatMountNoDeps"; + "destroy,format,mount" = "destroyFormatMountNoDeps"; + }) // { # legacy aliases disko = "diskoScriptNoDeps"; create = "createScriptNoDeps"; zap_create_mount = "diskoScriptNoDeps"; - }.${mode} + } else - { - destroy = "_cliDestroy"; - format = "_cliFormat"; - mount = "_cliMount"; + (if hasDiskoFile then + { + destroy = "_cliDestroy"; + format = "_cliFormat"; + mount = "_cliMount"; - "format,mount" = "_cliFormatMount"; - "destroy,format,mount" = "_cliDestroyFormatMount"; + "format,mount" = "_cliFormatMount"; + "destroy,format,mount" = "_cliDestroyFormatMount"; + } + else + { + destroy = "destroy"; + format = "format"; + mount = "munt"; + "format,mount" = "formatMount"; + "destroy,format,mount" = "destroyFormatMount"; + }) // { # legacy aliases disko = "diskoScript"; create = "createScript"; zap_create_mount = "diskoScript"; - }.${mode}; + } + ).${mode}; hasDiskoConfigFlake = - diskoFile != null || lib.hasAttrByPath [ "diskoConfigurations" flakeAttr ] (builtins.getFlake flake); + hasDiskoFile || lib.hasAttrByPath [ "diskoConfigurations" flakeAttr ] (builtins.getFlake flake); hasDiskoModuleFlake = lib.hasAttrByPath [ "nixosConfigurations" flakeAttr "config" "disko" "devices" ] (builtins.getFlake flake); + diskFormat = let diskoConfig = - if diskoFile != null then + if hasDiskoFile then import diskoFile else (builtins.getFlake flake).diskoConfigurations.${flakeAttr};