nixpkgs-bootstrap: BETTER updateScript fix

This commit is contained in:
2024-10-03 16:02:41 +00:00
parent 69c29f5089
commit 73b0a9fd88
9 changed files with 154 additions and 74 deletions

View File

@@ -7,8 +7,8 @@
{ }:
let
mkPkgs = branch: args: (
import ./pkgs/by-name/nixpkgs-bootstrap/package.nix args
)."${branch}".extend (import ./overlays/all.nix);
(import ./pkgs/by-name/nixpkgs-bootstrap/${branch}.nix {}).override args
).extend (import ./overlays/all.nix);
pkgs = mkPkgs "master" {};
inherit (pkgs) lib;

View File

@@ -1,8 +1,8 @@
{
nix-update-script,
localSystem,
system,
src,
version,
passthru,
}: let
commonNixpkgsArgs = {
@@ -44,11 +44,7 @@ in
# AND `nix-build -A nixpkgs`
patchedSrc.overrideAttrs (base: {
# attributes needed for update scripts
inherit version;
pname = "nixpkgs";
version = "24.05-unstable-2024-10-02";
passthru = (base.passthru or {}) // nixpkgs // {
updateScript = nix-update-script {
extraArgs = [ "--version" "branch" ];
};
} // passthru;
passthru = (base.passthru or {}) // nixpkgs // passthru;
})

View File

@@ -0,0 +1,9 @@
{
mkNixpkgs ? import ./mkNixpkgs.nix {}
}:
mkNixpkgs {
rev = "aa81bad818730f6f6c4ed638f8651ec4200138a4";
sha256 = "sha256-4zVifcF6QlcRLRXXnodGTukXV6+vFJMPl9om1w9RRDU=";
version = "24.05-unstable-2024-10-02";
branch = "master";
}

View File

