2022-10-23 13:29:30 +03:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
let
|
2023-05-16 14:40:03 +03:00
|
|
|
diskoLib = import ./lib {
|
2023-01-24 17:57:17 +03:00
|
|
|
inherit lib;
|
2023-02-07 18:37:12 +03:00
|
|
|
rootMountPoint = config.disko.rootMountPoint;
|
2023-01-24 17:57:17 +03:00
|
|
|
};
|
2022-10-23 13:29:30 +03:00
|
|
|
cfg = config.disko;
|
2023-01-30 23:36:51 +03:00
|
|
|
checked = cfg.checkScripts;
|
2023-02-06 17:24:34 +03:00
|
|
|
in
|
|
|
|
{
|
2022-10-23 13:29:30 +03:00
|
|
|
options.disko = {
|
|
|
|
devices = lib.mkOption {
|
2023-05-16 14:40:03 +03:00
|
|
|
type = diskoLib.devices;
|
2023-02-06 17:24:34 +03:00
|
|
|
default = { };
|
2023-01-03 21:52:57 +03:00
|
|
|
description = "The devices to set up";
|
2022-10-23 13:29:30 +03:00
|
|
|
};
|
2023-01-24 17:57:17 +03:00
|
|
|
rootMountPoint = lib.mkOption {
|
|
|
|
type = lib.types.str;
|
|
|
|
default = "/mnt";
|
|
|
|
description = "Where the device tree should be mounted by the mountScript";
|
|
|
|
};
|
2022-10-23 13:29:30 +03:00
|
|
|
enableConfig = lib.mkOption {
|
|
|
|
description = ''
|
|
|
|
configure nixos with the specified devices
|
|
|
|
should be true if the system is booted with those devices
|
|
|
|
should be false on an installer image etc.
|
|
|
|
'';
|
|
|
|
type = lib.types.bool;
|
|
|
|
default = true;
|
|
|
|
};
|
2023-01-30 23:36:51 +03:00
|
|
|
checkScripts = lib.mkOption {
|
|
|
|
description = ''
|
|
|
|
Whether to run shellcheck on script outputs
|
|
|
|
'';
|
|
|
|
type = lib.types.bool;
|
|
|
|
default = false;
|
|
|
|
};
|
2022-10-23 13:29:30 +03:00
|
|
|
};
|
2023-02-06 17:24:34 +03:00
|
|
|
config = lib.mkIf (cfg.devices.disk != { }) {
|
2023-05-16 14:40:03 +03:00
|
|
|
system.build.formatScript = (diskoLib.writeCheckedBash { inherit pkgs checked; }) "disko-create" ''
|
|
|
|
export PATH=${lib.makeBinPath (diskoLib.packages cfg.devices pkgs)}:$PATH
|
|
|
|
${diskoLib.create cfg.devices}
|
2022-11-23 15:29:51 +03:00
|
|
|
'';
|
|
|
|
|
2023-05-16 14:40:03 +03:00
|
|
|
system.build.mountScript = (diskoLib.writeCheckedBash { inherit pkgs checked; }) "disko-mount" ''
|
|
|
|
export PATH=${lib.makeBinPath (diskoLib.packages cfg.devices pkgs)}:$PATH
|
|
|
|
${diskoLib.mount cfg.devices}
|
2022-11-23 15:29:51 +03:00
|
|
|
'';
|
|
|
|
|
2023-05-16 14:40:03 +03:00
|
|
|
system.build.disko = (diskoLib.writeCheckedBash { inherit pkgs checked; }) "disko" ''
|
|
|
|
export PATH=${lib.makeBinPath (diskoLib.packages cfg.devices pkgs)}:$PATH
|
|
|
|
${diskoLib.zapCreateMount cfg.devices}
|
2022-11-23 15:29:51 +03:00
|
|
|
'';
|
|
|
|
|
2022-11-27 18:50:43 +03:00
|
|
|
# This is useful to skip copying executables uploading a script to an in-memory installer
|
2023-05-16 14:40:03 +03:00
|
|
|
system.build.diskoNoDeps = (diskoLib.writeCheckedBash { inherit pkgs checked; noDeps = true; }) "disko" ''
|
|
|
|
${diskoLib.zapCreateMount cfg.devices}
|
2022-11-27 18:50:43 +03:00
|
|
|
'';
|
|
|
|
|
2022-10-23 13:29:30 +03:00
|
|
|
# Remember to add config keys here if they are added to types
|
2023-05-16 14:40:03 +03:00
|
|
|
fileSystems = lib.mkIf cfg.enableConfig (lib.mkMerge (lib.catAttrs "fileSystems" (diskoLib.config cfg.devices)));
|
|
|
|
boot = lib.mkIf cfg.enableConfig (lib.mkMerge (lib.catAttrs "boot" (diskoLib.config cfg.devices)));
|
|
|
|
swapDevices = lib.mkIf cfg.enableConfig (lib.mkMerge (lib.catAttrs "swapDevices" (diskoLib.config cfg.devices)));
|
2022-10-23 13:29:30 +03:00
|
|
|
};
|
|
|
|
}
|