1
0
Fork 0
mirror of https://github.com/LnL7/nix-darwin.git synced 2025-03-06 08:47:00 +00:00
nix-darwin/modules/launchd/default.nix
2016-12-01 23:56:20 +01:00

64 lines
1.5 KiB
Nix

{ config, lib, pkgs, ... }:
with import ./lib.nix { inherit lib; };
with lib;
let
cfg = config.launchd;
toEnvironmentText = name: value: {
name = "${value.serviceConfig.Label}.plist";
value.text = toPLIST value.serviceConfig;
};
launchdConfig = import ./launchd.nix;
serviceOptions =
{ config, name, ... }:
{ options = {
serviceConfig = mkOption {
type = types.submodule launchdConfig;
example =
{ Program = "/run/current-system/sw/bin/nix-daemon";
KeepAlive = true;
};
default = {};
description = ''
Each attribute in this set specifies an option for a <key> in the plist.
https://developer.apple.com/legacy/library/documentation/Darwin/Reference/ManPages/man5/launchd.plist.5.html
'';
};
};
config = {
serviceConfig.Label = mkDefault "org.nixos.${name}";
};
};
in
{
options = {
launchd.agents = mkOption {
default = {};
type = types.attrsOf (types.submodule serviceOptions);
description = "Definition of launchd agents.";
};
launchd.daemons = mkOption {
default = {};
type = types.attrsOf (types.submodule serviceOptions);
description = "Definition of launchd daemons.";
};
};
config = {
environment.launchAgents = mapAttrs' toEnvironmentText cfg.agents;
environment.launchDaemons = mapAttrs' toEnvironmentText cfg.daemons;
};
}