@@ -0,0 +1,115 @@
# XXX: this is in the bootstrap path;
# this means it has to be evaluatable using only builtins,
# though i'm free to include optional functionality (e.g. update scripts) so long as i gate it behind availability checks.
#
# branch workflow:
# - daily:
# - nixos-unstable cut from master after enough packages have been built in caches.
# - every 6 hours:
# - master auto-merged into staging and staging-next
# - staging-next auto-merged into staging.
# - manually, approximately once per month:
# - staging-next is cut from staging.
# - staging-next merged into master.
#
# which branch to source from?
# - nixos-unstable: for everyday development; it provides good caching
# - master: temporarily if i'm otherwise cherry-picking lots of already-applied patches
# - staging-next: if testing stuff that's been PR'd into staging, i.e. base library updates.
# - staging: maybe if no staging-next -> master PR has been cut yet?
{
#VVV these may or may not be available when called VVV
fetchzip ? builtins.fetchTarball,
stdenv ? null,
unstableGitUpdater ? null,
}:
let
mkNixpkgs = {
rev ? null,
sha256 ? null,
branch ? null,
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
src' = fetchzip ({
url = "https://github.com/NixOS/nixpkgs/archive/${rev}.tar.gz";
# nixpkgs' update-source-version (updateScript) finds the new hash by specifying this hardcoded bogus hash
# and then checking the error messages.
# but that doesn't work for builtins; instead we leave the builtin hash unspec'd,
# and let eval progress to where pkgs.fetchzip exists and errors.
} // (if sha256 != "sha256-AzH1rZFqEH8sovZZfJykvsEmCedEZWigQFHWHl6/PdE=" then { inherit sha256; } else {}));
commonNixpkgsArgs = {
inherit localSystem;
# reset impurities
config = {};
overlays = [];
};
unpatchedNixpkgs = import src' commonNixpkgsArgs;
patchedSrc = unpatchedNixpkgs.applyPatches {
src = src';
name = "nixpkgs-patched-uninsane";
inherit version;
patches = unpatchedNixpkgs.callPackage ./patches.nix { };
# skip applied patches
prePatch = ''
realpatch=$(command -v patch)
patch() {
OUT=$($realpatch "$@") || echo "$OUT" | grep "Skipping patch" -q
}
'';
};
nixpkgsArgs = commonNixpkgsArgs // {
config = {
allowUnfree = true; # NIXPKGS_ALLOW_UNFREE=1
allowBroken = true; # NIXPKGS_ALLOW_BROKEN=1
};
} // (if (system != localSystem) then {
# XXX(2023/12/11): cache.nixos.org uses `system = ...` instead of `hostPlatform.system`, and that choice impacts the closure of every package.
# so avoid specifying hostPlatform.system on non-cross builds, so i can use upstream caches.
crossSystem = system;
} else {});
nixpkgs = import "${patchedSrc}" nixpkgsArgs;
in
# N.B.: this is crafted to allow `nixpkgs.FOO` from other nix code
# AND `nix-build -A nixpkgs`
patchedSrc.overrideAttrs (base: {
# attributes needed for update scripts
inherit version;
pname = "nixpkgs";
passthru = (base.passthru or {}) // nixpkgs // {
# override is used to configure hostPlatform higher up.
override = overrideArgs: mkNixpkgs (args // overrideArgs);
# N.B.: src has to be specified in passthru, not the outer scope, so as to take precedence over the nixpkgs `src` package
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}";
# 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

View File

@@ -1,58 +0,0 @@
# XXX: this is in the bootstrap path;
# this means it has to be evaluatable using only builtins,
# though i'm free to include optional functionality (e.g. update scripts) so long as i gate it behind availability checks.
#
# branch workflow:
# - daily:
# - nixos-unstable cut from master after enough packages have been built in caches.
# - every 6 hours:
# - master auto-merged into staging and staging-next
# - staging-next auto-merged into staging.
# - manually, approximately once per month:
# - staging-next is cut from staging.
# - staging-next merged into master.
#
# which branch to source from?
# - nixos-unstable: for everyday development; it provides good caching
# - master: temporarily if i'm otherwise cherry-picking lots of already-applied patches
# - staging-next: if testing stuff that's been PR'd into staging, i.e. base library updates.
# - staging: maybe if no staging-next -> master PR has been cut yet?
{
#VVV these may or may not be available when called VVV
fetchzip ? builtins.fetchTarball,
nix-update-script ? null,
stdenv ? 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
lock = {
master.rev = "dd89098d752fcd8af9c4e59a66b97af8e8fd185b";
master.sha256 = "sha256-L/g6FGwBe9yd7IXE4271e9ptU0Cb22ycA2I1Ymn+HTk=";
staging.rev = "6d24a9cf8384b08625e721c5a288b15a09abf7c8";
staging.sha256 = "sha256-rhQpVka7HgYHJZ5ejr0EnYm07aZ0Y+OIByzchDEZkPs=";
staging-next.rev = "01dfa6bca5da1b7acc5b0419fdc625c6d5053bb5";
staging-next.sha256 = "sha256-NFLhqDfWf49M4t6/YvK7XMqpLhTU1t1PcRUrGhODTM0=";
};
mkVariant = variant: let
lock' = lock."${variant}";
in import ./common.nix rec {
inherit localSystem nix-update-script system;
inherit (lock') rev;
src = fetchzip {
url = "https://github.com/NixOS/nixpkgs/archive/${lock'.rev}.tar.gz";
inherit (lock') sha256;
};
passthru = {
src = src // { inherit rev; };
};
};
in {
recurseForDerivations = true;
master = mkVariant "master";
staging = mkVariant "staging";
staging-next = mkVariant "staging-next";
}

View File

@@ -0,0 +1,9 @@
{
mkNixpkgs ? import ./mkNixpkgs.nix {}
}:
mkNixpkgs {
rev = "01dfa6bca5da1b7acc5b0419fdc625c6d5053bb5";
sha256 = "sha256-NFLhqDfWf49M4t6/YvK7XMqpLhTU1t1PcRUrGhODTM0=";
version = "24.05-unstable-2024-10-02";
branch = "staging-next";
}

View File

@@ -0,0 +1,9 @@
{
mkNixpkgs ? import ./mkNixpkgs.nix {}
}:
mkNixpkgs {
rev = "6d24a9cf8384b08625e721c5a288b15a09abf7c8";
sha256 = "sha256-rhQpVka7HgYHJZ5ejr0EnYm07aZ0Y+OIByzchDEZkPs=";
version = "24.05-unstable-2024-10-02";
branch = "staging";
}

View File

@@ -5,7 +5,7 @@
# using the correct invocation is critical if any packages mentioned here are
# additionally patched elsewhere
#
{ pkgs ? (import ./by-name/nixpkgs-bootstrap { }).master, final ? null }:
{ pkgs, final ? null }:
let
lib = pkgs.lib;
unpatched = pkgs;

View File

@@ -46,12 +46,12 @@ getPkgs() {
attrPrefix=sane
fi
# nix-env doesn't seem to build anything when evaluating queries,
# but since i use Import From Derivation along paths which i also want to query,
# then i need to ensure those derivations are available for import.
debug "creating requisite .drv store paths"
nix-instantiate -A nix "$NIX_FILES_TOP"
nix-instantiate -A nixpkgs "$NIX_FILES_TOP"
# # nix-env doesn't seem to build anything when evaluating queries,
# # but since i use Import From Derivation along paths which i also want to query,
# # then i need to ensure those derivations are available for import.
# debug "creating requisite .drv store paths"
# nix-instantiate -A nix "$NIX_FILES_TOP"
# nix-instantiate -A nixpkgs "$NIX_FILES_TOP"
debug "querying packages to update as part of '$attrPrefix'"
local attrs=$(nix eval --raw -f "$NIX_FILES_TOP" 'updateTargets."'"$attrPrefix"'"' --apply 'builtins.concatStringsSep " "')
debug "got: $attrs"