nixos/klipper: Allow specifying arbitrary user/group

This paves the way for alternative integrations such as
Moonraker.
This commit is contained in:
Zhaofeng Li 2021-07-18 21:34:45 -07:00
parent 942d45f74e
commit 94536fd6e3

View file

@ -17,6 +17,26 @@ in
description = "Allows Octoprint to control Klipper.";
};
user = mkOption {
type = types.nullOr types.str;
default = null;
description = ''
User account under which Klipper runs.
If null is specified (default), a temporary user will be created by systemd.
'';
};
group = mkOption {
type = types.nullOr types.str;
default = null;
description = ''
Group account under which Klipper runs.
If null is specified (default), a temporary user will be created by systemd.
'';
};
settings = mkOption {
type = format.type;
default = { };
@ -30,13 +50,24 @@ in
##### implementation
config = mkIf cfg.enable {
assertions = [{
assertion = cfg.octoprintIntegration -> config.services.octoprint.enable;
message = "Option klipper.octoprintIntegration requires Octoprint to be enabled on this system. Please enable services.octoprint to use it.";
}];
assertions = [
{
assertion = cfg.octoprintIntegration -> config.services.octoprint.enable;
message = "Option klipper.octoprintIntegration requires Octoprint to be enabled on this system. Please enable services.octoprint to use it.";
}
{
assertion = cfg.user != null -> cfg.group != null;
message = "Option klipper.group is not set when a user is specified.";
}
];
environment.etc."klipper.cfg".source = format.generate "klipper.cfg" cfg.settings;
services.klipper = mkIf cfg.octoprintIntegration {
user = config.services.octoprint.user;
group = config.services.octoprint.group;
};
systemd.services.klipper = {
description = "Klipper 3D Printer Firmware";
wantedBy = [ "multi-user.target" ];
@ -47,9 +78,9 @@ in
RuntimeDirectory = "klipper";
SupplementaryGroups = [ "dialout" ];
WorkingDirectory = "${package}/lib";
} // (if cfg.octoprintIntegration then {
Group = config.services.octoprint.group;
User = config.services.octoprint.user;
} // (if cfg.user != null then {
Group = cfg.group;
User = cfg.user;
} else {
DynamicUser = true;
User = "klipper";