mirror of
https://github.com/TECHNOFAB11/disko.git
synced 2025-12-12 08:00:05 +01:00
Merge pull request #65 from nix-community/no-deps
This commit is contained in:
commit
aca927667a
7 changed files with 52 additions and 41 deletions
15
cli.nix
15
cli.nix
|
|
@ -3,6 +3,7 @@
|
||||||
, flake ? null
|
, flake ? null
|
||||||
, flakeAttr ? null
|
, flakeAttr ? null
|
||||||
, diskoFile ? null
|
, diskoFile ? null
|
||||||
|
, noDeps ? false
|
||||||
, ... }@args:
|
, ... }@args:
|
||||||
let
|
let
|
||||||
disko = import ./. { };
|
disko = import ./. { };
|
||||||
|
|
@ -12,11 +13,21 @@ let
|
||||||
else
|
else
|
||||||
import diskoFile args;
|
import diskoFile args;
|
||||||
|
|
||||||
diskoEval = if (mode == "create") then
|
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
|
||||||
|
if (mode == "create") then
|
||||||
disko.createScript diskFormat pkgs
|
disko.createScript diskFormat pkgs
|
||||||
else if (mode == "mount") then
|
else if (mode == "mount") then
|
||||||
disko.mountScript diskFormat pkgs
|
disko.mountScript diskFormat pkgs
|
||||||
else if (mode = "zap_create_mount") then
|
else if (mode == "zap_create_mount") then
|
||||||
disko.zapCreateMount diskFormat pkgs
|
disko.zapCreateMount diskFormat pkgs
|
||||||
else
|
else
|
||||||
builtins.abort "invalid mode"
|
builtins.abort "invalid mode"
|
||||||
|
|
|
||||||
18
default.nix
18
default.nix
|
|
@ -16,18 +16,34 @@ in {
|
||||||
types = types;
|
types = types;
|
||||||
create = cfg: types.diskoLib.create (eval cfg).config.devices;
|
create = cfg: types.diskoLib.create (eval cfg).config.devices;
|
||||||
createScript = cfg: pkgs: pkgs.writeScript "disko-create" ''
|
createScript = cfg: pkgs: pkgs.writeScript "disko-create" ''
|
||||||
|
#!/usr/bin/env bash
|
||||||
export PATH=${lib.makeBinPath (types.diskoLib.packages (eval cfg).config.devices pkgs)}
|
export PATH=${lib.makeBinPath (types.diskoLib.packages (eval cfg).config.devices pkgs)}
|
||||||
${types.diskoLib.create (eval cfg).config.devices}
|
${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;
|
mount = cfg: types.diskoLib.mount (eval cfg).config.devices;
|
||||||
mountScript = cfg: pkgs: pkgs.writeScript "disko-mount" ''
|
mountScript = cfg: pkgs: pkgs.writeScript "disko-mount" ''
|
||||||
|
#!/usr/bin/env bash
|
||||||
export PATH=${lib.makeBinPath (types.diskoLib.packages (eval cfg).config.devices pkgs)}
|
export PATH=${lib.makeBinPath (types.diskoLib.packages (eval cfg).config.devices pkgs)}
|
||||||
${types.diskoLib.mount (eval cfg).config.devices}
|
${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)}
|
export PATH=${lib.makeBinPath (types.diskoLib.packages (eval cfg).config.devices pkgs)}
|
||||||
${types.diskoLib.zapCreateMount (eval cfg).config.devices}
|
${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; };
|
config = cfg: { imports = types.diskoLib.config (eval cfg).config.devices; };
|
||||||
packages = cfg: types.diskoLib.packages (eval cfg).config.devices;
|
packages = cfg: types.diskoLib.packages (eval cfg).config.devices;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
3
disko
3
disko
|
|
@ -72,6 +72,9 @@ while [[ $# -gt 0 ]]; do
|
||||||
--dry-run)
|
--dry-run)
|
||||||
dry_run=y
|
dry_run=y
|
||||||
;;
|
;;
|
||||||
|
--no-deps)
|
||||||
|
nix_args+=(--arg noDeps true)
|
||||||
|
;;
|
||||||
--show-trace)
|
--show-trace)
|
||||||
nix_args+=("$1")
|
nix_args+=("$1")
|
||||||
;;
|
;;
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
# Example to create a bios compatible gpt partition
|
# Example to create a bios compatible gpt partition
|
||||||
{ disks ? [ "/dev/vdb" ], lib, ... }: {
|
{ disks ? [ "/dev/vdb" ], lib, ... }: {
|
||||||
disk = lib.traceValSeq (lib.genAttrs [ (lib.head disks) ] (device: {
|
disk = lib.genAttrs [ (lib.head disks) ] (device: {
|
||||||
device = device;
|
device = device;
|
||||||
type = "disk";
|
type = "disk";
|
||||||
content = {
|
content = {
|
||||||
|
|
@ -31,5 +31,5 @@
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
}));
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
21
module.nix
21
module.nix
|
|
@ -16,26 +16,8 @@ in {
|
||||||
type = lib.types.bool;
|
type = lib.types.bool;
|
||||||
default = true;
|
default = true;
|
||||||
};
|
};
|
||||||
addScripts = lib.mkOption {
|
|
||||||
description = ''
|
|
||||||
add disko-create and disko-mount scripts to systemPackages.
|
|
||||||
'';
|
|
||||||
type = lib.types.bool;
|
|
||||||
default = true;
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
config = {
|
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" ''
|
system.build.formatScript = pkgs.writers.writeDash "disko-create" ''
|
||||||
export PATH=${lib.makeBinPath (types.diskoLib.packages cfg.devices pkgs)}
|
export PATH=${lib.makeBinPath (types.diskoLib.packages cfg.devices pkgs)}
|
||||||
${types.diskoLib.create cfg.devices}
|
${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
|
# 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}
|
${types.diskoLib.zapCreateMount cfg.devices}
|
||||||
'';
|
'';
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,6 @@
|
||||||
(lib.optionalAttrs (testMode == "module") {
|
(lib.optionalAttrs (testMode == "module") {
|
||||||
imports = [ ../module.nix ];
|
imports = [ ../module.nix ];
|
||||||
disko = {
|
disko = {
|
||||||
addScripts = false;
|
|
||||||
enableConfig = true;
|
enableConfig = true;
|
||||||
devices = import disko-config { inherit disks lib; };
|
devices = import disko-config { inherit disks lib; };
|
||||||
};
|
};
|
||||||
|
|
@ -76,7 +75,6 @@
|
||||||
(lib.optionalAttrs (testMode == "module") {
|
(lib.optionalAttrs (testMode == "module") {
|
||||||
imports = [ ../module.nix ];
|
imports = [ ../module.nix ];
|
||||||
disko = {
|
disko = {
|
||||||
addScripts = true;
|
|
||||||
enableConfig = false;
|
enableConfig = false;
|
||||||
devices = import disko-config { disks = builtins.tail disks; inherit lib; };
|
devices = import disko-config { disks = builtins.tail disks; inherit lib; };
|
||||||
};
|
};
|
||||||
|
|
@ -105,7 +103,7 @@
|
||||||
virtualisation.emptyDiskImages = builtins.genList (_: 4096) num-disks;
|
virtualisation.emptyDiskImages = builtins.genList (_: 4096) num-disks;
|
||||||
};
|
};
|
||||||
|
|
||||||
testScript = ''
|
testScript = { nodes, ... }: ''
|
||||||
def disks(oldmachine, num_disks):
|
def disks(oldmachine, num_disks):
|
||||||
disk_flags = ""
|
disk_flags = ""
|
||||||
for i in range(num_disks):
|
for i in range(num_disks):
|
||||||
|
|
@ -128,9 +126,9 @@
|
||||||
machine.succeed("${tsp-mount}") # verify that the command is idempotent
|
machine.succeed("${tsp-mount}") # verify that the command is idempotent
|
||||||
''}
|
''}
|
||||||
${lib.optionalString (testMode == "module") ''
|
${lib.optionalString (testMode == "module") ''
|
||||||
machine.succeed("disko-create")
|
machine.succeed("${nodes.machine.system.build.formatScript}")
|
||||||
machine.succeed("disko-mount")
|
machine.succeed("${nodes.machine.system.build.mountScript}")
|
||||||
machine.succeed("disko-mount") # verify that the command is idempotent
|
machine.succeed("${nodes.machine.system.build.mountScript}") # verify that the command is idempotent
|
||||||
''}
|
''}
|
||||||
${lib.optionalString (testMode == "cli") ''
|
${lib.optionalString (testMode == "cli") ''
|
||||||
# TODO use the disko cli here
|
# TODO use the disko cli here
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue