···2222 root=$(git rev-parse --show-toplevel)
2323 cd "$root"
2424 host=$(nix eval --raw --impure --expr builtins.currentSystem)
2525- # Only update scripts written for this flake: nix-update with --flake,
2626- # or a script inside this flake. Packages wrapping nixpkgs or
2727- # flake-input packages otherwise inherit an updateScript meant for
2828- # that checkout; those follow flake.lock instead.
2929- src=$(nix flake metadata --json . | jq -r .path)
3030-3131- # attr -> {cmd, pname, version, name}. Per package tryEval: one
3232- # package refusing to evaluate on this system must not hide the rest.
3333- scripts() {
3434- nix eval --json ".#packages.$1" --apply "
3535- ps: builtins.mapAttrs (n: p:
3636- let
3737- r = builtins.tryEval (
3838- let
3939- u = p.passthru.updateScript or null;
4040- isOurs = s: s == \"--flake\"
4141- || builtins.substring 0 (builtins.stringLength \"$src/\") s == \"$src/\";
4242- c =
4343- if builtins.isList u then u
4444- else if builtins.isAttrs u && u ? command then
4545- (if builtins.isList u.command then u.command else [ u.command ])
4646- else [ u ];
4747- v = {
4848- cmd = map toString c;
4949- pname = p.pname or n;
5050- version = p.version or \"\";
5151- name = p.name or n;
5252- };
5353- in
5454- if u == null || !(builtins.any isOurs v.cmd) then null else builtins.deepSeq v v
5555- );
5656- in
5757- if r.success then r.value else null) ps"
5858- }
5959- host_scripts=$(scripts "$host")
6060- linux_scripts='{}'
6161- if [ "$host" != x86_64-linux ]; then
6262- linux_scripts=$(scripts x86_64-linux)
6363- fi
6464- # host entries win over linux ones
6565- all=$(jq -s '.[1] + .[0] | with_entries(select(.value != null))' \
6666- <<<"$host_scripts $linux_scripts")
2525+ all=$(nix eval --json --impure --expr "import ${./scripts.nix} { flake = \"$root\"; host = \"$host\"; }")
67266827 if [ "''${1:-}" = --list ]; then
6928 jq -r 'to_entries[] | "\(.key)\t\(.value.cmd | join(" "))"' <<<"$all"
···11+# attr -> { cmd, pname, version, name } for every flake package with an
22+# updateScript written for this flake. One getFlake call, so the source path
33+# and both package sets come from the same snapshot of the (possibly dirty)
44+# tree. Host entries win; x86_64-linux fills in linux-only packages.
55+{ flake, host }:
66+let
77+ f = builtins.getFlake flake;
88+ src = toString f.outPath + "/";
99+1010+ # Only scripts written for this flake: nix-update with --flake, or a script
1111+ # inside this flake. Packages wrapping nixpkgs or flake-input packages
1212+ # otherwise inherit an updateScript meant for that checkout; those follow
1313+ # flake.lock instead.
1414+ isOurs = s: s == "--flake" || builtins.substring 0 (builtins.stringLength src) s == src;
1515+1616+ entry =
1717+ n: p:
1818+ let
1919+ u = p.passthru.updateScript or null;
2020+ c =
2121+ if builtins.isList u then
2222+ u
2323+ else if builtins.isAttrs u && u ? command then
2424+ (if builtins.isList u.command then u.command else [ u.command ])
2525+ else
2626+ [ u ];
2727+ v = {
2828+ cmd = map toString c;
2929+ pname = p.pname or n;
3030+ version = p.version or "";
3131+ name = p.name or n;
3232+ };
3333+ in
3434+ if u == null || !(builtins.any isOurs v.cmd) then null else builtins.deepSeq v v;
3535+3636+ # Per package tryEval: one package refusing to evaluate on this system must
3737+ # not hide the rest.
3838+ scripts =
3939+ system:
4040+ builtins.mapAttrs (
4141+ n: p:
4242+ let
4343+ r = builtins.tryEval (entry n p);
4444+ in
4545+ if r.success then r.value else null
4646+ ) (f.packages.${system} or { });
4747+4848+ merged = (if host == "x86_64-linux" then { } else scripts "x86_64-linux") // scripts host;
4949+in
5050+builtins.removeAttrs merged (builtins.filter (n: merged.${n} == null) (builtins.attrNames merged))