From cc58d3195342fee3574b5544565696a210d5d5ea Mon Sep 17 00:00:00 2001 From: Andrew Marshall Date: Sat, 26 Nov 2022 19:37:24 -0500 Subject: [PATCH] flake: Expose tests to allow running purely (#3412) * flake: Expose tests to allow running purely The existing way to run tests with `nix-shell` relies on impure usage of ``. This can lead to failures when the local nixpkgs is incompatible with the locked one. I.e., where CI is passing but a contributor may experience a failure. So, expose tests as `devShells.tests` to use the locked nixpkgs and allow easy invocation via `nix develop`. * tests: Remove impure path With Nix 2.10+ and pure evaluation mode e.g. ``` nix run nixpkgs/nixos-unstable#nixVersions.nix_2_10 -- develop -i .#tests.zplug-modules ``` this test would fail with: > error: the path '~/.customZplugHome' can not be resolved in pure mode Since the test only cares that it is a path, rather than anything about its contents, use a dummy empty directory. --- docs/contributing.adoc | 5 +++++ flake.nix | 2 ++ tests/modules/programs/zplug/modules.nix | 2 +- 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/docs/contributing.adoc b/docs/contributing.adoc index 0b440993..82a07a9a 100644 --- a/docs/contributing.adoc +++ b/docs/contributing.adoc @@ -256,3 +256,8 @@ and run an individual test, for example `alacritty-empty-settings`, through [source,console] $ nix-shell --pure tests -A run.alacritty-empty-settings + +However, those invocations will impurely source the system’s nixpkgs, and may cause failures. To run against the nixpkgs from the flake.lock, use instead e.g. + +[source,console] +$ nix develop --ignore-environment .#tests.all diff --git a/flake.nix b/flake.nix index 2a1af863..51211170 100644 --- a/flake.nix +++ b/flake.nix @@ -88,7 +88,9 @@ let pkgs = nixpkgs.legacyPackages.${system}; docs = import ./docs { inherit pkgs; }; + tests = import ./tests { inherit pkgs; }; in { + devShells.tests = tests.run; packages = rec { home-manager = pkgs.callPackage ./home-manager { }; docs-html = docs.manual.html; diff --git a/tests/modules/programs/zplug/modules.nix b/tests/modules/programs/zplug/modules.nix index 7c4abbc4..9f4d4332 100644 --- a/tests/modules/programs/zplug/modules.nix +++ b/tests/modules/programs/zplug/modules.nix @@ -8,7 +8,7 @@ with lib; enable = true; zplug = { enable = true; - zplugHome = ~/.customZplugHome; + zplugHome = pkgs.emptyDirectory; plugins = [ { name = "plugins/git";