From 489c060d2ecaf04142d8127733b97182454322e1 Mon Sep 17 00:00:00 2001 From: mjones-vsat <54289180+mjones-vsat@users.noreply.github.com> Date: Fri, 10 Jan 2025 06:47:22 -0800 Subject: [PATCH] nixpkgs: support buildPlatform, hostPlatform, and overlays (#184) --- nix/lib.nix | 19 ++++++++++++++++++- nix/modules/default.nix | 14 ++++++++++++-- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/nix/lib.nix b/nix/lib.nix index fa142fd..4e7610f 100644 --- a/nix/lib.nix +++ b/nix/lib.nix @@ -20,6 +20,7 @@ let makeSystemConfig = { modules, + overlays ? [ ], extraSpecialArgs ? { }, }: let @@ -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; }; diff --git a/nix/modules/default.nix b/nix/modules/default.nix index 791334c..f375994 100644 --- a/nix/modules/default.nix +++ b/nix/modules/default.nix @@ -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.'';