From 8c6f9ed8c45576a3dc26e32f341b2ff8aebb0824 Mon Sep 17 00:00:00 2001 From: Matt Sturgeon Date: Mon, 23 Dec 2024 12:42:58 +0000 Subject: [PATCH] lib/modules: allow specifying `system` as an `evalNixvim` arg --- flake-modules/legacy-packages.nix | 10 ++-------- lib/modules.nix | 8 ++++++++ modules/top-level/nixpkgs.nix | 3 ++- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/flake-modules/legacy-packages.nix b/flake-modules/legacy-packages.nix index 3e8555c5..323decc7 100644 --- a/flake-modules/legacy-packages.nix +++ b/flake-modules/legacy-packages.nix @@ -2,9 +2,8 @@ { perSystem = { - pkgs, - lib, makeNixvimWithModule, + system, ... }: { @@ -13,12 +12,7 @@ makeNixvim = module: makeNixvimWithModule { inherit module; }; nixvimConfiguration = helpers.modules.evalNixvim { - modules = [ - { - _file = ./legacy-packages.nix; - nixpkgs.pkgs = lib.mkDefault pkgs; - } - ]; + inherit system; }; }; }; diff --git a/lib/modules.nix b/lib/modules.nix index d9c39f12..cbffe1d4 100644 --- a/lib/modules.nix +++ b/lib/modules.nix @@ -21,12 +21,16 @@ in { modules ? [ ], extraSpecialArgs ? { }, + system ? null, # Can also be defined using the `nixpkgs.hostPlatform` option }: # Ensure a suitable `lib` is used 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. 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''; + 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 { modules = modules ++ [ ../modules/top-level @@ -34,6 +38,10 @@ in _file = ""; flake = lib.mkOptionDefault flake; } + (lib.optionalAttrs (system != null) { + _file = "evalNixvim"; + nixpkgs.hostPlatform = lib.mkOptionDefault { inherit system; }; + }) ]; specialArgs = { modulesPath = ../modules; diff --git a/modules/top-level/nixpkgs.nix b/modules/top-level/nixpkgs.nix index 5aec8816..cbe29fe1 100644 --- a/modules/top-level/nixpkgs.nix +++ b/modules/top-level/nixpkgs.nix @@ -164,7 +164,8 @@ in apply = lib.systems.elaborate; defaultText = lib.literalMD '' - 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 = '' Specifies the platform where the Nixvim configuration will run.