nixos/simp_le: Use systemd for setting user and group
This is much cleaner and we don't depend on sudo.
This commit is contained in:
parent
1641c19d0b
commit
e7362a877d
@ -145,8 +145,12 @@ in
|
|||||||
serviceConfig = {
|
serviceConfig = {
|
||||||
Type = "oneshot";
|
Type = "oneshot";
|
||||||
SuccessExitStatus = [ "0" "1" ];
|
SuccessExitStatus = [ "0" "1" ];
|
||||||
|
PermissionsStartOnly = true;
|
||||||
|
User = data.user;
|
||||||
|
Group = data.group;
|
||||||
|
PrivateTmp = true;
|
||||||
};
|
};
|
||||||
path = [ pkgs.simp_le pkgs.sudo ];
|
path = [ pkgs.simp_le ];
|
||||||
preStart = ''
|
preStart = ''
|
||||||
mkdir -p '${cfg.directory}'
|
mkdir -p '${cfg.directory}'
|
||||||
if [ ! -d '${cpath}' ]; then
|
if [ ! -d '${cpath}' ]; then
|
||||||
@ -157,13 +161,16 @@ in
|
|||||||
script = ''
|
script = ''
|
||||||
cd '${cpath}'
|
cd '${cpath}'
|
||||||
set +e
|
set +e
|
||||||
sudo -u '${data.user}' -- simp_le ${concatMapStringsSep " " (arg: escapeShellArg (toString arg)) cmdline}
|
simp_le ${concatMapStringsSep " " (arg: escapeShellArg (toString arg)) cmdline}
|
||||||
EXITCODE=$?
|
EXITCODE=$?
|
||||||
set -e
|
set -e
|
||||||
if [ "$EXITCODE" = "0" ]; then
|
echo "$EXITCODE" > /tmp/lastExitCode
|
||||||
|
exit "$EXITCODE"
|
||||||
|
'';
|
||||||
|
postStop = ''
|
||||||
|
if [ -e /tmp/lastExitCode ] && [ "$(cat /tmp/lastExitCode)" = "0" ]; then
|
||||||
|
echo "Executing postRun hook..."
|
||||||
${data.postRun}
|
${data.postRun}
|
||||||
else
|
|
||||||
exit "$EXITCODE"
|
|
||||||
fi
|
fi
|
||||||
'';
|
'';
|
||||||
})
|
})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user