From 7aa0fa372dc14d9f7fadb9737d398a33e8c72504 Mon Sep 17 00:00:00 2001 From: Matt Sturgeon Date: Wed, 28 Aug 2024 07:49:23 +0100 Subject: [PATCH] lib: include standalone wrapper in top-level `lib` - Defragment lib-related flake-modules - Expose the standalone-wrapper functions in the `lib` --- flake-modules/default.nix | 2 -- flake-modules/helpers.nix | 7 ------- flake-modules/legacy-packages.nix | 15 --------------- flake-modules/lib.nix | 29 +++++++++++++++++++++++++---- flake-modules/tests.nix | 18 +++++++----------- flake-modules/wrappers.nix | 4 ---- lib/default.nix | 10 +++++++--- 7 files changed, 39 insertions(+), 46 deletions(-) delete mode 100644 flake-modules/helpers.nix delete mode 100644 flake-modules/legacy-packages.nix 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..395c54d071 100644 --- a/flake-modules/tests.nix +++ b/flake-modules/tests.nix @@ -2,39 +2,35 @@ { perSystem = { + self', pkgs, pkgsUnfree, system, - helpers, - makeNixvimWithModule, ... }: let + inherit (self'.legacyPackages.lib) 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; - }; + extra-args-tests = import ../tests/extra-args.nix { inherit pkgs 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; + inherit pkgs makeNixvimWithModule mkTestDerivationFromNixvimModule; }; failing-tests = pkgs.callPackage ../tests/failing-tests.nix { - inherit (self.lib.${system}.check) mkTestDerivationFromNixvimModule; + inherit mkTestDerivationFromNixvimModule; }; no-flake = import ../tests/no-flake.nix { - inherit system; - inherit (self.lib.${system}.check) mkTestDerivationFromNvim; + inherit system mkTestDerivationFromNvim; nixvim = "${self}"; }; 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; }; +})