Skip to content

Commit

Permalink
nixpkgs: support buildPlatform, hostPlatform, and overlays (#184)
Browse files Browse the repository at this point in the history
  • Loading branch information
mjones-vsat authored Jan 10, 2025
1 parent c9e35e9 commit 489c060
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
19 changes: 18 additions & 1 deletion nix/lib.nix
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ let
makeSystemConfig =
{
modules,
overlays ? [ ],
extraSpecialArgs ? { },
}:
let
Expand All @@ -34,7 +35,23 @@ let
{
_file = "${self.printAttrPos (builtins.unsafeGetAttrPos "a" { a = null; })}: inline module";
_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" {
inherit lib config pkgs;
};
Expand Down
14 changes: 12 additions & 2 deletions nix/modules/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,23 @@
in
{
nixpkgs = {
# TODO: switch to lib.systems.parsedPlatform
hostPlatform = lib.mkOption {
buildPlatform = lib.mkOption {
type = types.str;
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.";
};

overlays = lib.mkOption {
type = with types; listOf anything;
default = [];
};

config = lib.mkOption {
type = types.attrs;
description = ''Configuration used to instantiate nixpkgs.'';
Expand Down

0 comments on commit 489c060

Please sign in to comment.