From 698713f2d92a76aff71699eb7b384c3bec74bb62 Mon Sep 17 00:00:00 2001 From: Daiderd Jordan Date: Mon, 19 Dec 2016 21:38:34 +0100 Subject: [PATCH] improve launchd activation --- modules/system/launchd.nix | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/modules/system/launchd.nix b/modules/system/launchd.nix index fc85af4f..4083353a 100644 --- a/modules/system/launchd.nix +++ b/modules/system/launchd.nix @@ -11,6 +11,14 @@ let 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); launchDaemons = filter (f: f.enable) (attrValues config.environment.launchDaemons); @@ -51,12 +59,8 @@ in # Set up launchd services in /Library/LaunchAgents and /Library/LaunchDaemons echo "setting up launchd services..." - ${concatMapStringsSep "\n" (attr: "launchctl unload '/Library/LaunchAgents/${attr.target}'") launchAgents} - ${concatMapStringsSep "\n" (attr: "launchctl unload '/Library/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} + ${concatMapStringsSep "\n" (attr: launchdActivation "LaunchAgents" attr.target) launchAgents} + ${concatMapStringsSep "\n" (attr: launchdActivation "LaunchDaemons" attr.target) launchDaemons} ''; };