From b9d17d5e6c981911f33270e0eefdcb978559d990 Mon Sep 17 00:00:00 2001 From: Matt Sturgeon Date: Thu, 17 Oct 2024 19:01:34 +0100 Subject: [PATCH] modules/nixpkgs: restructure `nixpkgs.pkgs.isDefined` assertion We can throw inline to ensure our error is displayed before any attempt to use the (non-existent) `pkgs` arg results in a less helpful error. --- modules/top-level/nixpkgs.nix | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/modules/top-level/nixpkgs.nix b/modules/top-level/nixpkgs.nix index 3116ec760..b2fc2984b 100644 --- a/modules/top-level/nixpkgs.nix +++ b/modules/top-level/nixpkgs.nix @@ -57,29 +57,28 @@ in }; }; - config = { - # For now we only set this when `nixpkgs.pkgs` is defined - # TODO: construct a default pkgs instance from pkgsPath and cfg options - # https://github.com/nix-community/nixvim/issues/1784 - _module.args = lib.optionalAttrs opt.pkgs.isDefined { + config = + let + # TODO: construct a default pkgs instance from pkgsPath and cfg options + # https://github.com/nix-community/nixvim/issues/1784 + + finalPkgs = + if opt.pkgs.isDefined then + cfg.pkgs + else + # TODO: Remove once pkgs can be constructed internally + throw '' + nixvim: `nixpkgs.pkgs` is not defined. In the future, this option will be optional. + Currently a pkgs instance must be evaluated externally and assigned to `nixpkgs.pkgs` option. + ''; + in + { # We explicitly set the default override priority, so that we do not need # to evaluate finalPkgs in case an override is placed on `_module.args.pkgs`. # After all, to determine a definition priority, we need to evaluate `._type`, # which is somewhat costly for Nixpkgs. With an explicit priority, we only # evaluate the wrapper to find out that the priority is lower, and then we # don't need to evaluate `finalPkgs`. - pkgs = lib.mkOverride lib.modules.defaultOverridePriority cfg.pkgs.__splicedPackages; + _module.args.pkgs = lib.mkOverride lib.modules.defaultOverridePriority finalPkgs.__splicedPackages; }; - - assertions = [ - { - # TODO: Remove or rephrase once pkgs can be constructed internally - assertion = config._module.args ? pkgs; - message = '' - `nixpkgs.pkgs` is not defined. In the future, this option will be optional. - Currently a pkgs instance must be evaluated externally and assigned to `nixpkgs.pkgs` option. - ''; - } - ]; - }; }