Make environment variables overridable

This commit is contained in:
Eelco Dolstra 2013-09-24 11:27:25 +02:00
parent b933b15d72
commit ec2266b2e2
2 changed files with 12 additions and 1 deletions

View File

@ -25,7 +25,12 @@ in
''; '';
type = types.attrsOf (mkOptionType { type = types.attrsOf (mkOptionType {
name = "a string or a list of strings"; 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); apply = mapAttrs (n: v: if isList v then concatStringsSep ":" v else v);
}; };

View File

@ -8,6 +8,7 @@
{ config, pkgs, ... }: { config, pkgs, ... }:
{ swapDevices = pkgs.lib.mkOverride 0 { swapDevices = pkgs.lib.mkOverride 0
[ { device = "/root/swapfile"; size = 128; } ]; [ { device = "/root/swapfile"; size = 128; } ];
environment.variables.EDITOR = pkgs.lib.mkOverride 0 "emacs";
}; };
testScript = testScript =
@ -52,6 +53,11 @@
subtest "reboot-wtmp", sub { subtest "reboot-wtmp", sub {
$machine->succeed("last | grep reboot >&2"); $machine->succeed("last | grep reboot >&2");
}; };
# Test whether we can override environment variables.
subtest "override-env-var", sub {
$machine->succeed('[ "$EDITOR" = emacs ]');
};
''; '';
} }