From bac24e6cebf6f3d9d3f03e167a0064e164c85a22 Mon Sep 17 00:00:00 2001 From: Colin Date: Fri, 9 May 2025 06:39:46 +0000 Subject: [PATCH] nixpkgs-bootstrap: hoist config to callArgs level, to simplify the call site --- impure.nix | 9 ++- pkgs/by-name/nixpkgs-bootstrap/mkNixpkgs.nix | 71 +++++++++----------- 2 files changed, 35 insertions(+), 45 deletions(-) diff --git a/impure.nix b/impure.nix index 57eae7d33..dc49b7f2b 100644 --- a/impure.nix +++ b/impure.nix @@ -8,11 +8,10 @@ localSystem ? builtins.currentSystem, }: let - mkNixpkgs = import ./pkgs/by-name/nixpkgs-bootstrap/mkNixpkgs.nix {}; - mkPkgs = branch: config: ( - import ./pkgs/by-name/nixpkgs-bootstrap/${branch}.nix { - mkNixpkgs = args: mkNixpkgs (config // args); - } + mkPkgs = branch: config: let + mkNixpkgs = import ./pkgs/by-name/nixpkgs-bootstrap/mkNixpkgs.nix config; + in ( + import ./pkgs/by-name/nixpkgs-bootstrap/${branch}.nix { inherit mkNixpkgs; } ).pkgs.extend (import ./overlays/all.nix); pkgs = mkPkgs "master" { inherit localSystem; }; inherit (pkgs) lib; diff --git a/pkgs/by-name/nixpkgs-bootstrap/mkNixpkgs.nix b/pkgs/by-name/nixpkgs-bootstrap/mkNixpkgs.nix index 40bbf7aa8..8d42a16f2 100644 --- a/pkgs/by-name/nixpkgs-bootstrap/mkNixpkgs.nix +++ b/pkgs/by-name/nixpkgs-bootstrap/mkNixpkgs.nix @@ -42,6 +42,9 @@ fetchzip ? null, stdenv ? null, unstableGitUpdater ? null, +#VVV config + localSystem ? if stdenv != null then stdenv.buildPlatform.system else builtins.currentSystem, #< not available in pure mode + system ? if stdenv != null then stdenv.hostPlatform.system else localSystem, }: let # nixpkgs' update-source-version (updateScript) calculates the new hash for a `src` by specifying this hardcoded bogus hash and then attempting to realize it. @@ -62,9 +65,6 @@ let rev ? "", sha256 ? "", version ? "", - #VVV config - localSystem ? if stdenv != null then stdenv.buildPlatform.system else builtins.currentSystem, #< not available in pure mode - system ? if stdenv != null then stdenv.hostPlatform.system else localSystem, }@args: let url = "https://github.com/NixOS/nixpkgs/archive/${rev}.tar.gz"; pname = "nixpkgs-${branch}"; @@ -126,47 +126,38 @@ let } else {}); nixpkgs = import patchedSrc nixpkgsArgs; in - if rev == "" && sha256 == "" && version == "" then - # allow `impure.nix` to invoke this with only `branch`, and we figure out the details for it. - # TODO: remove this code path. - import ./${branch}.nix { - mkNixpkgs = args': mkNixpkgs ({ - inherit localSystem system; - } // args'); - } - else - patchedSrc.overrideAttrs (base: { - # attributes needed for update scripts. - # TODO: should be possible to pass these straight through `applyPatches` instead of using `overrideAttrs`. - inherit version; - pname = "nixpkgs"; - passthru = (base.passthru or {}) // { - pkgs = nixpkgs; + patchedSrc.overrideAttrs (base: { + # attributes needed for update scripts. + # TODO: should be possible to pass these straight through `applyPatches` instead of using `overrideAttrs`. + inherit version; + pname = "nixpkgs"; + passthru = (base.passthru or {}) // { + pkgs = nixpkgs; - src = { - # required by unstableGitUpdater - gitRepoUrl = "https://github.com/NixOS/nixpkgs.git"; - inherit rev; - } // src'; + src = { + # required by unstableGitUpdater + gitRepoUrl = "https://github.com/NixOS/nixpkgs.git"; + inherit rev; + } // src'; - # required so that unstableGitUpdater can know in which file the `rev` variable can be updated in. - meta.position = let - position = builtins.unsafeGetAttrPos "rev" args; - in - "${position.file}:${toString position.line}"; + # required so that unstableGitUpdater can know in which file the `rev` variable can be updated in. + meta.position = let + position = builtins.unsafeGetAttrPos "rev" args; + in + "${position.file}:${toString position.line}"; - # while we could *technically* use `nixpkgs.<...>` updateScript - # that can force maaany rebuilds on staging/staging-next. - # updateScript = nix-update-script { - # extraArgs = [ "--version=branch=${branch}" ]; - # }; - updateScript = unstableGitUpdater { - # else the update script tries to walk 10000's of commits to find a tag - hardcodeZeroVersion = true; - inherit branch; - }; + # while we could *technically* use `nixpkgs.<...>` updateScript + # that can force maaany rebuilds on staging/staging-next. + # updateScript = nix-update-script { + # extraArgs = [ "--version=branch=${branch}" ]; + # }; + updateScript = unstableGitUpdater { + # else the update script tries to walk 10000's of commits to find a tag + hardcodeZeroVersion = true; + inherit branch; }; - }) + }; + }) ; in mkNixpkgs