Peder Bergebakken Sundt 357d2530e5 treewide: substitute pname for strings
Inspired by https://github.com/NixOS/nixpkgs/pull/387725#issuecomment-2704943777, script is based on https://github.com/NixOS/nixpkgs/pull/336172 using what i learned in https://github.com/NixOS/nixpkgs/pull/386865, part of https://github.com/NixOS/nixpkgs/issues/346453

Should be zero rebuilds.

All candidates were made using:

```shell

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'
}

FLOCKDIR="$(mktemp -d)"
N_WORKERS=4
while read attrpath fname col; do
    grep -qE 'repo *= *("\$\{pname\}"|pname);' "$fname" || continue

    echo | (
        # mutex on fname
        flock --nonblock 200 || {
            >&2 echo "failed to aquire lock for $fname"
            exit 1
        }

        echo "$attrpath"
        data="$(nix eval --impure  --expr 'with import ./. {}; { 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 '${pname}'  "$pname"         "$fname"
            sd -F ' = pname;' " = \"$pname\";" "$fname"
        )

        data2="$(nix eval --impure  --expr 'with import ./. {}; { 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

        (set -x
            sd -F ' rec {' ' {' "$fname"
        )

        data3="$(nix eval --impure  --expr 'with import ./. {}; { inherit ('"$attrpath"') pname drvPath passthru meta; drvPath2='"$attrpath"'.src.drvPath; }' --json 2>/dev/nul)"

        if [[ "$data" = "$data3" ]]; then
            (set -x; git-wait add "$fname")
        else
            (set -x; git-wait restore "$fname")
        fi

    ) 200>"$FLOCKDIR"/"$(sha256sum - <<<"$fname" | cut -d' ' -f1)".lock &

    while [[ $(jobs -p | wc -l) -ge $N_WORKERS ]]; do
        wait -n < <(jobs -p) || true
    done

done < <(list_attrpath_fname_col)

wait

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.
I checked and cherry-picked the changes using `GIT_DIFF_OPTS='-u15' git -c interactive.singleKey=true add --patch`
2025-03-11 23:55:31 +01:00

110 lines
2.8 KiB
Nix

{
stdenv,
autoreconfHook,
fetchFromGitLab,
fetchpatch,
fetchurl,
fontconfig,
freetype,
gpm,
lib,
ncurses,
pkg-config,
}:
stdenv.mkDerivation rec {
version = "1.7-2";
pname = "fbterm";
src = fetchFromGitLab {
domain = "salsa.debian.org";
owner = "debian";
repo = "fbterm";
rev = "debian/${version}";
hash = "sha256-vRUZgFpA1IkzkLzl7ImT+Yff5XqjFbUlkHmj/hd7XDE=";
};
nativeBuildInputs = [
autoreconfHook
pkg-config
ncurses
];
buildInputs = [
gpm
freetype
fontconfig
ncurses
];
makeFlags = [
"AR:=$(AR)"
];
# preConfigure = ''
# sed -e '/ifdef SYS_signalfd/atypedef long long loff_t;' -i src/fbterm.cpp
# sed -e '/install-exec-hook:/,/^[^\t]/{d}; /.NOEXPORT/iinstall-exec-hook:\
# ' -i src/Makefile.in
# export HOME=$PWD;
# export NIX_LDFLAGS="$NIX_LDFLAGS -lfreetype"
# '';
preInstall = ''
export HOME=$PWD
'';
postInstall =
let
fbtermrc = fetchurl {
url = "https://aur.archlinux.org/cgit/aur.git/plain/fbtermrc?h=fbterm";
hash = "sha256-zNIfi2ZjEGc5PLdOIirKGTXESb5Wm5XBAI1sfHa31LY=";
};
in
''
mkdir -p "$out/share/terminfo"
tic -a -v2 -o"$out/share/terminfo" terminfo/fbterm
mkdir -p "$out/etc/fbterm"
cp "${fbtermrc}" "$out/etc/fbterm"
'';
# Patches from https://aur.archlinux.org/cgit/aur.git/tree/PKGBUILD?h=fbterm
patches = [
(fetchpatch {
url = "https://aur.archlinux.org/cgit/aur.git/plain/fbconfig.patch?h=fbterm";
hash = "sha256-skCdUqyMkkqxS1YUI7cofsfnNNo3SL/qe4WEIXlhm/s=";
})
(fetchpatch {
url = "https://aur.archlinux.org/cgit/aur.git/plain/color_palette.patch?h=fbterm";
hash = "sha256-SkWxzfapyBTtMpTXkiFHRAw8/uXw7cAWwg5Q3TqWlk8=";
})
(fetchpatch {
url = "https://aur.archlinux.org/cgit/aur.git/plain/fbterm.patch?h=fbterm";
hash = "sha256-XNHBTGQGeaQPip2XgcKlr123VDwils2pnyiGqkBGhzU=";
})
(fetchpatch {
url = "https://aur.archlinux.org/cgit/aur.git/plain/0001-Fix-build-with-gcc-6.patch?h=fbterm";
hash = "sha256-3d3zBvr5upICVVkd6tn63IhuB0sF67f62aKnf8KvOwg=";
})
(fetchpatch {
url = "https://aur.archlinux.org/cgit/aur.git/plain/fix_ftbfs_crosscompile.patch?h=fbterm";
hash = "sha256-jv/FSG6dHR0jKjPXQIfqsvpiT/XYzwv/VwuV+qUSovM=";
})
(fetchpatch {
url = "https://aur.archlinux.org/cgit/aur.git/plain/fix_ftbfs_epoll.patch?h=fbterm";
hash = "sha256-wkhfG0uY/5ZApcXTERkaKqz5IDpnilxUEcxull4645A=";
})
];
meta = with lib; {
description = "Framebuffer terminal emulator";
mainProgram = "fbterm";
homepage = "https://salsa.debian.org/debian/fbterm";
maintainers = with maintainers; [
lovesegfault
raskin
];
license = licenses.gpl2Plus;
platforms = platforms.linux;
};
}