From ca980de3817464edc95bfba4f5bae608db2ff16f Mon Sep 17 00:00:00 2001 From: Peder Bergebakken Sundt Date: Sun, 1 Jun 2025 00:02:14 +0200 Subject: [PATCH] ljdsadsldsalkj --- justfile | 120 ++++++++++++++++++++++++++++++------------------------- 1 file changed, 66 insertions(+), 54 deletions(-) diff --git a/justfile b/justfile index ee3fc21..fcabb88 100644 --- a/justfile +++ b/justfile @@ -1,6 +1,6 @@ #!/usr/bin/env just --justfile -# makes variables accesible as $1 $2 $@, useful for escaping variadics +# makes variables accesible as $1 $2 $@, useful for escaping variadics set positional-arguments := true export invokedir := invocation_directory() @@ -8,12 +8,17 @@ export epoch := `date +%s` export GUM_FILTER_HEIGHT := "15" export FZF_DEFAULT_OPTS := "--height 15 --cycle --bind 'ctrl-a:toggle-all' " + env('FZF_DEFAULT_OPTS', "") export GIT := `command -v git-wait >/dev/null && echo "git-wait" || echo "git"` + # will trigger a direnv reload when we enter $SHELL export DIRENV_WATCHES := "" + # please no surprises for now export NIXPKGS_CONFIG := "" export NIX_PATH := `echo "${NIX_PATH_ORIG:-"${NIX_PATH:-}"}"` +XARGS_NL := "-d'\\n' --no-run-if-empty" +NIX_EVAL_OPTS := "--log-format raw --option warn-dirty false" + # required programs: git nix nom gum fzf tee nix-update @_default: @@ -47,10 +52,22 @@ list-packages +$cut_args="-c1-": _packages_json fi cut <"$cachefile" "$@" +list-packages-fname-filtered *fnames: + #!/usr/bin/env -S bash -euo pipefail + declare -a fnames=("$@") + if [[ "${#fnames[@]}" -gt 0 ]]; then + printf "%s\n" "${fnames[@]}" | just _list_packages_fname_filtered + elif [[ -t 0 ]]; then + fd . pkgs -enix -tf | fzf --reverse --multi | just _list_packages_fname_filtered + else + echo >&2 No args and no tty, reading from stdin... + just _list_packages_fname_filtered + fi @_list_packages_fname_filtered: - xargs -d $'\n' -n 2000 just __list_packages_fname_filtered \ + xargs {{XARGS_NL}} -n 2000 just __list_packages_fname_filtered \ | tr '0123456789' '9876543210' | sort -u | tr '0123456789' '9876543210' + @__list_packages_fname_filtered +fnames: just list-packages | grep --fixed-strings "$(printf "\t%s\t\n" "$@")" \ | grep -v $'\t'pkgs/top-level/ \ @@ -71,21 +88,10 @@ list-packages +$cut_args="-c1-": _packages_json | grep -v $'\t'pkgs/tools/package-management/akku/default.nix \ | grep -v $'\t'pkgs/tools/typesetting/tex/texlive/build-texlive-package.nix -list-packages-by-fname *fnames: - #!/usr/bin/env -S bash -euo pipefail - declare -a fnames=("$@") - if [[ "${#fnames[@]}" -gt 0 ]]; then - printf "%s\n" "${fnames[@]}" | just _list_packages_attrpath_filtered - elif [[ -t 0 ]]; then - fd . pkgs -enix -tf | fzf --reverse --multi | just _list_packages_attrpath_filtered - else - echo >&2 No args and no tty, reading from stdin... - just _list_packages_attrpath_filtered - fi - @_list_packages_attrpath_filtered: tr '0123456789' '9876543210' | sort -u | tr '0123456789' '9876543210' \ - | xargs -d $'\n' -n 2000 --no-run-if-empty just __list_packages_attrpath_filtered + | xargs {{XARGS_NL}} -n 2000 just __list_packages_attrpath_filtered + __list_packages_attrpath_filtered +attrpaths: #!/usr/bin/env -S bash -euo pipefail declare -a attrpaths=("$@") @@ -135,37 +141,40 @@ __list_packages_attrpath_filtered +attrpaths: # === build helpers === +@build-packages-fname-filtered *fnames: + cd "$invokedir"; just list-packages-fname-filtered "$@" | cut -f1 | xargs {{XARGS_NL}} just build-packages + @build-ripgrepped-packages $ripgrep_arg $attr_prefix="" $attr_suffix="" +$extra_args="": - [[ -n "$extra_args" ]] && export _JUST_NIX_INSTANTIATE_ARGS="$(shift; shift; printf " %q" "$@")"; \ - cd "$invokedir"; just list-ripgrepped-packages "$ripgrep_arg" | cut -f1 | xargs printf "${attr_prefix//%/%%}"'%s'"${attr_suffix//%/%%} " | xargs just build-packages + [[ -n "$extra_args" ]] && export _JUST_NIX_INSTANTIATE_ARGS="$(shift; shift; printf " %q" "$@")"; \ + cd "$invokedir"; just list-ripgrepped-packages "$ripgrep_arg" | cut -f1 | xargs {{XARGS_NL}} printf "${attr_prefix//%/%%}"'%s'"${attr_suffix//%/%%}\n" | xargs {{XARGS_NL}} just build-packages @build-nix-located-packages $nix_locate_arg $attr_prefix="" $attr_suffix="" +$extra_args="": - [[ -n "$extra_args" ]] && export _JUST_NIX_INSTANTIATE_ARGS="$(shift; shift; printf " %q" "$@")"; \ - cd "$invokedir"; just list-nix-located-packages "$nix_locate_arg" | cut -f1 | xargs printf "${attr_prefix//%/%%}"'%s'"${attr_suffix//%/%%} " | xargs just build-packages + [[ -n "$extra_args" ]] && export _JUST_NIX_INSTANTIATE_ARGS="$(shift; shift; printf " %q" "$@")"; \ + cd "$invokedir"; just list-nix-located-packages "$nix_locate_arg" | cut -f1 | xargs {{XARGS_NL}} printf "${attr_prefix//%/%%}"'%s'"${attr_suffix//%/%%}\n" | xargs {{XARGS_NL}} just build-packages @build-dirty-packages $attr_prefix="" $attr_suffix="" +$extra_args="": [[ -n "$extra_args" ]] && export _JUST_NIX_INSTANTIATE_ARGS="$(shift; shift; printf " %q" "$@")"; \ - cd "$invokedir"; just list-dirty-packages | cut -f1 | xargs printf "${attr_prefix//%/%%}"'%s'"${attr_suffix//%/%%} " | xargs just build-packages + cd "$invokedir"; just list-dirty-packages | cut -f1 | xargs {{XARGS_NL}} printf "${attr_prefix//%/%%}"'%s'"${attr_suffix//%/%%}\n" | xargs {{XARGS_NL}} just build-packages @instantiate-dirty-packages $attr_prefix="" $attr_suffix="" +$extra_args="": [[ -n "$extra_args" ]] && export _JUST_NIX_INSTANTIATE_ARGS="$(shift; shift; printf " %q" "$@")"; \ - cd "$invokedir"; just list-dirty-packages | cut -f1 | xargs printf "${attr_prefix//%/%%}"'%s'"${attr_suffix//%/%%} " | xargs just instantiate-packages + cd "$invokedir"; just list-dirty-packages | cut -f1 | xargs {{XARGS_NL}} printf "${attr_prefix//%/%%}"'%s'"${attr_suffix//%/%%}\n" | xargs {{XARGS_NL}} just instantiate-packages @build-touched-packages-since $attr_prefix="" $attr_suffix="" +$extra_args="": [[ -n "$extra_args" ]] && export _JUST_NIX_INSTANTIATE_ARGS="$(shift; shift; printf " %q" "$@")"; \ - cd "$invokedir"; just list-touched-packages-since | cut -f1 | xargs printf "${attr_prefix//%/%%}"'%s'"${attr_suffix//%/%%} " | xargs just build-packages + cd "$invokedir"; just list-touched-packages-since | cut -f1 | xargs {{XARGS_NL}} printf "${attr_prefix//%/%%}"'%s'"${attr_suffix//%/%%}\n" | xargs {{XARGS_NL}} just build-packages @instantiate-touched-packages-since $attr_prefix="" $attr_suffix="" +$extra_args="": [[ -n "$extra_args" ]] && export _JUST_NIX_INSTANTIATE_ARGS="$(shift; shift; printf " %q" "$@")"; \ - cd "$invokedir"; just list-touched-packages-since | cut -f1 | xargs printf "${attr_prefix//%/%%}"'%s'"${attr_suffix//%/%%} " | xargs just instantiate-packages + cd "$invokedir"; just list-touched-packages-since | cut -f1 | xargs {{XARGS_NL}} printf "${attr_prefix//%/%%}"'%s'"${attr_suffix//%/%%}\n" | xargs {{XARGS_NL}} just instantiate-packages @build-unmerged-packages $attr_prefix="" $attr_suffix="" +$extra_args="": [[ -n "$extra_args" ]] && export _JUST_NIX_INSTANTIATE_ARGS="$(shift; shift; printf " %q" "$@")"; \ - cd "$invokedir"; just list-unmerged-packages | xargs printf "${attr_prefix//%/%%}"'%s'"${attr_suffix//%/%%} " | xargs just build-packages + cd "$invokedir"; just list-unmerged-packages | xargs {{XARGS_NL}} printf "${attr_prefix//%/%%}"'%s'"${attr_suffix//%/%%}\n" | xargs {{XARGS_NL}} just build-packages @instantiate-unmerged-packages $attr_prefix="" $attr_suffix="" +$extra_args="": [[ -n "$extra_args" ]] && export _JUST_NIX_INSTANTIATE_ARGS="$(shift; shift; printf " %q" "$@")"; \ - cd "$invokedir"; just list-unmerged-packages | xargs printf "${attr_prefix//%/%%}"'%s'"${attr_suffix//%/%%} " | xargs just instantiate-packages + cd "$invokedir"; just list-unmerged-packages | xargs {{XARGS_NL}} printf "${attr_prefix//%/%%}"'%s'"${attr_suffix//%/%%}\n" | xargs {{XARGS_NL}} just instantiate-packages # @@ -247,6 +256,7 @@ profile *args: # _JUST_NIX_BUILD_ARGS='--check' # _JUST_NIX_BUILD_ARGS='-j0 --builders "@/etc/nix/machines; ssh://pederbs@heid.idi.ntnu.no x86_64-linux - 24 5 big-parallel"' # _JUST_NIX_INSTANTIATE_ARGS='--system darwin' + # TODO: is ^ now broken? @build-packages *$attrpaths: [[ "$#" -gt 0 ]] || set -- $(just _some_packages); \ @@ -275,7 +285,7 @@ __build_packages $system $outdir +$attrpaths: # set -x just _instantiate_packages "$system" "${attrpaths[@]}" | tee >(command cat >&2) \ | while IFS=! read path output; do printf "%s\n" "$(realpath "$path")${output:+!"$output"}"; done \ - | xargs -d'\n' nom-build --keep-going --no-out-link ${_JUST_NIX_BUILD_ARGS:-} ||: + | xargs {{XARGS_NL}} nom-build --keep-going --no-out-link ${_JUST_NIX_BUILD_ARGS:-} ||: # | eval xargs nom-build --keep-going --no-out-link ${_JUST_NIX_BUILD_ARGS:-} ||: worker() { local attrpath="$1" @@ -305,7 +315,8 @@ __build_packages $system $outdir +$attrpaths: fi # local outpaths=$( nix-store -q --outputs "$drvpath" ) # doesn't gcroot, some outputs may not be pulled from builders if [[ -L "$dst" ]]; then - nix log --option substituters "" $(readlink "$dst") > "$dst".log 2>/dev/null ||: + nix log $(readlink "$dst") > "$dst".log 2>/dev/null ||: + # nix log --option substituters "" $(readlink "$dst") > "$dst".log 2>/dev/null ||: else if [[ -z "$drvpath" ]]; then ln -s "$NOTFOUNDDIR"/no-eval "$dst" @@ -384,17 +395,18 @@ _build_package_sources $system +packages: } >build.nix chmod +x build.nix +# TODO: redesign or drop @build-pr-packages $pr=`just _a_pr` $merge=`gum choose --header="which refs/pull//xxx ?" merge head` $attrpaths=`just _some_packages` $args=`gum choose --no-limit -- -j0 "--system "{aarch64,x86_64}-{darwin,linux} --rebuild`: - -printf "github:nixos/nixpkgs/refs/pull/"$(just _sanitize_pr_url "$pr")"/$merge#%s" $attrpaths | xargs echo + nom build $args - -(printf "github:nixos/nixpkgs/refs/pull/"$(just _sanitize_pr_url "$pr")"/$merge#%s" $attrpaths | xargs nom build $args) || true - -printf "github:nixos/nixpkgs/refs/pull/"$(just _sanitize_pr_url "$pr")"/$merge#%s" $attrpaths | xargs echo + nom build $args + printf "github:nixos/nixpkgs/refs/pull/"$(just _sanitize_pr_url "$pr")"/$merge#%s\n" $attrpaths | xargs {{XARGS_NL}} echo + nom build $args + (printf "github:nixos/nixpkgs/refs/pull/"$(just _sanitize_pr_url "$pr")"/$merge#%s\n" $attrpaths | xargs {{XARGS_NL}} nom build $args) ||: + printf "github:nixos/nixpkgs/refs/pull/"$(just _sanitize_pr_url "$pr")"/$merge#%s\n" $attrpaths | xargs {{XARGS_NL}} echo + nom build $args # === commit helpers === [no-cd] @commit-staged *$message: - test -n "$(git diff HEAD --name-only --staged)" || ! echo >&2 "No files are staged!" - $GIT -c commit.template=<(git diff HEAD --name-only --staged | just _list_packages_fname_filtered | cut -f1 | xargs -d'\n' printf "%s: ${*//%/%%}\n") commit && git show + test -n "$(git diff HEAD --name-only --staged)" || ! echo >&2 "No files are staged!" + $GIT -c commit.template=<(git diff HEAD --name-only --staged | just _list_packages_fname_filtered | cut -f1 | xargs {{XARGS_NL}} printf "%s: ${*//%/%%}\n") commit && git show [no-cd] commit-dirty-packages +$message=`gum input --placeholder="commit message, (attrpath: this message)"`: @@ -460,7 +472,6 @@ push-new-pr: gh pr create fi - # === speed worktrees === bump-new-worktree *packages: @@ -482,7 +493,7 @@ bump-here *packages: declare -a packages=("$@") [[ -n "${packages[*]}" ]] || packages=($(just _some_packages)) system="$(just _a_system)" - printf "%s.src\n" "${packages[@]}" | xargs just __build_packages "$system" results-src-old ||: # TODO: unpack? + printf "%s.src\n" "${packages[@]}" | xargs {{XARGS_NL}} just __build_packages "$system" results-src-old ||: # TODO: unpack? config=( env NIXPKGS_ALLOW_UNFREE=1 @@ -490,7 +501,7 @@ bump-here *packages: NIXPKGS_ALLOW_INSECURE=1 ) for package in "${packages[@]}"; do - if nix eval --log-format raw --file default.nix "$package".passthru.updateScript >&/dev/null; then + if nix eval {{NIX_EVAL_OPTS}} --file default.nix "$package".passthru.updateScript >&/dev/null; then HEAD=$($GIT rev-parse HEAD) "${config[@]}" nix-update "$package" --use-update-script --update-script-args "--argstr skip-prompt true" --commit if [[ $($GIT rev-parse HEAD) = "$HEAD" ]]; then @@ -503,10 +514,10 @@ bump-here *packages: fi done set +e - printf "%s.src\n" "${packages[@]}" | xargs just __build_packages "$system" results-src-new # TODO: unpack? + printf "%s.src\n" "${packages[@]}" | xargs {{XARGS_NL}} just __build_packages "$system" results-src-new # TODO: unpack? just __build_packages "$system" results "${packages[@]}" # TODO: filter non-existing tests: - printf "%s.tests\n" "${packages[@]}" | env _JUST_NIX_BUILD_ARGS="-j1" xargs just __build_packages "$system" results-tests + printf "%s.tests\n" "${packages[@]}" | env _JUST_NIX_BUILD_ARGS="-j1" xargs {{XARGS_NL}} just __build_packages "$system" results-tests printf "HEAD^%s " $(seq 0 $(( "${#packages[@]}" - 1 ))) | xe $GIT show fd . -l results results-tests --max-depth 1 # test -L result && fd . result --type x --color=always | tee update-executables.txt @@ -515,7 +526,8 @@ bump-here *packages: printf "\n" printf "delta results-src-{old,new}/%s.src/.\n" "${packages[@]}" printf "\n" - printf > delta-cmds.sh "echo no; exit 1\n" + printf > delta-cmds.sh '#!/usr/bin/env bash\n' + printf >>delta-cmds.sh 'tail "$0" -n+3 | bat --style plain -l bash; exit 1\n' printf >>delta-cmds.sh "delta results-src-{old,new}/%s.src/.\n" "${packages[@]}" fix *packages: @@ -609,10 +621,10 @@ pr $number=`just _a_pr`: >>"$FNAME" echo; \ >>"$FNAME" echo ''; \ >>"$FNAME" echo; \ - >>"$FNAME" echo '_How to apply (pick one):_'; \ + >>"$FNAME" echo '_How to apply (pick either):_'; \ >>"$FNAME" echo; \ - >>"$FNAME" echo 'a. `curl -L "'"$($GIT diff --staged | gh gist create -f pr-$NUMBER.patch -)"'/raw" | $GIT apply`'; \ - >>"$FNAME" echo 'b. copy the patch above, run `$GIT apply`, paste (typically `ctrl-shift-v`), press enter, then end the input with `ctrl-d`'; \ + >>"$FNAME" echo 'a. `curl -L "'"$(git diff --staged | gh gist create -f pr-$NUMBER.patch -)"'/raw" | git apply`'; \ + >>"$FNAME" echo 'b. copy the patch above, run `git apply`, paste (typically `ctrl-shift-v`), press enter, then end the input with `ctrl-d`'; \ "$EDITOR" "$FNAME"; \ test -s "$FNAME" && bat --language markdown --style plain --pager never "$FNAME" && gum confirm && gh pr {{ mode }} "$NUMBER" --body-file "$FNAME"; \ rm -v "$FNAME" @@ -681,10 +693,10 @@ pop-commits-to-new-worktree $commits=`cd "$invokedir"; just _some_commits`: cd "$( just _new_worktree "$type" "$(gum input --placeholder="Branch name?" --value="$name")" )" - if (tac <<<"$commits" | xargs git cherry-pick); then + if (tac <<<"$commits" | xargs {{XARGS_NL}} git cherry-pick); then ( cd "$invokedir" - EDITOR="sed -i $(xargs <<<"$commits" printf " -e 's/^pick %s/#/g'")" \ + EDITOR="sed -i $(xargs {{XARGS_NL}} <<<"$commits" printf " -e 's/^pick %s/#/g'")" \ git rebase "$(tail -n1 <<<"$commits")"^^ -i ) git log -n "$(wc -l <<<"$commits" )" @@ -793,7 +805,7 @@ _mk_clean_list: ( cd master # TODO: assert "upstream" present? - just _upstream_release_branches "" | xargs -d'\n' $GIT fetch upstream + just _upstream_release_branches "" | xargs {{XARGS_NL}} $GIT fetch upstream ) porcelain2jsonl() { uniq | ( @@ -867,7 +879,7 @@ _get_version $attrpath +paths: if [[ -d "$path" ]]; then sleep 0.1 # HACK, sort it properly instead echo "$attrpath.version @ $path: $( - nix eval --log-format raw --file "$path"/default.nix "$attrpath" \ + nix eval {{NIX_EVAL_OPTS}} --file "$path"/default.nix "$attrpath" \ --apply 'let lib = import ./master/lib; in lib.getVersion' --raw )" & fi @@ -902,9 +914,9 @@ open-package-urls $package=`just _a_package`: #!/usr/bin/env -S bash -euo pipefail fpkg="$(jq -rn --arg x "$package" '$x | @uri')" bpkg="$(jq -rn --arg x "$(rev <<<"$package" | cut -d. -f1 | rev)" '$x | @uri')" - # homepage="$(nix eval --log-format raw --file master/default.nix "$package".meta.homepage --raw ||:)" - srcpage="$(nix eval --log-format raw --file master/default.nix "$package".src.meta.homepage --raw ||:)" - position="$({ nix eval --log-format raw --file master/default.nix "$package".meta.position --raw ||: ; } | rev | cut -d: -f2- | rev | sd -F "$PWD/master/" "")" + # homepage="$(nix eval {{NIX_EVAL_OPTS}} --file master/default.nix "$package".meta.homepage --raw ||:)" + srcpage="$(nix eval {{NIX_EVAL_OPTS}} --file master/default.nix "$package".src.meta.homepage --raw ||:)" + position="$({ nix eval {{NIX_EVAL_OPTS}} --file master/default.nix "$package".meta.position --raw ||: ; } | rev | cut -d: -f2- | rev | sd -F "$PWD/master/" "")" declare -a urls=() urls+=("https://hydra.nixos.org/job/nixos/trunk-combined/nixpkgs.${fpkg}.x86_64-linux") urls+=("https://github.com/NixOS/nixpkgs/pulls?q=is%3Apr+in%3Atitle+${bpkg}") @@ -1042,8 +1054,8 @@ _a_system: printf "%s\n" "$JUST_SYSTEM" | head -n1 exit 0 fi - # nix eval --file master/default.nix lib.systems.flakeExposed --json | jq .[] -r | xargs -d'\n' gum choose --selected "$(just _this_system)" - systems="$(nix eval --log-format raw --file master/default.nix lib.systems.flakeExposed --json)" + # nix eval --file master/default.nix lib.systems.flakeExposed --json | jq .[] -r | xargs {{XARGS_NL}} gum choose --selected "$(just _this_system)" + systems="$(nix eval {{NIX_EVAL_OPTS}} --file master/default.nix lib.systems.flakeExposed --json)" system="$(just _this_system)" # system="aarch64-darwin" jq <<<"$systems" .[] -r | fzf --sync --layout=reverse $( @@ -1057,8 +1069,8 @@ _some_systems: printf "%s\n" "$JUST_SYSTEM" exit 0 fi - # nix eval --log-format raw --file master/default.nix lib.systems.flakeExposed --json | jq .[] -r | xargs -d'\n' gum choose --no-limit --selected "$(just _this_system)" - systems="$(nix eval --log-format raw --file master/default.nix lib.systems.flakeExposed --json)" + # nix eval {{NIX_EVAL_OPTS}} --file master/default.nix lib.systems.flakeExposed --json | jq .[] -r | xargs {{XARGS_NL}} gum choose --no-limit --selected "$(just _this_system)" + systems="$(nix eval {{NIX_EVAL_OPTS}} --file master/default.nix lib.systems.flakeExposed --json)" system="$(just _this_system)" # system="aarch64-darwin" jq <<<"$systems" .[] -r | fzf --sync --layout=reverse --multi $( @@ -1067,13 +1079,13 @@ _some_systems: ) _a_maintainer: - nix eval --log-format raw --file master/maintainers/maintainer-list.nix \ + nix eval {{NIX_EVAL_OPTS}} --file master/maintainers/maintainer-list.nix \ --apply 'x: builtins.attrValues (builtins.mapAttrs (k: v: v.github or k) x)' --json \ | jq .[] -r \ | fzf --sync --layout=reverse _some_maintainers: - nix eval --log-format raw --file master/maintainers/maintainer-list.nix \ + nix eval {{NIX_EVAL_OPTS}} --file master/maintainers/maintainer-list.nix \ --apply 'x: builtins.attrValues (builtins.mapAttrs (k: v: v.github or k) x)' --json \ | jq .[] -r \ | fzf --sync --layout=reverse --multi