summaryrefslogtreecommitdiff
path: root/modules/system
diff options
context:
space:
mode:
authorDaiderd Jordan <daiderd@gmail.com>2016-12-02 08:34:05 +0100
committerDaiderd Jordan <daiderd@gmail.com>2016-12-02 08:34:05 +0100
commit12aa7e581568f61f69a1bd0da905d6f58f083e2a (patch)
tree825da26c14b5a0e1e61167ccf3739e23dbc109b1 /modules/system
parentfecd4bc368de258158fa71edd9bf0645fb457dbb (diff)
added missing launchd activation
Diffstat (limited to 'modules/system')
-rw-r--r--modules/system/launchd.nix63
1 files changed, 63 insertions, 0 deletions
diff --git a/modules/system/launchd.nix b/modules/system/launchd.nix
new file mode 100644
index 0000000..fc85af4
--- /dev/null
+++ b/modules/system/launchd.nix
@@ -0,0 +1,63 @@
+{ config, lib, pkgs, ... }:
+
+with lib;
+
+let
+
+ cfg = config.system;
+
+ text = import ../system/write-text.nix {
+ inherit lib;
+ mkTextDerivation = pkgs.writeText;
+ };
+
+ launchAgents = filter (f: f.enable) (attrValues config.environment.launchAgents);
+ launchDaemons = filter (f: f.enable) (attrValues config.environment.launchDaemons);
+
+in
+
+{
+ options = {
+
+ environment.launchAgents = mkOption {
+ type = types.loaOf (types.submodule text);
+ default = {};
+ description = ''
+ Set of files that have to be linked in <filename>/Library/LaunchAgents</filename>.
+ '';
+ };
+
+ environment.launchDaemons = mkOption {
+ type = types.loaOf (types.submodule text);
+ default = {};
+ description = ''
+ Set of files that have to be linked in <filename>/Library/LaunchDaemons</filename>.
+ '';
+ };
+
+ };
+
+ config = {
+
+ system.build.launchd = pkgs.runCommand "launchd" {} ''
+ mkdir -p $out/Library/LaunchAgents $out/Library/LaunchDaemons
+ cd $out/Library/LaunchAgents
+ ${concatMapStringsSep "\n" (attr: "ln -s '${attr.source}' '${attr.target}'") launchAgents}
+ cd $out/Library/LaunchDaemons
+ ${concatMapStringsSep "\n" (attr: "ln -s '${attr.source}' '${attr.target}'") launchDaemons}
+ '';
+
+ system.activationScripts.launchd.text = ''
+ # 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}
+ '';
+
+ };
+}