-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpackages-with-update-script.nix
98 lines (86 loc) · 3.3 KB
/
packages-with-update-script.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
let
pkgs =
(import (fetchTarball "https://github.com/SaumonNet/proxmox-nixos/archive/main.tar.gz"))
.packages.x86_64-linux;
lib = (import (fetchTarball "https://github.com/NixOS/nixpkgs/archive/master.tar.gz") { }).lib;
in
# code in the following let block was copied from nixos/nixpkgs under
# the MIT License
let
# Remove duplicate elements from the list based on some extracted value. O(n^2) complexity.
nubOn =
f: list:
if list == [ ] then
[ ]
else
let
x = lib.head list;
xs = lib.filter (p: f x != f p) (lib.drop 1 list);
in
[ x ] ++ nubOn f xs;
/*
Recursively find all packages (derivations) in `pkgs` matching `cond` predicate.
Type: packagesWithPath :: AttrPath → (AttrPath → derivation → bool) → AttrSet → List<AttrSet{attrPath :: str; package :: derivation; }>
AttrPath :: [str]
The packages will be returned as a list of named pairs comprising of:
- attrPath: stringified attribute path (based on `rootPath`)
- package: corresponding derivation
*/
packagesWithPath =
rootPath: cond: pkgs:
let
packagesWithPathInner =
path: pathContent:
let
result = builtins.tryEval pathContent;
somewhatUniqueRepresentant =
{ package, attrPath }:
{
inherit (package) updateScript;
# Some updaters use the same `updateScript` value for all packages.
# Also compare `meta.description`.
position = package.meta.position or null;
# We cannot always use `meta.position` since it might not be available
# or it might be shared among multiple packages.
};
dedupResults = lst: nubOn somewhatUniqueRepresentant (lib.concatLists lst);
in
if result.success then
let
evaluatedPathContent = result.value;
in
if lib.isDerivation evaluatedPathContent then
lib.optional (cond path evaluatedPathContent) {
attrPath = lib.concatStringsSep "." path;
package = evaluatedPathContent;
}
else if lib.isAttrs evaluatedPathContent then
# If user explicitly points to an attrSet or it is marked for recursion, we recur.
if
path == rootPath
|| evaluatedPathContent.recurseForDerivations or false
|| evaluatedPathContent.recurseForRelease or false
then
dedupResults (
lib.mapAttrsToList (name: elem: packagesWithPathInner (path ++ [ name ]) elem) evaluatedPathContent
)
else
[ ]
else
[ ]
else
[ ];
in
packagesWithPathInner rootPath pkgs;
# Recursively find all packages (derivations) in `pkgs` matching `cond` predicate.
packagesWith = packagesWithPath [ ];
# Recursively find all packages in `pkgs` with updateScript matching given predicate.
packagesWithUpdateScriptMatchingPredicate =
cond: packagesWith (path: pkg: builtins.hasAttr "updateScript" pkg && cond path pkg);
in
let
allPackagesWithUpdateScript = packagesWithUpdateScriptMatchingPredicate (
_path: _package: true
) pkgs;
in
lib.concatMapStrings (p: "${p.attrPath} 0 1\n") allPackagesWithUpdateScript