diff --git a/flake-modules/wrappers.nix b/flake-modules/wrappers.nix index 30fa85be2a..084f5ce0ab 100644 --- a/flake-modules/wrappers.nix +++ b/flake-modules/wrappers.nix @@ -1,10 +1,18 @@ -{ inputs, self, ... }: +{ + inputs, + self, + lib, + ... +}: { perSystem = { system, pkgs, ... }: { _module.args = { - makeNixvimWithModule = import ../wrappers/standalone.nix pkgs self; + makeNixvimWithModule = import ../wrappers/standalone.nix { + inherit lib self; + defaultSystem = system; + }; }; checks = diff --git a/lib/tests.nix b/lib/tests.nix index 2363750514..168d9e3cde 100644 --- a/lib/tests.nix +++ b/lib/tests.nix @@ -30,7 +30,8 @@ let mkTestDerivationFromNixvimModule = { name ? null, - pkgs ? defaultPkgs, + pkgs ? null, + system ? defaultPkgs.stdenv.hostPlatform.system, module, extraSpecialArgs ? { }, }: @@ -42,14 +43,18 @@ let _nixvimTests = true; }; + systemMod = + if pkgs == null then + { nixpkgs.hostPlatform = lib.mkDefault { inherit system; }; } + else + { nixpkgs.pkgs = lib.mkDefault pkgs; }; + result = helpers.modules.evalNixvim { modules = [ module (lib.optionalAttrs (name != null) { test.name = name; }) { wrapRc = true; } - # TODO: Only do this when `args?pkgs` - # Consider deprecating the `pkgs` arg too... - { nixpkgs.pkgs = lib.mkDefault pkgs; } + systemMod ]; inherit extraSpecialArgs; }; diff --git a/templates/simple/flake.nix b/templates/simple/flake.nix index 8e80918683..ef20dfedac 100644 --- a/templates/simple/flake.nix +++ b/templates/simple/flake.nix @@ -18,12 +18,12 @@ ]; perSystem = - { pkgs, system, ... }: + { system, ... }: let nixvimLib = nixvim.lib.${system}; nixvim' = nixvim.legacyPackages.${system}; nixvimModule = { - inherit pkgs; + inherit system; # or alternatively, set `pkgs` module = import ./config; # import the module directly # You can use `extraSpecialArgs` to pass additional arguments to your module files extraSpecialArgs = { diff --git a/wrappers/standalone.nix b/wrappers/standalone.nix index 494074a5b1..a7eac7ce71 100644 --- a/wrappers/standalone.nix +++ b/wrappers/standalone.nix @@ -1,8 +1,13 @@ -default_pkgs: self: +{ + self, + lib, + defaultSystem, +}: { # TODO: Deprecate this arg in favour of using module options - pkgs ? default_pkgs, - lib ? pkgs.lib, + pkgs ? null, + # NOTE: `defaultSystem` is the only reason this function can't go in `.lib` + system ? defaultSystem, extraSpecialArgs ? { }, _nixvimTests ? false, module, @@ -12,23 +17,32 @@ let helpers = self.lib.nixvim.override { inherit _nixvimTests; }; inherit (helpers.modules) evalNixvim; + systemMod = + if pkgs == null then + { + _file = ./standalone.nix; + nixpkgs.hostPlatform = lib.mkDefault { inherit system; }; + } + else + { + _file = ./standalone.nix; + nixpkgs.pkgs = lib.mkDefault pkgs; + }; + mkNvim = mod: let nixvimConfig = evalNixvim { modules = [ mod - # TODO: only include this when `args?pkgs`: - { - _file = ./standalone.nix; - nixpkgs.pkgs = lib.mkDefault pkgs; - } + systemMod ]; inherit extraSpecialArgs; }; inherit (nixvimConfig.config) enableMan build; + inherit (nixvimConfig._module.args.pkgs) symlinkJoin; in - (pkgs.symlinkJoin { + (symlinkJoin { name = "nixvim"; paths = [ build.package