From ec2266b2e24e546c13e5c100c1f777bb50bcec65 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Tue, 24 Sep 2013 11:27:25 +0200 Subject: [PATCH] Make environment variables overridable --- modules/config/shells-environment.nix | 7 ++++++- tests/misc.nix | 6 ++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/modules/config/shells-environment.nix b/modules/config/shells-environment.nix index fe72194a1ab3..0bb7c4e26fe5 100644 --- a/modules/config/shells-environment.nix +++ b/modules/config/shells-environment.nix @@ -25,7 +25,12 @@ in ''; type = types.attrsOf (mkOptionType { name = "a string or a list of strings"; - check = x: builtins.isString x || isList x; + merge = xs: + let xs' = evalProperties xs; in + if isList (head xs') then concatLists xs' + else if length xs' > 1 then abort "variable in ‘environment.variables’ has multiple values" + else if !builtins.isString (head xs') then abort "variable in ‘environment.variables’ does not have a string value" + else head xs'; }); apply = mapAttrs (n: v: if isList v then concatStringsSep ":" v else v); }; diff --git a/tests/misc.nix b/tests/misc.nix index 47775ce2a1ed..e18a208fe432 100644 --- a/tests/misc.nix +++ b/tests/misc.nix @@ -8,6 +8,7 @@ { config, pkgs, ... }: { swapDevices = pkgs.lib.mkOverride 0 [ { device = "/root/swapfile"; size = 128; } ]; + environment.variables.EDITOR = pkgs.lib.mkOverride 0 "emacs"; }; testScript = @@ -52,6 +53,11 @@ subtest "reboot-wtmp", sub { $machine->succeed("last | grep reboot >&2"); }; + + # Test whether we can override environment variables. + subtest "override-env-var", sub { + $machine->succeed('[ "$EDITOR" = emacs ]'); + }; ''; }