1
0
Fork 0
mirror of https://github.com/LnL7/nix-darwin.git synced 2024-12-14 11:57:34 +00:00
nix-darwin/eval-config.nix
Emily e25eeff158 nixpkgs: rebase module on latest NixOS
This is based on the current NixOS `nixpkgs` module, adjusted for the
nix-darwin context and without adding the options due for deprecation
in NixOS.

This gives us the ability to set the package set modularly through
`nixpkgs.pkgs` and builds up infrastructure for handling user-specified
Nixpkgs instantiations more robustly.

The cross-compilation options are currently not very useful due to
even Darwin->Darwin cross-compilation not being wholly functional
yet, but it looks feasible to build an `aarch64-darwin` system from
`x86_64-darwin` with some patching and it should be possible to make
cross-compilation more widely supported after the Darwin SDK situation
in Nixpkgs improves.

One casualty is the error for setting `nixpkgs.*` options when
overriding the package set. That could be ported over to this new
scheme, but it'd increase divergence with the NixOS module and reduce
cross-compatibility of configurations, so I lean towards adding it
upstream to NixOS if anything. (But if people want to keep it I can add
it back.)
2023-07-08 22:39:19 +01:00

50 lines
1.1 KiB
Nix

{ lib }:
let
nixpkgs-lib = lib;
in
{ system ? builtins.currentSystem or "x86_64-darwin"
, pkgs ? null
, lib ? nixpkgs-lib
, 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 = {
_module.args.pkgs = lib.mkIf (pkgs != null) (lib.mkForce pkgs);
nixpkgs.source = lib.mkDefault inputs.nixpkgs;
# This permits the configuration to override the passed-in
# system.
nixpkgs.system = lib.mkDefault system;
};
};
eval = lib.evalModules (builtins.removeAttrs args [ "lib" "inputs" "pkgs" "system" ] // {
modules = modules ++ [ argsModule pkgsModule ] ++ baseModules;
specialArgs = { modulesPath = builtins.toString ./modules; } // specialArgs;
});
in
{
inherit (eval._module.args) pkgs;
inherit (eval) options config;
system = eval.config.system.build.toplevel;
}