From 71a46a9608405d2ce69aa59b2db5b78d535c246d Mon Sep 17 00:00:00 2001 From: Matt Sturgeon Date: Sat, 19 Oct 2024 22:59:48 +0100 Subject: [PATCH 1/3] modules/nixpkgs: make `source` option public --- modules/top-level/nixpkgs.nix | 8 -------- wrappers/_shared.nix | 5 +++-- 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/modules/top-level/nixpkgs.nix b/modules/top-level/nixpkgs.nix index 96d8925281..ed64556a6d 100644 --- a/modules/top-level/nixpkgs.nix +++ b/modules/top-level/nixpkgs.nix @@ -136,9 +136,6 @@ in Ignored when `nixpkgs.pkgs` is set. ''; - - # FIXME: This is a stub option for now - internal = true; }; }; @@ -165,10 +162,5 @@ in # evaluate the wrapper to find out that the priority is lower, and then we # don't need to evaluate `finalPkgs`. _module.args.pkgs = lib.mkOverride lib.modules.defaultOverridePriority finalPkgs.__splicedPackages; - - # FIXME: This is a stub option for now - warnings = lib.optional ( - opt.source.isDefined && opt.source.highestPrio < (lib.mkOptionDefault null).priority - ) "Defining the option `nixpkgs.source` currently has no effect"; }; } diff --git a/wrappers/_shared.nix b/wrappers/_shared.nix index 9d93f9ea48..93676729b3 100644 --- a/wrappers/_shared.nix +++ b/wrappers/_shared.nix @@ -32,10 +32,11 @@ let evalArgs // { modules = evalArgs.modules or [ ] ++ [ - # Use global packages by default in nixvim's submodule - # TODO: `useGlobalPackages` option and/or deprecate using host packages? { _file = ./_shared.nix; + + # Use global packages by default in nixvim's submodule + # TODO: `useGlobalPackages` option and/or deprecate using host packages? nixpkgs.pkgs = lib.mkDefault pkgs; } ]; From 99f66f1e9ac676b951694615f92ae7a8ba36b983 Mon Sep 17 00:00:00 2001 From: Matt Sturgeon Date: Sat, 19 Oct 2024 23:45:28 +0100 Subject: [PATCH 2/3] modules/nixpkgs: init platform options --- modules/top-level/nixpkgs.nix | 46 +++++++++++++++++++++++++++++++++++ wrappers/_shared.nix | 14 ++++++++--- 2 files changed, 57 insertions(+), 3 deletions(-) diff --git a/modules/top-level/nixpkgs.nix b/modules/top-level/nixpkgs.nix index ed64556a6d..eff0088000 100644 --- a/modules/top-level/nixpkgs.nix +++ b/modules/top-level/nixpkgs.nix @@ -137,6 +137,52 @@ in Ignored when `nixpkgs.pkgs` is set. ''; }; + + hostPlatform = lib.mkOption { + type = with lib.types; either str attrs; + example = { + system = "aarch64-linux"; + }; + apply = lib.systems.elaborate; + defaultText = lib.literalMD '' + Inherited from the "host" configuration's `pkgs`. + Must be specified manually when building a standalone nixvim. + ''; + description = '' + Specifies the platform where the Nixvim configuration will run. + + To cross-compile, also set `nixpkgs.buildPlatform`. + + Ignored when `nixpkgs.pkgs` is set. + ''; + }; + + buildPlatform = lib.mkOption { + type = with lib.types; either str attrs; + default = cfg.hostPlatform; + example = { + system = "x86_64-linux"; + }; + apply = + value: + let + elaborated = lib.systems.elaborate value; + in + # If equivalent to `hostPlatform`, make it actually identical so that `==` can be used + # See https://github.com/NixOS/nixpkgs/issues/278001 + if lib.systems.equals elaborated cfg.hostPlatform then cfg.hostPlatform else elaborated; + defaultText = lib.literalMD '' + Inherited from the "host" configuration's `pkgs`. + Or `config.nixpkgs.hostPlatform` when building a standalone nixvim. + ''; + description = '' + Specifies the platform on which Nixvim should be built. + By default, Nixvim is built on the system where it runs, but you can change where it's built. + Setting this option will cause Nixvim to be cross-compiled. + + Ignored when `nixpkgs.pkgs` is set. + ''; + }; }; config = diff --git a/wrappers/_shared.nix b/wrappers/_shared.nix index 93676729b3..588b809382 100644 --- a/wrappers/_shared.nix +++ b/wrappers/_shared.nix @@ -35,9 +35,17 @@ let { _file = ./_shared.nix; - # Use global packages by default in nixvim's submodule - # TODO: `useGlobalPackages` option and/or deprecate using host packages? - nixpkgs.pkgs = lib.mkDefault pkgs; + nixpkgs = { + # Use global packages by default in nixvim's submodule + # TODO: `useGlobalPackages` option and/or deprecate using host packages? + pkgs = lib.mkDefault pkgs; + + # Inherit platform spec + # FIXME: buildPlatform can't use option-default because it already has a default + # (it defaults to hostPlatform)... + hostPlatform = lib.mkOptionDefault pkgs.stdenv.hostPlatform; + buildPlatform = lib.mkDefault pkgs.stdenv.buildPlatform; + }; } ]; } From 87176c7e169328c75385f09d9e03eab062e3b94b Mon Sep 17 00:00:00 2001 From: Matt Sturgeon Date: Sun, 20 Oct 2024 00:11:36 +0100 Subject: [PATCH 3/3] modules/nixpkgs: init `useGlobalPackages` option --- wrappers/_shared.nix | 50 +++++++++++++++++++++++++++++++------------- 1 file changed, 35 insertions(+), 15 deletions(-) diff --git a/wrappers/_shared.nix b/wrappers/_shared.nix index 588b809382..200f71526e 100644 --- a/wrappers/_shared.nix +++ b/wrappers/_shared.nix @@ -28,25 +28,45 @@ let setAttrByPath ; cfg = config.programs.nixvim; + + # TODO: Find a way to document the options declared here + nixpkgsModule = + { config, ... }: + { + _file = ./_shared.nix; + + options.nixpkgs = { + useGlobalPackages = lib.mkOption { + type = lib.types.bool; + default = true; # TODO: Added 2024-10-20; switch to false one release after adding a deprecation warning + description = '' + Whether Nixvim should use the host configuration's `pkgs` instance. + + The host configuration is usually home-manager, nixos, or nix-darwin. + + When false, an instance of nixpkgs will be constructed by nixvim. + ''; + }; + }; + + config = { + nixpkgs = { + # Use global packages by default in nixvim's submodule + pkgs = lib.mkIf config.nixpkgs.useGlobalPackages (lib.mkForce pkgs); + + # Inherit platform spec + # FIXME: buildPlatform can't use option-default because it already has a default + # (it defaults to hostPlatform)... + hostPlatform = lib.mkOptionDefault pkgs.stdenv.hostPlatform; + buildPlatform = lib.mkDefault pkgs.stdenv.buildPlatform; + }; + }; + }; nixvimConfiguration = config.lib.nixvim.modules.evalNixvim ( evalArgs // { modules = evalArgs.modules or [ ] ++ [ - { - _file = ./_shared.nix; - - nixpkgs = { - # Use global packages by default in nixvim's submodule - # TODO: `useGlobalPackages` option and/or deprecate using host packages? - pkgs = lib.mkDefault pkgs; - - # Inherit platform spec - # FIXME: buildPlatform can't use option-default because it already has a default - # (it defaults to hostPlatform)... - hostPlatform = lib.mkOptionDefault pkgs.stdenv.hostPlatform; - buildPlatform = lib.mkDefault pkgs.stdenv.buildPlatform; - }; - } + nixpkgsModule ]; } );