2016-12-02 08:34:05 +01:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
cfg = config.system;
|
|
|
|
|
|
|
|
text = import ../system/write-text.nix {
|
|
|
|
inherit lib;
|
|
|
|
mkTextDerivation = pkgs.writeText;
|
|
|
|
};
|
|
|
|
|
2016-12-19 21:38:34 +01:00
|
|
|
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}'
|
|
|
|
'';
|
|
|
|
|
2016-12-02 08:34:05 +01:00
|
|
|
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..."
|
|
|
|
|
2016-12-19 21:38:34 +01:00
|
|
|
${concatMapStringsSep "\n" (attr: launchdActivation "LaunchAgents" attr.target) launchAgents}
|
|
|
|
${concatMapStringsSep "\n" (attr: launchdActivation "LaunchDaemons" attr.target) launchDaemons}
|
2016-12-02 08:34:05 +01:00
|
|
|
'';
|
|
|
|
|
|
|
|
};
|
|
|
|
}
|