Abstract daemon setup
parent
ac895afd28
commit
bc4af3390c
@ -0,0 +1,31 @@
|
|||||||
|
{ 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;
|
||||||
|
};
|
||||||
|
}
|
Loading…
Reference in New Issue