diff --git a/modules/config/shells-environment.nix b/modules/config/shells-environment.nix index fe72194a1ab..0bb7c4e26fe 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 47775ce2a1e..e18a208fe43 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 ]'); + }; ''; }