diff --git a/pkgs/applications/networking/browsers/chromium/default.nix b/pkgs/applications/networking/browsers/chromium/default.nix index 990eafa066778..58cb30f335ad1 100644 --- a/pkgs/applications/networking/browsers/chromium/default.nix +++ b/pkgs/applications/networking/browsers/chromium/default.nix @@ -79,13 +79,7 @@ let pulseSupport ungoogled ; - gnChromium = buildPackages.gn.overrideAttrs (oldAttrs: { - version = if (upstream-info.deps.gn ? "version") then upstream-info.deps.gn.version else "0"; - src = fetchgit { - url = "https://gn.googlesource.com/gn"; - inherit (upstream-info.deps.gn) rev hash; - }; - }); + gnChromium = buildPackages.gn.override upstream-info.deps.gn; }); browser = callPackage ./browser.nix { diff --git a/pkgs/applications/networking/browsers/chromium/info.json b/pkgs/applications/networking/browsers/chromium/info.json index eb1b32f6892f4..0018ece27e34b 100644 --- a/pkgs/applications/networking/browsers/chromium/info.json +++ b/pkgs/applications/networking/browsers/chromium/info.json @@ -12,8 +12,9 @@ "hash": "sha256-UouvzNFStYScnyfIJcz1Om7cDhC7EyShZQ/Icu73BPo=" }, "gn": { + "version": "0-unstable-2025-06-19", "rev": "97b68a0bb62b7528bc3491c7949d6804223c2b82", - "hash": "sha256-m+z10s40Q/iYcoMw3o/+tmhIdqHMsYJjdGabHrK/aqo=" + "hash": "sha256-gwptzuirIdPAV9XCaAT09aM/fY7d6xgBU7oSu9C4tmE=" }, "npmHash": "sha256-R2gOpfPOUAmnsnUTIvzDPHuHNzL/b2fwlyyfTrywEcI=" }, @@ -809,8 +810,9 @@ "hash": "sha256-UouvzNFStYScnyfIJcz1Om7cDhC7EyShZQ/Icu73BPo=" }, "gn": { + "version": "0-unstable-2025-06-19", "rev": "97b68a0bb62b7528bc3491c7949d6804223c2b82", - "hash": "sha256-m+z10s40Q/iYcoMw3o/+tmhIdqHMsYJjdGabHrK/aqo=" + "hash": "sha256-gwptzuirIdPAV9XCaAT09aM/fY7d6xgBU7oSu9C4tmE=" }, "ungoogled-patches": { "rev": "139.0.7258.66-1", diff --git a/pkgs/applications/networking/browsers/chromium/update.mjs b/pkgs/applications/networking/browsers/chromium/update.mjs index 42483eb06b401..838c07ae68143 100755 --- a/pkgs/applications/networking/browsers/chromium/update.mjs +++ b/pkgs/applications/networking/browsers/chromium/update.mjs @@ -62,7 +62,7 @@ for (const attr_path of Object.keys(lockfile)) { chromedriver: !ungoogled ? await fetch_chromedriver_binaries(await get_latest_chromium_release('mac')) : undefined, deps: { depot_tools: {}, - gn: {}, + gn: await fetch_gn(chromium_rev, lockfile_initial[attr_path].deps.gn), 'ungoogled-patches': !ungoogled ? undefined : { rev: ungoogled_patches.rev, hash: ungoogled_patches.hash, @@ -78,12 +78,6 @@ for (const attr_path of Object.keys(lockfile)) { hash: depot_tools.hash, } - const gn = await fetch_gn(chromium_rev, lockfile_initial[attr_path].deps.gn) - lockfile[attr_path].deps.gn = { - rev: gn.rev, - hash: gn.hash, - } - // DEPS update loop lockfile[attr_path].DEPS = await resolve_DEPS(depot_tools.out, chromium_rev) for (const [path, value] of Object.entries(lockfile[attr_path].DEPS)) { @@ -133,10 +127,34 @@ for (const attr_path of Object.keys(lockfile)) { async function fetch_gn(chromium_rev, gn_previous) { const DEPS_file = await get_gitiles_file('https://chromium.googlesource.com/chromium/src', chromium_rev, 'DEPS') - const gn_rev = /^\s+'gn_version': 'git_revision:(?.+)',$/m.exec(DEPS_file).groups.rev - const hash = gn_rev === gn_previous.rev ? gn_previous.hash : '' + const { rev } = /^\s+'gn_version': 'git_revision:(?.+)',$/m.exec(DEPS_file).groups + + const cache_hit = rev === gn_previous.rev; + if (cache_hit) { + return gn_previous + } + + const commit_date = await get_gitiles_commit_date('https://gn.googlesource.com/gn', rev) + const version = `0-unstable-${commit_date}` - return await prefetch_gitiles('https://gn.googlesource.com/gn', gn_rev, hash) + const expr = [`(import ./. {}).gn.override { version = "${version}"; rev = "${rev}"; hash = ""; }`] + const derivation = await $nixpkgs`nix-instantiate --expr ${expr}` + + return { + version, + rev, + hash: await prefetch_FOD(derivation), + } +} + + +async function get_gitiles_commit_date(base_url, rev) { + const url = `${base_url}/+/${rev}?format=json` + const response = await (await fetch(url)).text() + const json = JSON.parse(response.replace(`)]}'\n`, '')) + + const date = new Date(json.commiter.time) + return date.toISOString().split("T")[0] } @@ -259,4 +277,3 @@ async function prefetch_FOD(...args) { return hash } - diff --git a/pkgs/by-name/gn/gn/generic.nix b/pkgs/by-name/gn/gn/generic.nix deleted file mode 100644 index 98328fcd97f38..0000000000000 --- a/pkgs/by-name/gn/gn/generic.nix +++ /dev/null @@ -1,79 +0,0 @@ -{ - stdenv, - lib, - fetchgit, - fetchpatch, - cctools, - writeText, - ninja, - python3, - ... -}: - -{ - rev, - revNum, - version, - sha256, -}: - -let - revShort = builtins.substring 0 7 rev; - lastCommitPosition = writeText "last_commit_position.h" '' - #ifndef OUT_LAST_COMMIT_POSITION_H_ - #define OUT_LAST_COMMIT_POSITION_H_ - - #define LAST_COMMIT_POSITION_NUM ${revNum} - #define LAST_COMMIT_POSITION "${revNum} (${revShort})" - - #endif // OUT_LAST_COMMIT_POSITION_H_ - ''; - -in -stdenv.mkDerivation { - pname = "gn-unstable"; - inherit version; - - src = fetchgit { - # Note: The TAR-Archives (+archive/${rev}.tar.gz) are not deterministic! - url = "https://gn.googlesource.com/gn"; - inherit rev sha256; - }; - - nativeBuildInputs = [ - ninja - python3 - ]; - buildInputs = lib.optionals stdenv.hostPlatform.isDarwin [ - cctools - ]; - - env.NIX_CFLAGS_COMPILE = "-Wno-error"; - # Relax hardening as otherwise gn unstable 2024-06-06 and later fail with: - # cc1plus: error: '-Wformat-security' ignored without '-Wformat' [-Werror=format-security] - hardeningDisable = [ "format" ]; - - buildPhase = '' - python build/gen.py --no-last-commit-position - ln -s ${lastCommitPosition} out/last_commit_position.h - ninja -j $NIX_BUILD_CORES -C out gn - ''; - - installPhase = '' - install -vD out/gn "$out/bin/gn" - ''; - - setupHook = ./setup-hook.sh; - - meta = with lib; { - description = "Meta-build system that generates build files for Ninja"; - mainProgram = "gn"; - homepage = "https://gn.googlesource.com/gn"; - license = licenses.bsd3; - platforms = platforms.unix; - maintainers = with maintainers; [ - stesie - matthewbauer - ]; - }; -} diff --git a/pkgs/by-name/gn/gn/package.nix b/pkgs/by-name/gn/gn/package.nix index fa3322edd2222..988151f91b129 100644 --- a/pkgs/by-name/gn/gn/package.nix +++ b/pkgs/by-name/gn/gn/package.nix @@ -1,10 +1,102 @@ -{ callPackage, ... }@args: +{ + stdenv, + lib, + fetchgit, + cctools, + ninja, + python3, -callPackage ./generic.nix args { # Note: Please use the recommended version for Chromium stable, i.e. from # /pkgs/applications/networking/browsers/chromium/info.json - rev = "85cc21e94af590a267c1c7a47020d9b420f8a033"; - revNum = "2233"; # git describe $rev --match initial-commit | cut -d- -f3 - version = "2025-04-28"; - sha256 = "sha256-+nKP2hBUKIqdNfDz1vGggXSdCuttOt0GwyGUQ3Z1ZHI="; + version ? + # This is a workaround for update-source-version to be able to update this + let + _version = "0-unstable-2025-06-19"; + in + _version, + rev ? "97b68a0bb62b7528bc3491c7949d6804223c2b82", + hash ? "sha256-gwptzuirIdPAV9XCaAT09aM/fY7d6xgBU7oSu9C4tmE=", +}: + +stdenv.mkDerivation { + pname = "gn"; + inherit version; + + src = fetchgit { + url = "https://gn.googlesource.com/gn"; + inherit rev hash; + leaveDotGit = true; + deepClone = true; + postFetch = '' + cd "$out" + mkdir .nix-files + git rev-parse --short=12 HEAD > .nix-files/REV_SHORT + git describe --match initial-commit | cut -d- -f3 > .nix-files/REV_NUM + find "$out" -name .git -print0 | xargs -0 rm -rf + ''; + }; + + nativeBuildInputs = [ + ninja + python3 + ]; + buildInputs = lib.optionals stdenv.hostPlatform.isDarwin [ + cctools + ]; + + env.NIX_CFLAGS_COMPILE = "-Wno-error"; + # Relax hardening as otherwise gn unstable 2024-06-06 and later fail with: + # cc1plus: error: '-Wformat-security' ignored without '-Wformat' [-Werror=format-security] + hardeningDisable = [ "format" ]; + + configurePhase = '' + runHook preConfigure + + python build/gen.py --no-last-commit-position + cat > out/last_commit_position.h << EOF + #ifndef OUT_LAST_COMMIT_POSITION_H_ + #define OUT_LAST_COMMIT_POSITION_H_ + + #define LAST_COMMIT_POSITION_NUM $(<.nix-files/REV_NUM) + #define LAST_COMMIT_POSITION "$(<.nix-files/REV_NUM) ($(<.nix-files/REV_SHORT))" + + #endif // OUT_LAST_COMMIT_POSITION_H_ + EOF + + runHook postConfigure + ''; + + buildPhase = '' + runHook preBuild + + ninja -v -j $NIX_BUILD_CORES -C out gn + + runHook postBuild + ''; + + installPhase = '' + runHook preInstall + + install -vD out/gn "$out/bin/gn" + + runHook postInstall + ''; + + setupHook = ./setup-hook.sh; + + passthru.updateScript = ./update.sh; + + meta = { + description = "Meta-build system that generates build files for Ninja"; + mainProgram = "gn"; + homepage = "https://gn.googlesource.com/gn"; + license = lib.licenses.bsd3; + platforms = lib.platforms.unix; + maintainers = with lib.maintainers; [ + stesie + matthewbauer + marcin-serwin + emilylange + ]; + }; } diff --git a/pkgs/by-name/gn/gn/update.sh b/pkgs/by-name/gn/gn/update.sh new file mode 100755 index 0000000000000..692426e8f149c --- /dev/null +++ b/pkgs/by-name/gn/gn/update.sh @@ -0,0 +1,21 @@ +#!/usr/bin/env nix-shell +#!nix-shell -i bash -p jq curl common-updater-scripts + +set -ex + +rev=$( + curl --location "https://raw.githubusercontent.com/NixOS/nixpkgs/refs/heads/master/pkgs/applications/networking/browsers/chromium/info.json" \ + | jq -r ".chromium.deps.gn.rev" +) + +commit_time=$( + curl "https://gn.googlesource.com/gn/+/$rev?format=json" \ + | sed "s/)]}'//" \ + | jq -r ".committer.time" \ + | awk '{print $2, $3, $5, $4 $6}' +) + +commit_date=$(TZ= date --date "$commit_time" --iso-8601) +version="0-unstable-$commit_date" + +update-source-version --rev="$rev" --version-key="_version" "gn" "$version" diff --git a/pkgs/development/tools/electron/info.json b/pkgs/development/tools/electron/info.json index 13aa8d2762f89..9719f9c19b005 100644 --- a/pkgs/development/tools/electron/info.json +++ b/pkgs/development/tools/electron/info.json @@ -4,10 +4,9 @@ "chromium": { "deps": { "gn": { - "hash": "sha256-EqbwCLkseND1v3UqM+49N7GuoXJ3PlJjWOes4OijQ3U=", + "hash": "sha256-U0f/Q134UJrSke+/o9Hs4+mQa/vSM2hdkRXhLfhnqME=", "rev": "ed1abc107815210dc66ec439542bee2f6cbabc00", - "url": "https://gn.googlesource.com/gn", - "version": "2025-01-13" + "version": "0-unstable-2025-01-13" } }, "version": "134.0.6998.205" @@ -1313,10 +1312,9 @@ "chromium": { "deps": { "gn": { - "hash": "sha256-vDKMt23RMDI+KX6CmjfeOhRv2haf/mDOuHpWKnlODcg=", + "hash": "sha256-MnGl+D9ahQibUHCtyOUf1snvmeupUn4D2yrDj55JTe4=", "rev": "6e8e0d6d4a151ab2ed9b4a35366e630c55888444", - "url": "https://gn.googlesource.com/gn", - "version": "2025-03-24" + "version": "0-unstable-2025-03-24" } }, "version": "136.0.7103.177" @@ -2638,10 +2636,9 @@ "chromium": { "deps": { "gn": { - "hash": "sha256-UB9a7Fr1W0yYld6WbXyRR8dFqWsj/zx4KumDZ5JQKSM=", + "hash": "sha256-BplU8qNKObVrKMLKTyqivPF1L6bbJulFC+Zop9UpmZY=", "rev": "ebc8f16ca7b0d36a3e532ee90896f9eb48e5423b", - "url": "https://gn.googlesource.com/gn", - "version": "2025-05-21" + "version": "0-unstable-2025-05-21" } }, "version": "138.0.7204.185" diff --git a/pkgs/development/tools/electron/update.py b/pkgs/development/tools/electron/update.py index 0303cb1c682bb..6baf1135a796b 100755 --- a/pkgs/development/tools/electron/update.py +++ b/pkgs/development/tools/electron/update.py @@ -1,5 +1,5 @@ #! /usr/bin/env nix-shell -#! nix-shell -i python -p python3.pkgs.joblib python3.pkgs.click python3.pkgs.click-log nix nix-prefetch-git prefetch-yarn-deps prefetch-npm-deps gclient2nix +#! nix-shell -i python -p python3.pkgs.joblib python3.pkgs.click python3.pkgs.click-log nix nurl prefetch-yarn-deps prefetch-npm-deps gclient2nix """ electron updater @@ -32,7 +32,7 @@ import click import click_log -from datetime import datetime +from datetime import datetime, UTC from typing import Iterable, Tuple from urllib.request import urlopen from joblib import Parallel, delayed, Memory @@ -44,6 +44,9 @@ os.chdir(os.path.dirname(__file__)) +# Absolute path of nixpkgs top-level directory +NIXPKGS_PATH = subprocess.check_output(["git", "rev-parse", "--show-toplevel"]).decode("utf-8").strip() + memory: Memory = Memory("cache", verbose=0) logger = logging.getLogger(__name__) @@ -78,26 +81,34 @@ def get_electron_file(electron_tag: str, filepath: str) -> str: ) +@memory.cache +def get_gn_hash(gn_version, gn_commit): + print("gn.override", file=sys.stderr) + expr = f'(import {NIXPKGS_PATH} {{}}).gn.override {{ version = "{gn_version}"; rev = "{gn_commit}"; hash = ""; }}' + out = subprocess.check_output(["nurl", "--hash", "--expr", expr]) + return out.decode("utf-8").strip() + @memory.cache def get_chromium_gn_source(chromium_tag: str) -> dict: gn_pattern = r"'gn_version': 'git_revision:([0-9a-f]{40})'" gn_commit = re.search(gn_pattern, get_chromium_file(chromium_tag, "DEPS")).group(1) - gn_prefetch: bytes = subprocess.check_output( - [ - "nix-prefetch-git", - "--quiet", - "https://gn.googlesource.com/gn", - "--rev", - gn_commit, - ] + + gn_commit_info = json.loads( + urlopen(f"https://gn.googlesource.com/gn/+/{gn_commit}?format=json") + .read() + .decode("utf-8") + .split(")]}'\n")[1] ) - gn: dict = json.loads(gn_prefetch) + + gn_commit_date = datetime.strptime(gn_commit_info["commiter"]["time"], "%a %b %d %H:%M:%S %Y %z") + gn_date = gn_commit_date.astimezone(UTC).date().isoformat() + gn_version = f"0-unstable-{gn_date}" + return { "gn": { - "version": datetime.fromisoformat(gn["date"]).date().isoformat(), - "url": gn["url"], - "rev": gn["rev"], - "hash": gn["hash"], + "version": gn_version, + "rev": gn_commit, + "hash": get_gn_hash(gn_version, gn_commit), } }