2022-10-23 10:29:30 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
let
|
|
|
|
types = import ./types.nix { inherit lib; };
|
|
|
|
cfg = config.disko;
|
|
|
|
in {
|
|
|
|
options.disko = {
|
|
|
|
devices = lib.mkOption {
|
2022-12-27 17:47:49 +00:00
|
|
|
type = types.devices;
|
|
|
|
default = {};
|
2023-01-03 18:52:57 +00:00
|
|
|
description = "The devices to set up";
|
2022-10-23 10:29:30 +00: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;
|
|
|
|
};
|
|
|
|
};
|
2022-12-27 17:47:49 +00:00
|
|
|
config = lib.mkIf (cfg.devices.disk != {}) {
|
2023-01-15 16:28:23 +00:00
|
|
|
system.build.formatScript = pkgs.writers.writeBash "disko-create" ''
|
2022-12-10 00:03:17 +00:00
|
|
|
export PATH=${lib.makeBinPath (types.diskoLib.packages cfg.devices pkgs)}:$PATH
|
2022-11-23 12:29:51 +00:00
|
|
|
${types.diskoLib.create cfg.devices}
|
|
|
|
'';
|
|
|
|
|
2023-01-15 16:28:23 +00:00
|
|
|
system.build.mountScript = pkgs.writers.writeBash "disko-mount" ''
|
2022-12-10 00:03:17 +00:00
|
|
|
export PATH=${lib.makeBinPath (types.diskoLib.packages cfg.devices pkgs)}:$PATH
|
2022-11-23 12:29:51 +00:00
|
|
|
${types.diskoLib.mount cfg.devices}
|
|
|
|
'';
|
|
|
|
|
2022-11-25 11:52:40 +00:00
|
|
|
system.build.disko = pkgs.writers.writeBash "disko" ''
|
2022-12-10 00:03:17 +00:00
|
|
|
export PATH=${lib.makeBinPath (types.diskoLib.packages cfg.devices pkgs)}:$PATH
|
2022-11-23 12:29:51 +00:00
|
|
|
${types.diskoLib.zapCreateMount cfg.devices}
|
|
|
|
'';
|
|
|
|
|
2022-11-27 15:50:43 +00:00
|
|
|
# This is useful to skip copying executables uploading a script to an in-memory installer
|
2022-11-29 09:53:56 +00:00
|
|
|
system.build.diskoNoDeps = pkgs.writeScript "disko" ''
|
|
|
|
#!/usr/bin/env bash
|
2022-11-27 15:50:43 +00:00
|
|
|
${types.diskoLib.zapCreateMount cfg.devices}
|
|
|
|
'';
|
|
|
|
|
2022-10-23 10:29:30 +00:00
|
|
|
# Remember to add config keys here if they are added to types
|
|
|
|
fileSystems = lib.mkIf cfg.enableConfig (lib.mkMerge (lib.catAttrs "fileSystems" (types.diskoLib.config cfg.devices)));
|
|
|
|
boot = lib.mkIf cfg.enableConfig (lib.mkMerge (lib.catAttrs "boot" (types.diskoLib.config cfg.devices)));
|
2022-11-05 20:17:35 +00:00
|
|
|
swapDevices = lib.mkIf cfg.enableConfig (lib.mkMerge (lib.catAttrs "swapDevices" (types.diskoLib.config cfg.devices)));
|
2022-10-23 10:29:30 +00:00
|
|
|
};
|
|
|
|
}
|