diff options
| author | Daiderd Jordan <daiderd@gmail.com> | 2017-01-25 22:35:06 +0100 |
|---|---|---|
| committer | Daiderd Jordan <daiderd@gmail.com> | 2017-01-25 22:35:06 +0100 |
| commit | 0cbdc2f8f961f14abda0b23e29d3f5ee2f62ad98 (patch) | |
| tree | 162b7acf818c5bcde11cd2104b8675b573e210e0 /modules/system | |
| parent | 199808713e10a71d4c04a3d6943793f39c29b212 (diff) | |
launchd: add user agents
Diffstat (limited to 'modules/system')
| -rw-r--r-- | modules/system/activation-scripts.nix | 1 | ||||
| -rw-r--r-- | modules/system/default.nix | 1 | ||||
| -rw-r--r-- | modules/system/launchd.nix | 32 |
3 files changed, 33 insertions, 1 deletions
diff --git a/modules/system/activation-scripts.nix b/modules/system/activation-scripts.nix index 4a66996..5de7595 100644 --- a/modules/system/activation-scripts.nix +++ b/modules/system/activation-scripts.nix @@ -84,6 +84,7 @@ in umask 0022 ${cfg.activationScripts.defaults.text} + ${cfg.activationScripts.userLaunchd.text} ${cfg.activationScripts.extraUserActivation.text} exit $_status diff --git a/modules/system/default.nix b/modules/system/default.nix index efc6511..16731ed 100644 --- a/modules/system/default.nix +++ b/modules/system/default.nix @@ -92,6 +92,7 @@ in ln -s ${cfg.path} $out/sw mkdir -p $out/Library + ln -s ${cfg.build.launchd}/Library/LaunchAgents $out/Library/LaunchAgents ln -s ${cfg.build.launchd}/Library/LaunchDaemons $out/Library/LaunchDaemons echo "$activationScript" > $out/activate diff --git a/modules/system/launchd.nix b/modules/system/launchd.nix index a79c0dd..8020a08 100644 --- a/modules/system/launchd.nix +++ b/modules/system/launchd.nix @@ -13,14 +13,23 @@ let launchdActivation = basedir: target: '' if test -f '/Library/${basedir}/${target}'; then - launchctl unload '/Library/${basedir}/${target}' + launchctl unload '/Library/${basedir}/${target}' || true fi cp -f '${cfg.build.launchd}/Library/${basedir}/${target}' '/Library/${basedir}/${target}' launchctl load '/Library/${basedir}/${target}' ''; + userLaunchdActivation = target: '' + if test -f ~/Library/LaunchAgents/${target}; then + launchctl unload ~/Library/LaunchAgents/${target} || true + fi + cp -f ${cfg.build.userLaunchd}/Library/LaunchAgents/${target} ~/Library/LaunchAgents/${target} + launchctl load ~/Library/LaunchAgents/${target} + ''; + launchAgents = filter (f: f.enable) (attrValues config.environment.launchAgents); launchDaemons = filter (f: f.enable) (attrValues config.environment.launchDaemons); + userLaunchAgents = filter (f: f.enable) (attrValues config.environment.userLaunchAgents); in @@ -43,6 +52,14 @@ in ''; }; + environment.userLaunchAgents = mkOption { + type = types.loaOf (types.submodule text); + default = {}; + description = '' + Set of files that have to be linked in <filename>~/Library/LaunchAgents</filename>. + ''; + }; + }; config = { @@ -55,6 +72,12 @@ in ${concatMapStringsSep "\n" (attr: "ln -s '${attr.source}' '${attr.target}'") launchDaemons} ''; + system.build.userLaunchd = pkgs.runCommand "user-launchd" {} '' + mkdir -p $out/Library/LaunchAgents $out/Library/LaunchDaemons + cd $out/Library/LaunchAgents + ${concatMapStringsSep "\n" (attr: "ln -s '${attr.source}' '${attr.target}'") userLaunchAgents} + ''; + system.activationScripts.launchd.text = '' # Set up launchd services in /Library/LaunchAgents and /Library/LaunchDaemons echo "setting up launchd services..." @@ -63,5 +86,12 @@ in ${concatMapStringsSep "\n" (attr: launchdActivation "LaunchDaemons" attr.target) launchDaemons} ''; + system.activationScripts.userLaunchd.text = '' + # Set up launchd services in ~/Library/LaunchAgents + echo "setting up user launchd services..." + + ${concatMapStringsSep "\n" (attr: userLaunchdActivation attr.target) userLaunchAgents} + ''; + }; } |
