[Nix-dev] NixOS configuration unit tests
Eelco Dolstra
eelco.dolstra at logicblox.com
Fri Jan 23 15:39:04 CET 2015
Hi,
On 23/01/15 15:04, Wout Mertens wrote:
> I'm thinking that it might be a good idea to have unit tests for the
> configuration.nix descriptions. That way we can be more sure that a change
> doesn't have unintended consequences.
>
> For example, we could have tests like "if you set config.foo and config.bar, the
> evaluation should fail" and "if you set config.foo then config.baz should get a
> value".
>
> One specific use case is the license whitelisting/blacklisting
> (https://github.com/NixOS/nixpkgs/pull/5892), where we don't ever want to
> inadvertently allow forbidden licenses.
>
> Any thoughts on how to implement this? An approach might be a shell script that
> runs a few nix-instantiate command lines and expects errors and values, but how
> would that integrate with the nixos tests?
Basically by adding a job like this to nixos/release.nix (not tested):
bla = runCommand "bla"
{ buildInputs = [ nix ];
src = ./..;
}
''
# Ugly hack to make read-only evaluation work.
export NIX_DB_DIR=$TMPDIR
export NIX_STATE_DIR=$TMPDIR
nix-store --init
echo '{ config.foo = true; config.bar = true; }' > foo.nix
nix-instantiate --dry-run $src/nixos -A system \
-I nixos-configuration=$(pwd)/foo.nix
...
'';
and then add this job to "tested" in nixos/release-combined.nix to make the
NixOS channel depend on it.
--
Eelco Dolstra | LogicBlox, Inc. | http://nixos.org/~eelco/
More information about the nix-dev
mailing list