1
1
mirror of https://github.com/LnL7/nix-darwin.git synced 2024-08-15 23:50:31 +03:00
nix-darwin/eval-config.nix
Michael Hoang 5528b36698 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`.
2022-02-04 21:32:40 +11:00

63 lines
1.8 KiB
Nix

{ lib }:
{ system ? builtins.currentSystem or "x86_64-darwin"
, pkgs ? null
, modules
, inputs
, baseModules ? import ./modules/module-list.nix
, specialArgs ? { }
, check ? true
}@args:
let
argsModule = {
_file = ./eval-config.nix;
config = {
_module.args = {
inherit baseModules inputs modules;
};
};
};
pkgsModule = { config, inputs, ... }: {
_file = ./eval-config.nix;
config = {
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.
nixpkgs.system = lib.mkDefault system;
};
};
libExtended = lib.extend (self: super: {
# Added in nixpkgs #136909, adds forward compatibility until 22.03 is deprecated.
literalExpression = super.literalExpression or super.literalExample;
literalDocBook = super.literalDocBook or super.literalExample;
});
eval = libExtended.evalModules (builtins.removeAttrs args [ "inputs" "pkgs" "system" ] // {
modules = modules ++ [ argsModule pkgsModule ] ++ baseModules;
specialArgs = { modulesPath = builtins.toString ./modules; } // specialArgs;
});
# Was moved in nixpkgs #82751, so both need to be handled here until 20.03 is deprecated.
# https://github.com/NixOS/nixpkgs/commits/dcdd232939232d04c1132b4cc242dd3dac44be8c
_module = eval._module or eval.config._module;
in
{
inherit (_module.args) pkgs;
inherit (eval) options config;
system = eval.config.system.build.toplevel;
}