From 5528b366981dab354f7ec7299c26b8c9303cdf06 Mon Sep 17 00:00:00 2001 From: Michael Hoang Date: Fri, 4 Feb 2022 21:32:40 +1100 Subject: [PATCH] eval-config: Support passing in `pkgs` This is useful for flake users as they will usually already have an instantiated Nixpkgs e.g. let pkgs = import nixpkgs { config.allowUnfree = true; overlays = [ ... ]; } in darwin.lib.darwinSystem { inherit pkgs; } This change makes `nix-darwin` match the behaviour of NixOS and `home-manager`. --- eval-config.nix | 13 +++++++++++-- flake.nix | 1 - modules/nix/nixpkgs.nix | 2 +- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/eval-config.nix b/eval-config.nix index 719d7640..af7849f2 100644 --- a/eval-config.nix +++ b/eval-config.nix @@ -1,6 +1,7 @@ { lib }: { system ? builtins.currentSystem or "x86_64-darwin" +, pkgs ? null , modules , inputs , baseModules ? import ./modules/module-list.nix @@ -21,7 +22,15 @@ let pkgsModule = { config, inputs, ... }: { _file = ./eval-config.nix; config = { - _module.args.pkgs = import inputs.nixpkgs config.nixpkgs; + assertions = [ { + # Ensure that nixpkgs.* options are not set when pkgs is set + assertion = pkgs == null || (config.nixpkgs.config == { } && config.nixpkgs.overlays == [ ]); + message = '' + `nixpkgs` options are disabled when `pkgs` is supplied through `darwinSystem`. + ''; + } ]; + + _module.args.pkgs = if pkgs != null then pkgs else import inputs.nixpkgs config.nixpkgs; # This permits the configuration to override the passed-in # system. @@ -35,7 +44,7 @@ let literalDocBook = super.literalDocBook or super.literalExample; }); - eval = libExtended.evalModules (builtins.removeAttrs args [ "inputs" "system" ] // { + eval = libExtended.evalModules (builtins.removeAttrs args [ "inputs" "pkgs" "system" ] // { modules = modules ++ [ argsModule pkgsModule ] ++ baseModules; specialArgs = { modulesPath = builtins.toString ./modules; } // specialArgs; }); diff --git a/flake.nix b/flake.nix index ce68ccf6..caad8757 100644 --- a/flake.nix +++ b/flake.nix @@ -29,6 +29,5 @@ system = "x86_64-darwin"; modules = [ self.darwinModules.simple ]; }).system; - }; } diff --git a/modules/nix/nixpkgs.nix b/modules/nix/nixpkgs.nix index b00a1821..9db3b6aa 100644 --- a/modules/nix/nixpkgs.nix +++ b/modules/nix/nixpkgs.nix @@ -109,7 +109,7 @@ in config = { - # _module.args.pkgs is defined in ../../default.nix + # _module.args.pkgs is defined in ../../eval-config.nix }; }