diff options
-rw-r--r-- | cli.nix | 25 | ||||
-rw-r--r-- | default.nix | 18 | ||||
-rwxr-xr-x | disko | 3 | ||||
-rw-r--r-- | example/with-lib.nix | 4 | ||||
-rw-r--r-- | flake.nix | 12 | ||||
-rw-r--r-- | module.nix | 21 | ||||
-rw-r--r-- | tests/lib.nix | 10 |
7 files changed, 52 insertions, 41 deletions
@@ -3,6 +3,7 @@ , flake ? null , flakeAttr ? null , diskoFile ? null +, noDeps ? false , ... }@args: let disko = import ./. { }; @@ -12,13 +13,23 @@ let else import diskoFile args; - diskoEval = if (mode == "create") then - disko.createScript diskFormat pkgs - else if (mode == "mount") then - disko.mountScript diskFormat pkgs - else if (mode = "zap_create_mount") then - disko.zapCreateMount diskFormat pkgs + diskoEval = if noDeps then + if (mode == "create") then + disko.createScriptNoDeps diskFormat pkgs + else if (mode == "mount") then + disko.mountScriptNoDeps diskFormat pkgs + else if (mode == "zap_create_mount") then + disko.zapCreateMountScriptNoDeps diskFormat pkgs + else + builtins.abort "invalid mode" else - builtins.abort "invalid mode" + if (mode == "create") then + disko.createScript diskFormat pkgs + else if (mode == "mount") then + disko.mountScript diskFormat pkgs + else if (mode == "zap_create_mount") then + disko.zapCreateMount diskFormat pkgs + else + builtins.abort "invalid mode" ; in diskoEval diff --git a/default.nix b/default.nix index 03a6833..bc975a7 100644 --- a/default.nix +++ b/default.nix @@ -16,18 +16,34 @@ in { types = types; create = cfg: types.diskoLib.create (eval cfg).config.devices; createScript = cfg: pkgs: pkgs.writeScript "disko-create" '' + #!/usr/bin/env bash export PATH=${lib.makeBinPath (types.diskoLib.packages (eval cfg).config.devices pkgs)} ${types.diskoLib.create (eval cfg).config.devices} ''; + createScriptNoDeps = cfg: pkgs: pkgs.writeScript "disko-create" '' + #!/usr/bin/env bash + ${types.diskoLib.create (eval cfg).config.devices} + ''; mount = cfg: types.diskoLib.mount (eval cfg).config.devices; mountScript = cfg: pkgs: pkgs.writeScript "disko-mount" '' + #!/usr/bin/env bash export PATH=${lib.makeBinPath (types.diskoLib.packages (eval cfg).config.devices pkgs)} ${types.diskoLib.mount (eval cfg).config.devices} ''; - zapCreateMount = cfg: pkgs: pkgs.writeScript "disko-zap-create-mount" '' + mountScriptNoDeps = cfg: pkgs: pkgs.writeScript "disko-mount" '' + #!/usr/bin/env bash + ${types.diskoLib.mount (eval cfg).config.devices} + ''; + zapCreateMount = cfg: types.diskoLib.zapCreateMount (eval cfg).config.devices; + zapCreateMountScript = cfg: pkgs: pkgs.writeScript "disko-zap-create-mount" '' + #!/usr/bin/env bash export PATH=${lib.makeBinPath (types.diskoLib.packages (eval cfg).config.devices pkgs)} ${types.diskoLib.zapCreateMount (eval cfg).config.devices} ''; + zapCreateMountScriptNoDeps = cfg: pkgs: pkgs.writeScript "disko-zap-create-mount" '' + #!/usr/bin/env bash + ${types.diskoLib.zapCreateMount (eval cfg).config.devices} + ''; config = cfg: { imports = types.diskoLib.config (eval cfg).config.devices; }; packages = cfg: types.diskoLib.packages (eval cfg).config.devices; } @@ -72,6 +72,9 @@ while [[ $# -gt 0 ]]; do --dry-run) dry_run=y ;; + --no-deps) + nix_args+=(--arg noDeps true) + ;; --show-trace) nix_args+=("$1") ;; diff --git a/example/with-lib.nix b/example/with-lib.nix index e746f5b..ce0b93d 100644 --- a/example/with-lib.nix +++ b/example/with-lib.nix @@ -1,6 +1,6 @@ # Example to create a bios compatible gpt partition { disks ? [ "/dev/vdb" ], lib, ... }: { - disk = lib.traceValSeq (lib.genAttrs [ (lib.head disks) ] (device: { + disk = lib.genAttrs [ (lib.head disks) ] (device: { device = device; type = "disk"; content = { @@ -31,5 +31,5 @@ } ]; }; - })); + }); } @@ -25,12 +25,12 @@ passAsFile = ["buildPhase"]; buildPhase = '' mkdir -p $out/bin $out/share/disko - cp -r $src/* $out/share/disko - sed \ - -e "s|libexec_dir=\".*\"|libexec_dir=\"$out/share/disko\"|" \ - -e "s|#!/usr/bin/env.*|#!/usr/bin/env bash|" \ - $src/disko > $out/bin/disko - chmod 755 $out/bin/disko + cp -r $src/* $out/share/disko + sed \ + -e "s|libexec_dir=\".*\"|libexec_dir=\"$out/share/disko\"|" \ + -e "s|#!/usr/bin/env.*|#!/usr/bin/env bash|" \ + $src/disko > $out/bin/disko + chmod 755 $out/bin/disko ''; args = ["-c" ". $buildPhasePath"]; src = inclFiles { inherit name; src = ./.; } [ @@ -16,26 +16,8 @@ in { type = lib.types.bool; default = true; }; - addScripts = lib.mkOption { - description = '' - add disko-create and disko-mount scripts to systemPackages. - ''; - type = lib.types.bool; - default = true; - }; }; config = { - environment.systemPackages = (lib.optionals cfg.addScripts [ - (pkgs.writers.writeDashBin "disko-create" '' - export PATH=${lib.makeBinPath (types.diskoLib.packages cfg.devices pkgs)} - ${types.diskoLib.create cfg.devices} - '') - (pkgs.writers.writeDashBin "disko-mount" '' - export PATH=${lib.makeBinPath (types.diskoLib.packages cfg.devices pkgs)} - ${types.diskoLib.mount cfg.devices} - '') - ]) ++ lib.optionals cfg.enableConfig (types.diskoLib.packages cfg.devices pkgs); - system.build.formatScript = pkgs.writers.writeDash "disko-create" '' export PATH=${lib.makeBinPath (types.diskoLib.packages cfg.devices pkgs)} ${types.diskoLib.create cfg.devices} @@ -52,7 +34,8 @@ in { ''; # This is useful to skip copying executables uploading a script to an in-memory installer - system.build.diskoNoDeps = pkgs.writers.writeBash "disko" '' + system.build.diskoNoDeps = pkgs.writeScript "disko" '' + #!/usr/bin/env bash ${types.diskoLib.zapCreateMount cfg.devices} ''; diff --git a/tests/lib.nix b/tests/lib.nix index 195abcc..6d787ed 100644 --- a/tests/lib.nix +++ b/tests/lib.nix @@ -33,7 +33,6 @@ (lib.optionalAttrs (testMode == "module") { imports = [ ../module.nix ]; disko = { - addScripts = false; enableConfig = true; devices = import disko-config { inherit disks lib; }; }; @@ -76,7 +75,6 @@ (lib.optionalAttrs (testMode == "module") { imports = [ ../module.nix ]; disko = { - addScripts = true; enableConfig = false; devices = import disko-config { disks = builtins.tail disks; inherit lib; }; }; @@ -105,7 +103,7 @@ virtualisation.emptyDiskImages = builtins.genList (_: 4096) num-disks; }; - testScript = '' + testScript = { nodes, ... }: '' def disks(oldmachine, num_disks): disk_flags = "" for i in range(num_disks): @@ -128,9 +126,9 @@ machine.succeed("${tsp-mount}") # verify that the command is idempotent ''} ${lib.optionalString (testMode == "module") '' - machine.succeed("disko-create") - machine.succeed("disko-mount") - machine.succeed("disko-mount") # verify that the command is idempotent + machine.succeed("${nodes.machine.system.build.formatScript}") + machine.succeed("${nodes.machine.system.build.mountScript}") + machine.succeed("${nodes.machine.system.build.mountScript}") # verify that the command is idempotent ''} ${lib.optionalString (testMode == "cli") '' # TODO use the disko cli here |