disko/cli.nix

71 lines
1.7 KiB
Nix
Raw Permalink Normal View History

{ pkgs ? import <nixpkgs> { }
2023-02-02 13:02:55 +00:00
, lib ? pkgs.lib
2022-10-26 22:02:49 +00:00
, mode ? "mount"
, flake ? null
, flakeAttr ? null
, diskoFile ? null
, rootMountPoint ? "/mnt"
2022-12-01 19:33:03 +00:00
, noDeps ? false
, ...
}@args:
2022-10-26 22:02:49 +00:00
let
2022-12-22 10:09:04 +00:00
disko = import ./. {
inherit rootMountPoint;
2023-02-02 13:02:55 +00:00
inherit lib;
2022-12-22 10:09:04 +00:00
};
diskoAttr =
if noDeps then
{
format = "formatScriptNoDeps";
mount = "mountScriptNoDeps";
2023-06-23 02:57:57 +00:00
disko = "diskoScriptNoDeps";
# legacy aliases
create = "createScriptNoDeps";
zap_create_mount = "diskoScriptNoDeps";
}.${mode}
else
{
format = "formatScript";
mount = "mountScript";
disko = "diskoScript";
# legacy aliases
create = "createScript";
zap_create_mount = "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)
2022-12-01 19:33:03 +00:00
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}
2022-12-01 19:33:03 +00:00
else
(builtins.abort "couldn't find `diskoConfigurations.${flakeAttr}` or `nixosConfigurations.${flakeAttr}.config.disko.devices`");
in
diskoScript