1
0
Fork 0
mirror of https://github.com/LnL7/nix-darwin.git synced 2024-12-14 11:57:34 +00:00

improve launchd activation

This commit is contained in:
Daiderd Jordan 2016-12-19 21:38:34 +01:00
parent 58e4f7d0cf
commit 698713f2d9
No known key found for this signature in database
GPG key ID: D02435D05B810C96

View file

@ -11,6 +11,14 @@ let
mkTextDerivation = pkgs.writeText; mkTextDerivation = pkgs.writeText;
}; };
launchdActivation = basedir: target: ''
if test -f '/Library/${basedir}/${target}'; then
launchctl unload '/Library/${basedir}/${target}'
fi
cp -f '${cfg.build.launchd}/Library/${basedir}/${target}' '/Library/${basedir}/${target}'
launchctl load '/Library/${basedir}/${target}'
'';
launchAgents = filter (f: f.enable) (attrValues config.environment.launchAgents); launchAgents = filter (f: f.enable) (attrValues config.environment.launchAgents);
launchDaemons = filter (f: f.enable) (attrValues config.environment.launchDaemons); launchDaemons = filter (f: f.enable) (attrValues config.environment.launchDaemons);
@ -51,12 +59,8 @@ in
# Set up launchd services in /Library/LaunchAgents and /Library/LaunchDaemons # Set up launchd services in /Library/LaunchAgents and /Library/LaunchDaemons
echo "setting up launchd services..." echo "setting up launchd services..."
${concatMapStringsSep "\n" (attr: "launchctl unload '/Library/LaunchAgents/${attr.target}'") launchAgents} ${concatMapStringsSep "\n" (attr: launchdActivation "LaunchAgents" attr.target) launchAgents}
${concatMapStringsSep "\n" (attr: "launchctl unload '/Library/LaunchDaemons/${attr.target}'") launchDaemons} ${concatMapStringsSep "\n" (attr: launchdActivation "LaunchDaemons" attr.target) launchDaemons}
${concatMapStringsSep "\n" (attr: "cp -f '${cfg.build.launchd}/Library/LaunchAgents/${attr.target}' '/Library/LaunchAgents/${attr.target}'") launchAgents}
${concatMapStringsSep "\n" (attr: "cp -f '${cfg.build.launchd}/Library/LaunchDaemons/${attr.target}' '/Library/LaunchDaemons/${attr.target}'") launchDaemons}
${concatMapStringsSep "\n" (attr: "launchctl load '/Library/LaunchAgents/${attr.target}'") launchAgents}
${concatMapStringsSep "\n" (attr: "launchctl load '/Library/LaunchDaemons/${attr.target}'") launchDaemons}
''; '';
}; };