From ce690db770d88decba4d279b05a4ef2af7a67204 Mon Sep 17 00:00:00 2001 From: Daiderd Jordan Date: Wed, 19 Oct 2016 23:25:15 +0200 Subject: added support for environment.variables --- modules/environment.nix | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'modules') diff --git a/modules/environment.nix b/modules/environment.nix index 68c5677..ace1b1c 100644 --- a/modules/environment.nix +++ b/modules/environment.nix @@ -6,6 +6,12 @@ let cfg = config.environment; + exportVariables = + mapAttrsToList (n: v: ''export ${n}="${v}"'') cfg.variables; + + exportedEnvVars = + concatStringsSep "\n" exportVariables; + in { options = { @@ -31,10 +37,28 @@ in { description = "List of additional package outputs to be symlinked into /run/current-system/sw."; }; + environment.variables = mkOption { + default = {}; + description = '' + A set of environment variables used in the global environment. + These variables will be set on shell initialisation. + The value of each variable can be either a string or a list of + strings. The latter is concatenated, interspersed with colon + characters. + ''; + type = types.attrsOf (types.loeOf types.str); + apply = mapAttrs (n: v: if isList v then concatStringsSep ":" v else v); + }; + + }; config = { + system.build.setEnvironment = pkgs.writeText "set-environment" '' + ${exportedEnvVars} + ''; + system.path = pkgs.buildEnv { name = "system-path"; paths = cfg.systemPackages; -- cgit v1.2.3