You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

35 lines
874 B
Nix

{ name, displayName, fakeHome, binaryPath, environmentVariables, prepare ? "", before ? null }:
{ 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"];
before = lib.mkIf (before != null) before;
serviceConfig = {
ExecStart = binaryPath;
User = name;
Restart = "on-failure";
# PermissionsStartOnly = true;
};
preStart = ''
${lib.optionalString (prepare != null) prepare}
${lib.optionalString fakeHome ''
mkdir -m 0700 -p /tmp/${name}-home
chown ${name} /tmp/${name}-home
''}
'';
environment = {
HOME = lib.mkIf fakeHome "/tmp/${name}-home";
} // environmentVariables;
};
}