lib/modules: allow specifying system as an evalNixvim arg

This commit is contained in:
Matt Sturgeon 2024-12-23 12:42:58 +00:00
parent 7790746d38
commit 8c6f9ed8c4
No known key found for this signature in database
GPG key ID: 4F91844CED1A8299
3 changed files with 12 additions and 9 deletions

View file

@ -2,9 +2,8 @@
{ {
perSystem = perSystem =
{ {
pkgs,
lib,
makeNixvimWithModule, makeNixvimWithModule,
system,
... ...
}: }:
{ {
@ -13,12 +12,7 @@
makeNixvim = module: makeNixvimWithModule { inherit module; }; makeNixvim = module: makeNixvimWithModule { inherit module; };
nixvimConfiguration = helpers.modules.evalNixvim { nixvimConfiguration = helpers.modules.evalNixvim {
modules = [ inherit system;
{
_file = ./legacy-packages.nix;
nixpkgs.pkgs = lib.mkDefault pkgs;
}
];
}; };
}; };
}; };

View file

@ -21,12 +21,16 @@ in
{ {
modules ? [ ], modules ? [ ],
extraSpecialArgs ? { }, extraSpecialArgs ? { },
system ? null, # Can also be defined using the `nixpkgs.hostPlatform` option
}: }:
# Ensure a suitable `lib` is used # Ensure a suitable `lib` is used
assert lib.assertMsg (extraSpecialArgs ? lib -> extraSpecialArgs.lib ? nixvim) '' assert lib.assertMsg (extraSpecialArgs ? lib -> extraSpecialArgs.lib ? nixvim) ''
Nixvim requires a lib that includes some custom extensions, however the `lib` from `specialArgs` does not have a `nixvim` attr. Nixvim requires a lib that includes some custom extensions, however the `lib` from `specialArgs` does not have a `nixvim` attr.
Remove `lib` from nixvim's `specialArgs` or ensure you apply nixvim's extensions to your `lib`. Remove `lib` from nixvim's `specialArgs` or ensure you apply nixvim's extensions to your `lib`.
See https://nix-community.github.io/nixvim/user-guide/helpers.html#using-a-custom-lib-with-nixvim''; See https://nix-community.github.io/nixvim/user-guide/helpers.html#using-a-custom-lib-with-nixvim'';
assert lib.assertMsg (system != null -> lib.isString system) ''
When `system` is supplied to `evalNixvim`, it must be a string.
To define a more complex system, please use nixvim's `nixpkgs.hostPlatform` option.'';
lib.evalModules { lib.evalModules {
modules = modules ++ [ modules = modules ++ [
../modules/top-level ../modules/top-level
@ -34,6 +38,10 @@ in
_file = "<nixvim-flake>"; _file = "<nixvim-flake>";
flake = lib.mkOptionDefault flake; flake = lib.mkOptionDefault flake;
} }
(lib.optionalAttrs (system != null) {
_file = "evalNixvim";
nixpkgs.hostPlatform = lib.mkOptionDefault { inherit system; };
})
]; ];
specialArgs = { specialArgs = {
modulesPath = ../modules; modulesPath = ../modules;

View file

@ -164,7 +164,8 @@ in
apply = lib.systems.elaborate; apply = lib.systems.elaborate;
defaultText = lib.literalMD '' defaultText = lib.literalMD ''
- Inherited from the "host" configuration's `pkgs` - Inherited from the "host" configuration's `pkgs`
- Must be specified manually when building a standalone nixvim - Or `evalNixvim`'s `system` argument
- Otherwise, must be specified manually
''; '';
description = '' description = ''
Specifies the platform where the Nixvim configuration will run. Specifies the platform where the Nixvim configuration will run.