diff --git a/flake-modules/default.nix b/flake-modules/default.nix index 45b8948761..aec111f321 100644 --- a/flake-modules/default.nix +++ b/flake-modules/default.nix @@ -2,9 +2,7 @@ { imports = [ ./dev - ./helpers.nix ./lib.nix - ./legacy-packages.nix ./overlays.nix ./packages.nix ./templates.nix diff --git a/flake-modules/helpers.nix b/flake-modules/helpers.nix deleted file mode 100644 index b7ec897bfa..0000000000 --- a/flake-modules/helpers.nix +++ /dev/null @@ -1,7 +0,0 @@ -{ - perSystem = - { pkgs, ... }: - { - _module.args.helpers = import ../lib/helpers.nix { inherit pkgs; }; - }; -} diff --git a/flake-modules/legacy-packages.nix b/flake-modules/legacy-packages.nix deleted file mode 100644 index 88d7bea093..0000000000 --- a/flake-modules/legacy-packages.nix +++ /dev/null @@ -1,15 +0,0 @@ -{ - perSystem = - { - pkgs, - config, - makeNixvimWithModule, - ... - }: - { - legacyPackages = rec { - inherit makeNixvimWithModule; - makeNixvim = module: makeNixvimWithModule { inherit module; }; - }; - }; -} diff --git a/flake-modules/lib.nix b/flake-modules/lib.nix index 142ad43666..514377dfa0 100644 --- a/flake-modules/lib.nix +++ b/flake-modules/lib.nix @@ -1,11 +1,32 @@ { + self, config, lib, - withSystem, + getSystem, ... }: { - flake.lib = lib.genAttrs config.systems ( - lib.flip withSystem ({ pkgs, ... }: import ../lib { inherit pkgs lib; }) - ); + perSystem = + { self', pkgs, ... }: + { + # `helpers` is used throughout the flake modules + _module.args = { + inherit (self'.lib) helpers; + }; + + legacyPackages = { + # Export nixvim's lib in legacyPackages + lib = import ../lib { + inherit pkgs lib; + flake = self; + }; + + # Historically, we exposed these at the top-level of legacyPackages + # TODO: Consider renaming the new location, and keeping the old name here? + inherit (self'.legacyPackages.lib) makeNixvimWithModule makeNixvim; + }; + }; + + # Also expose `legacyPackages..lib` as `lib.` + flake.lib = lib.genAttrs config.systems (system: (getSystem system).legacyPackages.lib); } diff --git a/flake-modules/tests.nix b/flake-modules/tests.nix index bf80e78c76..e8b7d20506 100644 --- a/flake-modules/tests.nix +++ b/flake-modules/tests.nix @@ -1,53 +1,40 @@ -{ self, ... }: +{ self, lib, ... }: { perSystem = { + self', pkgs, pkgsUnfree, system, - helpers, - makeNixvimWithModule, ... }: let - evaluatedNixvim = helpers.modules.evalNixvim { check = false; }; + inherit (self'.legacyPackages.lib) helpers makeNixvimWithModule; + callTest = lib.callPackageWith ( + pkgs + // { + nixvimLib = self'.legacyPackages.lib; + inherit helpers makeNixvimWithModule; + inherit (self'.legacyPackages.lib.check) mkTestDerivationFromNvim mkTestDerivationFromNixvimModule; + evaluatedNixvim = helpers.modules.evalNixvim { check = false; }; + } + ); in { checks = { - extra-args-tests = import ../tests/extra-args.nix { - inherit pkgs; - inherit makeNixvimWithModule; - }; - - extend = import ../tests/extend.nix { inherit pkgs makeNixvimWithModule; }; - - extra-files = import ../tests/extra-files.nix { inherit pkgs makeNixvimWithModule; }; - - enable-except-in-tests = import ../tests/enable-except-in-tests.nix { - inherit pkgs makeNixvimWithModule; - inherit (self.lib.${system}.check) mkTestDerivationFromNixvimModule; - }; - - failing-tests = pkgs.callPackage ../tests/failing-tests.nix { - inherit (self.lib.${system}.check) mkTestDerivationFromNixvimModule; - }; - - no-flake = import ../tests/no-flake.nix { + extra-args-tests = callTest ../tests/extra-args.nix { }; + extend = callTest ../tests/extend.nix { }; + extra-files = callTest ../tests/extra-files.nix { }; + enable-except-in-tests = callTest ../tests/enable-except-in-tests.nix { }; + failing-tests = callTest ../tests/failing-tests.nix { }; + no-flake = callTest ../tests/no-flake.nix { inherit system; - inherit (self.lib.${system}.check) mkTestDerivationFromNvim; nixvim = "${self}"; }; - - lib-tests = import ../tests/lib-tests.nix { - inherit pkgs helpers; - inherit (pkgs) lib; - }; - - maintainers = import ../tests/maintainers.nix { inherit pkgs; }; - - generated = pkgs.callPackage ../tests/generated.nix { }; - - package-options = pkgs.callPackage ../tests/package-options.nix { inherit evaluatedNixvim; }; - } // import ../tests { inherit pkgs pkgsUnfree helpers; }; + lib-tests = callTest ../tests/lib-tests.nix { }; + maintainers = callTest ../tests/maintainers.nix { }; + generated = callTest ../tests/generated.nix { }; + package-options = callTest ../tests/package-options.nix { }; + } // callTest ../tests { inherit pkgsUnfree; }; }; } diff --git a/flake-modules/wrappers.nix b/flake-modules/wrappers.nix index 30fa85be2a..8f171e43ee 100644 --- a/flake-modules/wrappers.nix +++ b/flake-modules/wrappers.nix @@ -3,10 +3,6 @@ perSystem = { system, pkgs, ... }: { - _module.args = { - makeNixvimWithModule = import ../wrappers/standalone.nix pkgs self; - }; - checks = { home-manager-module = diff --git a/lib/default.nix b/lib/default.nix index 91000de15f..b67f54d2c1 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -1,12 +1,16 @@ # Args probably only needs pkgs and lib { + flake, pkgs, lib ? pkgs.lib, _nixvimTests ? false, - ... }@args: -{ +lib.fix (self: { # Add all exported modules here check = import ./tests.nix { inherit lib pkgs; }; helpers = import ./helpers.nix (args // { inherit _nixvimTests; }); -} + + # TODO: Consider renaming these? + makeNixvimWithModule = import ../wrappers/standalone.nix pkgs flake; + makeNixvim = module: self.makeNixvimWithModule { inherit module; }; +}) diff --git a/tests/default.nix b/tests/default.nix index 3ff5da3e81..a28fdfbdba 100644 --- a/tests/default.nix +++ b/tests/default.nix @@ -1,13 +1,13 @@ { - lib ? pkgs.lib, helpers, + lib, + linkFarm, pkgs, pkgsUnfree, + mkTestDerivationFromNixvimModule, }: let - fetchTests = import ./fetch-tests.nix; - test-derivation = import ../lib/tests.nix { inherit pkgs lib; }; - inherit (test-derivation) mkTestDerivationFromNixvimModule; + fetchTests = import ./fetch-tests.nix { inherit lib pkgs helpers; }; moduleToTest = name: module: @@ -17,10 +17,7 @@ let }; # List of files containing configurations - testFiles = fetchTests { - inherit lib pkgs helpers; - root = ./test-sources; - }; + testFiles = fetchTests ./test-sources; exampleFiles = { name = "examples"; @@ -44,13 +41,13 @@ in lib.pipe (testFiles ++ [ exampleFiles ]) [ (builtins.map (file: { inherit (file) name; - path = pkgs.linkFarm file.name (builtins.mapAttrs moduleToTest file.cases); + path = linkFarm file.name (builtins.mapAttrs moduleToTest file.cases); })) (helpers.groupListBySize 10) (lib.imap1 ( i: group: rec { name = "test-${toString i}"; - value = pkgs.linkFarm name group; + value = linkFarm name group; } )) builtins.listToAttrs diff --git a/tests/enable-except-in-tests.nix b/tests/enable-except-in-tests.nix index 65070198c6..2ef815e3ed 100644 --- a/tests/enable-except-in-tests.nix +++ b/tests/enable-except-in-tests.nix @@ -1,5 +1,7 @@ { pkgs, + linkFarm, + runCommandNoCCLocal, mkTestDerivationFromNixvimModule, makeNixvimWithModule, }: @@ -19,7 +21,7 @@ let let nvim = makeNixvimWithModule { inherit pkgs module; }; in - pkgs.runCommand "enable-except-in-tests-not-in-test" + runCommandNoCCLocal "enable-except-in-tests-not-in-test" { printConfig = "${nvim}/bin/nixvim-print-init"; } '' if ! "$printConfig" | grep 'require("image").setup'; then @@ -31,7 +33,7 @@ let touch $out ''; in -pkgs.linkFarm "enable-except-in-tests" [ +linkFarm "enable-except-in-tests" [ { name = "in-test"; path = inTest; diff --git a/tests/extend.nix b/tests/extend.nix index 00bd828152..507428be32 100644 --- a/tests/extend.nix +++ b/tests/extend.nix @@ -1,4 +1,7 @@ -{ makeNixvimWithModule, pkgs }: +{ + makeNixvimWithModule, + runCommandNoCCLocal, +}: let firstStage = makeNixvimWithModule { module = { @@ -10,7 +13,7 @@ let generated = secondStage.extend { extraConfigLua = "-- third stage"; }; in -pkgs.runCommand "extend-test" { printConfig = "${generated}/bin/nixvim-print-init"; } '' +runCommandNoCCLocal "extend-test" { printConfig = "${generated}/bin/nixvim-print-init"; } '' config=$($printConfig) for stage in "first" "second" "third"; do if ! "$printConfig" | grep -q -- "-- $stage stage"; then diff --git a/tests/extra-args.nix b/tests/extra-args.nix index e43f6dff12..3492b10c40 100644 --- a/tests/extra-args.nix +++ b/tests/extra-args.nix @@ -1,4 +1,7 @@ -{ makeNixvimWithModule, pkgs }: +{ + makeNixvimWithModule, + runCommandNoCCLocal, +}: let defaultModule = { regularArg, ... }: @@ -28,7 +31,7 @@ let }; }; in -pkgs.runCommand "special-arg-test" { printConfig = "${generated}/bin/nixvim-print-init"; } '' +runCommandNoCCLocal "special-arg-test" { printConfig = "${generated}/bin/nixvim-print-init"; } '' config=$($printConfig) if ! "$printConfig" | grep -- '-- regularArg=regularValue'; then echo "Missing regularArg in config" diff --git a/tests/extra-files.nix b/tests/extra-files.nix index 9f4465e04a..a333927324 100644 --- a/tests/extra-files.nix +++ b/tests/extra-files.nix @@ -1,4 +1,7 @@ -{ makeNixvimWithModule, pkgs }: +{ + makeNixvimWithModule, + runCommandNoCCLocal, +}: let extraFiles = { "one".text = "one"; @@ -12,7 +15,7 @@ let }; }; in -pkgs.runCommand "extra-files-test" +runCommandNoCCLocal "extra-files-test" { root = build.config.filesPlugin; files = builtins.attrNames extraFiles; diff --git a/tests/fetch-tests.nix b/tests/fetch-tests.nix index d522c33f08..39f03fae86 100644 --- a/tests/fetch-tests.nix +++ b/tests/fetch-tests.nix @@ -1,5 +1,4 @@ { - root, lib, pkgs, helpers, @@ -49,4 +48,4 @@ let builtins.concatLists ]; in -fetchTests root [ ] +root: fetchTests root [ ] diff --git a/tests/generated.nix b/tests/generated.nix index 28a89ff451..56c9383da3 100644 --- a/tests/generated.nix +++ b/tests/generated.nix @@ -1,7 +1,7 @@ { lib, - runCommand, pkgs, + runCommandNoCCLocal, }: let # Format a list of errors with an error message and trailing newline @@ -68,7 +68,7 @@ let } ); in -runCommand "generated-sources-test" { inherit errors; } '' +runCommandNoCCLocal "generated-sources-test" { inherit errors; } '' if [ -n "$errors" ]; then echo -n "$errors" exit 1 diff --git a/tests/lib-tests.nix b/tests/lib-tests.nix index abaecb23eb..c4ca8a42de 100644 --- a/tests/lib-tests.nix +++ b/tests/lib-tests.nix @@ -1,9 +1,10 @@ # For shorter test iterations run the following in the root of the repo: # `echo ':b checks.${builtins.currentSystem}.lib-tests' | nix repl .` { - lib, - pkgs, helpers, + lib, + runCommandNoCCLocal, + writeText, }: let luaNames = { @@ -45,9 +46,9 @@ let ]; }; - drv = pkgs.writeText "example-derivation" "hello, world!"; + drv = writeText "example-derivation" "hello, world!"; - results = pkgs.lib.runTests { + results = lib.runTests { testToLuaObject = { expr = helpers.toLuaObject { foo = "bar"; @@ -377,11 +378,11 @@ let }; in if results == [ ] then - pkgs.runCommand "lib-tests-success" { } "touch $out" + runCommandNoCCLocal "lib-tests-success" { } "touch $out" else - pkgs.runCommand "lib-tests-failure" + runCommandNoCCLocal "lib-tests-failure" { - results = pkgs.lib.concatStringsSep "\n" ( + results = lib.concatStringsSep "\n" ( builtins.map (result: '' ${result.name}: expected: ${lib.generators.toPretty { } result.expected} diff --git a/tests/maintainers.nix b/tests/maintainers.nix index a9033aacff..f99e73e34f 100644 --- a/tests/maintainers.nix +++ b/tests/maintainers.nix @@ -1,6 +1,6 @@ { - pkgs ? import { }, - lib ? pkgs.lib, + lib, + runCommandNoCCLocal, }: let inherit (lib) attrNames filter length; @@ -9,7 +9,7 @@ let duplicates = filter (name: nixpkgsList ? ${name}) (attrNames nixvimList); count = length duplicates; in -pkgs.runCommand "maintainers-test" { inherit count duplicates; } '' +runCommandNoCCLocal "maintainers-test" { inherit count duplicates; } '' if [ $count -gt 0 ]; then echo "$count nixvim maintainers are also nixpkgs maintainers:" for name in $duplicates; do