32 lines
719 B
Nix
32 lines
719 B
Nix
|
{ name, displayName, fakeHome, binaryPath, environmentVariables }:
|
||
|
{ lib, ... }: {
|
||
|
users.groups.${name} = {};
|
||
|
users.users.${name} = {
|
||
|
description = "${name} Service User";
|
||
|
isSystemUser = true;
|
||
|
group = name;
|
||
|
};
|
||
|
|
||
|
systemd.services.${name} = {
|
||
|
description = displayName;
|
||
|
wantedBy = ["multi-user.target"];
|
||
|
after = ["network.target"];
|
||
|
|
||
|
serviceConfig = {
|
||
|
ExecStart = binaryPath;
|
||
|
User = name;
|
||
|
Restart = "on-failure";
|
||
|
# PermissionsStartOnly = true;
|
||
|
};
|
||
|
|
||
|
preStart = lib.mkIf fakeHome ''
|
||
|
mkdir -m 0700 -p /tmp/${name}-home
|
||
|
chown ${name} /tmp/${name}-home
|
||
|
'';
|
||
|
|
||
|
environment = {
|
||
|
HOME = lib.mkIf fakeHome "/tmp/${name}-home";
|
||
|
} // environmentVariables;
|
||
|
};
|
||
|
}
|