nixpkgs: support buildPlatform, hostPlatform, and overlays (#184)

This commit is contained in:
mjones-vsat 2025-01-10 06:47:22 -08:00 committed by GitHub
parent c9e35e9b7d
commit 489c060d2e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 30 additions and 3 deletions

View file

@ -20,6 +20,7 @@ let
makeSystemConfig = makeSystemConfig =
{ {
modules, modules,
overlays ? [ ],
extraSpecialArgs ? { }, extraSpecialArgs ? { },
}: }:
let let
@ -34,7 +35,23 @@ let
{ {
_file = "${self.printAttrPos (builtins.unsafeGetAttrPos "a" { a = null; })}: inline module"; _file = "${self.printAttrPos (builtins.unsafeGetAttrPos "a" { a = null; })}: inline module";
_module.args = { _module.args = {
pkgs = import nixpkgs { system = config.nixpkgs.hostPlatform; inherit (config.nixpkgs) config; }; pkgs = let
cfg = config.nixpkgs;
systemArgs =
if cfg.buildPlatform != cfg.hostPlatform then
{
localSystem = cfg.buildPlatform;
crossSystem = cfg.hostPlatform;
}
else
{
system = cfg.hostPlatform;
};
in
import nixpkgs ({
overlays = overlays ++ cfg.overlays;
inherit (config.nixpkgs) config;
} // systemArgs);
utils = import "${nixos}/lib/utils.nix" { utils = import "${nixos}/lib/utils.nix" {
inherit lib config pkgs; inherit lib config pkgs;
}; };

View file

@ -20,13 +20,23 @@
in in
{ {
nixpkgs = { nixpkgs = {
# TODO: switch to lib.systems.parsedPlatform buildPlatform = lib.mkOption {
hostPlatform = lib.mkOption {
type = types.str; type = types.str;
example = "x86_64-linux"; example = "x86_64-linux";
default = config.nixpkgs.hostPlatform;
};
hostPlatform = lib.mkOption {
type = with types; either str attrs;
example = "x86_64-linux";
default = throw "the option nixpkgs.hostPlatform needs to be set."; default = throw "the option nixpkgs.hostPlatform needs to be set.";
}; };
overlays = lib.mkOption {
type = with types; listOf anything;
default = [];
};
config = lib.mkOption { config = lib.mkOption {
type = types.attrs; type = types.attrs;
description = ''Configuration used to instantiate nixpkgs.''; description = ''Configuration used to instantiate nixpkgs.'';