2022-11-19 16:14:18 +01:00
|
|
|
{ lib, config, ... }:
|
2022-06-21 01:47:36 +02:00
|
|
|
let
|
|
|
|
inherit (lib) types mkEnableOption mkOption mkIf;
|
|
|
|
cfg = config.machineVars;
|
|
|
|
in {
|
|
|
|
options.machineVars = {
|
|
|
|
headless = mkEnableOption "Whether or not the machine should have graphical output.";
|
|
|
|
|
|
|
|
screens = mkOption {
|
|
|
|
type = types.attrsOf (types.submodule ( { name, ...}: {
|
|
|
|
options = {
|
|
|
|
name = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = name;
|
|
|
|
example = "DP-1";
|
|
|
|
description = "The name of the screen";
|
|
|
|
};
|
|
|
|
|
2022-11-20 17:12:27 +01:00
|
|
|
primary = mkEnableOption "Whether this screen should be the primary one. There can only be one primary screen";
|
|
|
|
|
|
|
|
resolution = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
example = "3840x2160";
|
|
|
|
default = "1920x1080";
|
|
|
|
description = "The resolution of the screen";
|
|
|
|
};
|
|
|
|
|
|
|
|
frequency = mkOption {
|
|
|
|
type = types.ints.positive;
|
|
|
|
example = 144;
|
|
|
|
default = 60;
|
2022-06-21 01:47:36 +02:00
|
|
|
description = "The update frequency of the screen, defined in Hz";
|
|
|
|
};
|
2022-11-20 17:12:27 +01:00
|
|
|
|
|
|
|
position = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
example = "1920x0";
|
|
|
|
default = "0x0";
|
|
|
|
description = "The position of the screen, compared to the other screens";
|
|
|
|
};
|
2022-06-21 01:47:36 +02:00
|
|
|
};
|
|
|
|
}));
|
|
|
|
default = { };
|
|
|
|
description = "A detailed description of the machines screens.";
|
|
|
|
};
|
|
|
|
|
|
|
|
gaming = mkEnableOption "Whether or not the machine should have gaming software installed.";
|
|
|
|
development = mkEnableOption "Whether or not the machine should come with developmen
|
|
|
|
t tools preinstalled.";
|
|
|
|
creative = mkEnableOption "Whether or not the machine should have creative software
|
|
|
|
(music, video and image editing) installed.";
|
|
|
|
|
2022-08-19 03:49:21 +02:00
|
|
|
wlanInterface = mkOption {
|
|
|
|
type = types.nullOr types.string;
|
|
|
|
default = null;
|
|
|
|
};
|
|
|
|
|
|
|
|
# Check " ls -1 /sys/class/power_supply/ "
|
|
|
|
battery = mkOption {
|
|
|
|
type = types.nullOr types.string;
|
|
|
|
default = null;
|
|
|
|
};
|
|
|
|
|
2022-06-21 01:47:36 +02:00
|
|
|
laptop = mkEnableOption "Whether the machine is a laptop";
|
|
|
|
|
|
|
|
fixDisplayCommand = mkOption {
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
default = null;
|
|
|
|
};
|
2022-06-22 20:16:57 +02:00
|
|
|
|
2022-08-16 03:24:06 +02:00
|
|
|
dataDrives = let
|
2022-06-22 20:16:57 +02:00
|
|
|
driveType =
|
2022-08-16 03:24:06 +02:00
|
|
|
types.path;
|
|
|
|
# types.addCheck types.path (path: builtins.elem path (builtins.attrNames config.fileSystems));
|
2022-06-22 20:16:57 +02:00
|
|
|
in {
|
|
|
|
drives = mkOption {
|
|
|
|
type = types.attrsOf driveType;
|
|
|
|
default = { };
|
|
|
|
example = {
|
|
|
|
dataDrive1 = "/data/data1";
|
|
|
|
dataDrive2 = "/another/location";
|
|
|
|
};
|
|
|
|
description = ''
|
|
|
|
Drives that should act as data drives.
|
|
|
|
These need to be registered in `fileSystems`
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
default = mkOption {
|
|
|
|
type = types.nullOr driveType;
|
|
|
|
description = ''
|
|
|
|
Data drive that should be used for most purposes.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
2022-06-21 01:47:36 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
config = {
|
|
|
|
assertions = [
|
|
|
|
{
|
|
|
|
assertion = cfg.headless -> !cfg.creative;
|
|
|
|
message = "A headless machine can't have creative software installed.";
|
|
|
|
}
|
|
|
|
{
|
|
|
|
assertion = cfg.headless -> !cfg.gaming;
|
|
|
|
message = "A headless machine can't have gaming software installed.";
|
|
|
|
}
|
|
|
|
{
|
|
|
|
assertion = cfg.headless -> (cfg.screens == { } && cfg.fixDisplayCommand == null);
|
|
|
|
message = "A headless machine can't have any screens.";
|
|
|
|
}
|
2022-08-19 03:49:21 +02:00
|
|
|
{
|
|
|
|
assertion = cfg.battery != null -> cfg.laptop;
|
|
|
|
message = "A battery shouldn't exist on a non laptop machine";
|
|
|
|
}
|
2022-11-20 17:12:27 +01:00
|
|
|
# FIXME:
|
|
|
|
# {
|
|
|
|
# assertion = map () (cfg.screens)
|
|
|
|
# message = "There can only be one primary screen.";
|
|
|
|
# }
|
2022-06-21 01:47:36 +02:00
|
|
|
];
|
|
|
|
|
|
|
|
warnings = lib.optionals (0 < (lib.length (builtins.attrNames cfg.screens)) && (cfg.fixDisplayCommand != null)) [
|
|
|
|
"You are overriding the fixDisplayCommand even though machineVars.screens is defined. One of these should be omitted"
|
|
|
|
];
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|