From d21ba5a4871f02c50efc2de0ae61b749a6318a10 Mon Sep 17 00:00:00 2001 From: Nick Novitski Date: Wed, 12 Jun 2024 18:41:49 -0700 Subject: [PATCH] linux-builder: make compatible with cross-arch builder package Before this commit, aarch64 users building the following configuration would end up with an aarch64-linux builder, while after it, they get the x86_64-linux builder they expect: ```nix nix.linux-builder = { enable = true; package = pkgs.darwin.linux-builder-x86_64; }; ``` Before, in order to get an x86_64-linux builder, they would have needed to use this configuration instead: ```nix nix.linux-builder = { enable = true; config.nixpkgs.hostPlatform = "x86_64-linux"; systems = ["x86_64-linux"]; }; ``` The reason for this is that the linux-builder module calls `override` on the package option, and the `linux-builder-x86_64` package is also defined using override: ```nix linux-builder-x86_64 = linux-builder.override { modules = [ { nixpkgs.hostPlatform = "x86_64-linux"; } ]; }; ``` The module was effectively discarding the `nixpkgs.hostPlatform` option. Example issue: https://github.com/NixOS/nixpkgs/issues/313784 --- modules/nix/linux-builder.nix | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/modules/nix/linux-builder.nix b/modules/nix/linux-builder.nix index 176d69eb..b0c3cd6a 100644 --- a/modules/nix/linux-builder.nix +++ b/modules/nix/linux-builder.nix @@ -7,9 +7,11 @@ let cfg = config.nix.linux-builder; - builderWithOverrides = cfg.package.override { - modules = [ cfg.config ]; - }; + builderWithOverrides = cfg.package.override (previousArguments: { + # the linux-builder packages require a list `modules` argument, so it's + # always non-null. + modules = previousArguments.modules ++ [ cfg.config ]; + }); # create-builder uses TMPDIR to share files with the builder, notably certs. # macOS will clean up files in /tmp automatically that haven't been accessed in 3+ days. @@ -133,8 +135,10 @@ in systems = mkOption { type = types.listOf types.str; - default = [ "${stdenv.hostPlatform.uname.processor}-linux" ]; - defaultText = literalExpression ''[ "''${stdenv.hostPlatform.uname.processor}-linux" ]''; + default = [ builderWithOverrides.nixosConfig.nixpkgs.hostPlatform.system ]; + defaultText = '' + The `nixpkgs.hostPlatform.system` of the build machine's final NixOS configuration. + ''; example = literalExpression '' [ "x86_64-linux"