forked from nix-community/disko
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli.nix
64 lines (57 loc) · 1.59 KB
/
cli.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
{ pkgs ? import <nixpkgs> { }
, lib ? pkgs.lib
, mode ? "mount"
, flake ? null
, flakeAttr ? null
, diskoFile ? null
, rootMountPoint ? "/mnt"
, noDeps ? false
, ...
}@args:
let
disko = import ./. {
inherit rootMountPoint;
inherit lib;
};
diskoAttr =
if noDeps then
{
create = "createScriptNoDeps";
mount = "mountScriptNoDeps";
zap_create_mount = "diskoScriptNoDeps";
disko = "diskoScriptNoDeps";
}.${mode}
else
{
create = "createScript";
mount = "mountScript";
zap_create_mount = "diskoScript";
disko = "diskoScript";
}.${mode};
hasDiskoConfigFlake =
diskoFile != null || 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
import diskoFile
else
(builtins.getFlake flake).diskoConfigurations.${flakeAttr};
in
if builtins.isFunction diskoConfig then
diskoConfig ({ inherit lib; } // args)
else
diskoConfig;
diskoEval =
disko.${diskoAttr} diskFormat pkgs;
diskoScript =
if hasDiskoConfigFlake then
diskoEval
else if (lib.traceValSeq hasDiskoModuleFlake) then
(builtins.getFlake flake).nixosConfigurations.${flakeAttr}.config.system.build.${diskoAttr}
else
(builtins.abort "neither diskoConfigurations.${flakeAttr} nor nixosConfigurations.${flakeAttr} found");
in
diskoScript