From 7854d5f18c750eb7b2df3d3511eb17224ec0e835 Mon Sep 17 00:00:00 2001 From: Matt Sturgeon Date: Wed, 15 Jan 2025 21:45:47 +0000 Subject: [PATCH 1/4] modules/test: fix expectations `lib.toJSON` -> `builtins.toJSON` --- modules/top-level/test.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/top-level/test.nix b/modules/top-level/test.nix index 79a3229c7e..fe47f87aac 100644 --- a/modules/top-level/test.nix +++ b/modules/top-level/test.nix @@ -225,12 +225,12 @@ in }; any = { predicate = v: builtins.any (lib.hasInfix v); - message = v: "Expected ${lib.toJSON v} infix to be present."; + message = v: "Expected ${builtins.toJSON v} infix to be present."; valueType = lib.types.str; }; anyExact = { predicate = builtins.elem; - message = v: "Expected ${lib.toJSON v} to be present."; + message = v: "Expected ${builtins.toJSON v} to be present."; valueType = lib.types.str; }; }; From 5192a85f3224cd2ef49da53162c0138823afd4e9 Mon Sep 17 00:00:00 2001 From: Matt Sturgeon Date: Thu, 16 Jan 2025 01:47:16 +0000 Subject: [PATCH 2/4] test/nixpkgs-module: use a fixed `runCommand` function Rather than getting `runCommand` from the pkgs instance under test, get the function from a fixed/consistent pkgs instance. --- modules/top-level/test.nix | 18 +++++++++++++++++- tests/nixpkgs-module.nix | 2 ++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/modules/top-level/test.nix b/modules/top-level/test.nix index fe47f87aac..95dc945ca9 100644 --- a/modules/top-level/test.nix +++ b/modules/top-level/test.nix @@ -169,6 +169,22 @@ in ''; internal = true; }; + + # Primarily intended for internal use, allowing us to test `pkgs` while using a `runCommand` from a different nixpkgs instance. + runCommand = lib.mkOption { + type = + with lib.types; + addCheck unspecified builtins.isFunction + // { + description = "runCommand function"; + }; + description = '' + `runCommand` function used to construct `build.test`. + ''; + defaultText = lib.literalExpression "pkgs.runCommandLocal"; + default = pkgs.runCommandLocal; + internal = true; + }; }; options.build = { @@ -238,7 +254,7 @@ in build.test = assert lib.assertMsg (cfg.runNvim -> cfg.buildNixvim) "`test.runNvim` requires `test.buildNixvim`."; - pkgs.runCommandLocal cfg.name + cfg.runCommand cfg.name { nativeBuildInputs = lib.optionals cfg.buildNixvim [ config.build.packageUnchecked diff --git a/tests/nixpkgs-module.nix b/tests/nixpkgs-module.nix index 20e3bed1a3..db6556cd9d 100644 --- a/tests/nixpkgs-module.nix +++ b/tests/nixpkgs-module.nix @@ -4,6 +4,7 @@ linkFarmFromDrvs, self, stdenv, + runCommandLocal, }: let @@ -19,6 +20,7 @@ let inherit name; buildNixvim = false; runNvim = false; + runCommand = runCommandLocal; }; } ]; From e13b2a51296cccc6bc975ab2dbd6a4e2c2b60efc Mon Sep 17 00:00:00 2001 From: Matt Sturgeon Date: Wed, 15 Jan 2025 21:49:27 +0000 Subject: [PATCH 3/4] tests/nixpkgs-module: split up helper fn --- tests/nixpkgs-module.nix | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/tests/nixpkgs-module.nix b/tests/nixpkgs-module.nix index db6556cd9d..f592f3494e 100644 --- a/tests/nixpkgs-module.nix +++ b/tests/nixpkgs-module.nix @@ -10,23 +10,22 @@ let defaultPkgs = pkgs; - testModule = + evalModule = name: module: - let - configuration = lib.nixvim.modules.evalNixvim { - modules = lib.toList module ++ [ - { - test = { - inherit name; - buildNixvim = false; - runNvim = false; - runCommand = runCommandLocal; - }; - } - ]; - }; - in - configuration.config.build.test; + lib.nixvim.modules.evalNixvim { + modules = lib.toList module ++ [ + { + test = { + inherit name; + buildNixvim = false; + runNvim = false; + runCommand = runCommandLocal; + }; + } + ]; + }; + + testModule = name: module: (evalModule name module).config.build.test; in linkFarmFromDrvs "nixpkgs-module-test" [ From d4c67764a7d4e5dbda611933005560cc5bfcfb3f Mon Sep 17 00:00:00 2001 From: Matt Sturgeon Date: Thu, 16 Jan 2025 02:53:27 +0000 Subject: [PATCH 4/4] tests/nixpkgs-module: only import the minimal modules for test Instead of importing the full set of top-level nixvim modules, only import the nixpkgs-module and its direct dependencies. --- tests/nixpkgs-module.nix | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tests/nixpkgs-module.nix b/tests/nixpkgs-module.nix index f592f3494e..ba04381b8a 100644 --- a/tests/nixpkgs-module.nix +++ b/tests/nixpkgs-module.nix @@ -10,11 +10,14 @@ let defaultPkgs = pkgs; + # Only imports the bare minimum modules, to ensure we are not accidentally evaluating `pkgs.*` evalModule = name: module: - lib.nixvim.modules.evalNixvim { + lib.evalModules { modules = lib.toList module ++ [ { + _module.check = false; + flake = self; test = { inherit name; buildNixvim = false; @@ -22,6 +25,9 @@ let runCommand = runCommandLocal; }; } + ../modules/misc + ../modules/top-level/test.nix + ../modules/top-level/nixpkgs.nix ]; };