This repository has no description
1.7 kB
50 lines
1# attr -> { cmd, pname, version, name } for every flake package with an
2# updateScript written for this flake. One getFlake call, so the source path
3# and both package sets come from the same snapshot of the (possibly dirty)
4# tree. Host entries win; x86_64-linux fills in linux-only packages.
5{ flake, host }:
6let
7 f = builtins.getFlake flake;
8 src = toString f.outPath + "/";
9
10 # Only scripts written for this flake: nix-update with --flake, or a script
11 # inside this flake. Packages wrapping nixpkgs or flake-input packages
12 # otherwise inherit an updateScript meant for that checkout; those follow
13 # flake.lock instead.
14 isOurs = s: s == "--flake" || builtins.substring 0 (builtins.stringLength src) s == src;
15
16 entry =
17 n: p:
18 let
19 u = p.passthru.updateScript or null;
20 c =
21 if builtins.isList u then
22 u
23 else if builtins.isAttrs u && u ? command then
24 (if builtins.isList u.command then u.command else [ u.command ])
25 else
26 [ u ];
27 v = {
28 cmd = map toString c;
29 pname = p.pname or n;
30 version = p.version or "";
31 name = p.name or n;
32 };
33 in
34 if u == null || !(builtins.any isOurs v.cmd) then null else builtins.deepSeq v v;
35
36 # Per package tryEval: one package refusing to evaluate on this system must
37 # not hide the rest.
38 scripts =
39 system:
40 builtins.mapAttrs (
41 n: p:
42 let
43 r = builtins.tryEval (entry n p);
44 in
45 if r.success then r.value else null
46 ) (f.packages.${system} or { });
47
48 merged = (if host == "x86_64-linux" then { } else scripts "x86_64-linux") // scripts host;
49in
50builtins.removeAttrs merged (builtins.filter (n: merged.${n} == null) (builtins.attrNames merged))