Skip to content

treewide: substitute finalAttrs.pname for strings#413122

Merged
drupol merged 1 commit intoNixOS:masterfrom
pbsds:migrate-pname-finalattrs-1748834390
Jun 2, 2025
Merged

treewide: substitute finalAttrs.pname for strings#413122
drupol merged 1 commit intoNixOS:masterfrom
pbsds:migrate-pname-finalattrs-1748834390

Conversation

@pbsds
Copy link
Member

@pbsds pbsds commented Jun 2, 2025

Based on #410679, this time targeting finalAttrs.pname. Limited to pkgs/by-name, part of #346453
I widened the grep to allow for more patterns where finalAttrs.pname are used.

Should be zero rebuilds.

All candidates were made using:

#!/usr/bin/env nix-shell
#!nix-shell -I nixpkgs=. --pure -i bash -p ripgrep sd jq git git-wait lix util-linux

# not suprises plz
export NIX_PATH= # no nixpkgs-overlays
export NIXPKGS_CONFIG=

export NIXPKGS_ALLOW_UNFREE=1
export NIXPKGS_ALLOW_INSECURE=1
export NIXPKGS_ALLOW_BROKEN=1

git-wait restore .

test -s packages.json || ( set -x;
  time nix-env --extra-experimental-features no-url-literals --option system x86_64-linux -f ./. -qaP --json --meta --drv-path --out-path --show-trace --no-allow-import-from-derivation --arg config '{ allowAliases = false; }' > packages.json
)

list_attrpath_fname_col() {
    jq <packages.json 'to_entries[] | select(.value.meta.position==null|not) | "\(.key)\t\(.value.meta.position)"' -r |
        sed -e "s#\t$(realpath .)/#\t#" |
        sed -e 's#:\([0-9]*\)$#\t\1#' |
        grep . |
        grep -iv haskell |
        grep -iv /top-level/ |
        grep -iv chicken |
        grep pkgs/by-name/ |
        grep -iv build |
        grep -E '/(package|default)\.nix'
}

tmp_uid="ZaeDuash6dae1eochai4quuethie3biemahThe1Aenahng9ied" # pwgen -n 50

while read attrpath fname col; do
    grep -qE '\b(repo|exec|icon) *= *("\$\{finalAttrs\.pname\}"|finalAttrs\.pname);' "$fname" ||
    grep -qF '/${finalAttrs.pname}' "$fname" ||
    grep -qF '${finalAttrs.pname}/' "$fname" || continue

    echo | (

        echo "$attrpath"
        data="$(nix eval --log-format raw --impure --expr 'with import ./. {}; lib.attrsets.filterAttrsRecursive (n: v: !lib.isFunction v) { inherit ('"$attrpath"') pname drvPath passthru meta; drvPath2='"$attrpath"'.src.drvPath; }' --json)" || exit
        test -n "$data" || exit
        pname="$(jq <<<"$data" .pname -r)"
        test -n "$pname" || exit

        (set -x
            sd -F '"${finalAttrs.pname}-${finalAttrs.version}' "$tmp_uid" "$fname" # avoid changing this pattern, this is better addressed with more targeted treewides

            sd -F '${finalAttrs.pname}'   "$pname"         "$fname"
            sd -F ' = finalAttrs.pname;'  " = \"$pname\";" "$fname"

            sd -F "$tmp_uid" '"${finalAttrs.pname}-${finalAttrs.version}' "$fname" # revert tmp_uid
        )

        data2="$(nix eval --log-format raw --impure --expr 'with import ./. {}; lib.attrsets.filterAttrsRecursive (n: v: !lib.isFunction v) { inherit ('"$attrpath"') pname drvPath passthru meta; drvPath2='"$attrpath"'.src.drvPath; }' --json)"
        if [[ "$data" = "$data2" ]]; then
            (set -x; git-wait add "$fname")
        else
            (set -x; git-wait restore "$fname")
            exit
        fi

    )

done < <(list_attrpath_fname_col)

git restore .

time nix-env --extra-experimental-features no-url-literals --option system x86_64-linux -f ./. -qaP --json --meta --drv-path --out-path --show-trace --no-allow-import-from-derivation --arg config '{ allowAliases = false; }' > packages2.json

diff packages{,2}.json is empty, indicating that no package nor src derivation has changed, nor have I introduced any eval failures.
I checked and cherry-picked the changes using GIT_DIFF_OPTS='-u20' git -c interactive.singleKey=true add --patch along to some music. I then tested merging against master, staging and staging-next

Things done

  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandboxing enabled in nix.conf? (See Nix manual)
    • sandbox = relaxed
    • sandbox = true
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • Nixpkgs 25.11 Release Notes (or backporting 24.11 and 25.05 Nixpkgs Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
  • NixOS 25.11 Release Notes (or backporting 24.11 and 25.05 NixOS Release notes)
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
  • Fits CONTRIBUTING.md.

Add a 👍 reaction to pull requests you find important.

@pbsds pbsds requested a review from philiptaron June 2, 2025 04:20
@github-actions github-actions bot added 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. 10.rebuild-linux: 0 This PR does not cause any packages to rebuild on Linux. labels Jun 2, 2025
@drupol drupol merged commit 3804709 into NixOS:master Jun 2, 2025
15 of 18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. 10.rebuild-linux: 0 This PR does not cause any packages to rebuild on Linux.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants