From d014ed24453949721f40ea5b3b4385d398a14a26 Mon Sep 17 00:00:00 2001 From: Daiderd Jordan Date: Wed, 25 Jan 2017 21:16:53 +0100 Subject: [PATCH] launchd: add command, path and environment options --- modules/environment/default.nix | 13 +++------- modules/launchd/default.nix | 44 +++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 9 deletions(-) diff --git a/modules/environment/default.nix b/modules/environment/default.nix index 5fa222e1..05a6c9ba 100644 --- a/modules/environment/default.nix +++ b/modules/environment/default.nix @@ -34,9 +34,7 @@ in { environment.systemPath = mkOption { type = types.loeOf types.path; default = (reverseList cfg.profiles) ++ [ "/usr/local" "/usr" "" ]; - description = '' - The set of paths that are added to PATH - ''; + description = "The set of paths that are added to PATH."; apply = x: if isList x then makeBinPath x else x; }; @@ -48,9 +46,7 @@ in { "/nix/var/nix/profiles/default" "/run/current-system/sw" ]; - description = '' - A list of profiles used to setup the global environment. - ''; + description = "A list of profiles used to setup the global environment."; }; environment.extraOutputsToInstall = mkOption { @@ -63,14 +59,13 @@ in { environment.loginShell = mkOption { type = types.str; default = "$SHELL"; - description = '' - Configure default login shell. - ''; + description = "Configure default login shell."; }; environment.variables = mkOption { type = types.attrsOf (types.either types.str (types.listOf types.str)); default = {}; + example = { EDITOR = "vim"; LANG = "nl_NL.UTF-8"; }; description = '' A set of environment variables used in the global environment. These variables will be set on shell initialisation. diff --git a/modules/launchd/default.nix b/modules/launchd/default.nix index b692e744..faf60c22 100644 --- a/modules/launchd/default.nix +++ b/modules/launchd/default.nix @@ -16,7 +16,49 @@ let serviceOptions = { config, name, ... }: + let + + cmd = config.command; + env = config.environment // optionalAttrs (config.path != "") { PATH = config.path; }; + + in + { options = { + environment = mkOption { + type = types.attrsOf (types.either types.str (types.listOf types.str)); + default = {}; + example = { PATH = "/foo/bar/bin"; LANG = "nl_NL.UTF-8"; }; + description = "Environment variables passed to the service's processes."; + apply = mapAttrs (n: v: if isList v then concatStringsSep ":" v else v); + }; + + path = mkOption { + type = types.listOf types.path; + default = []; + apply = ps: "${makeBinPath ps}"; + description = '' + Packages added to the service's PATH + environment variable. Both the bin + and sbin subdirectories of each + package are added. + ''; + }; + + command = mkOption { + type = types.either types.str types.path; + default = ""; + description = "Command executed as the service's main process."; + }; + + # preStart = mkOption { + # type = types.lines; + # default = ""; + # description = '' + # Shell commands executed before the service's main process + # is started. + # ''; + # }; + serviceConfig = mkOption { type = types.submodule launchdConfig; example = @@ -33,6 +75,8 @@ let config = { serviceConfig.Label = mkDefault "org.nixos.${name}"; + serviceConfig.ProgramArguments = mkIf (cmd != "") [ "/bin/sh" "-c" "exec ${cmd}" ]; + serviceConfig.EnvironmentVariables = mkIf (env != {}) env; }; };