1
0
Fork 0
mirror of https://github.com/LnL7/nix-darwin.git synced 2024-12-14 11:57:34 +00:00

launchd: add command, path and environment options

This commit is contained in:
Daiderd Jordan 2017-01-25 21:16:53 +01:00
parent 44d4d2b277
commit d014ed2445
No known key found for this signature in database
GPG key ID: D02435D05B810C96
2 changed files with 48 additions and 9 deletions

View file

@ -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.

View file

@ -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 <envar>PATH</envar>
environment variable. Both the <filename>bin</filename>
and <filename>sbin</filename> 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;
};
};