generated from nix-community/nur-packages-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ci.nix
85 lines (74 loc) · 2.7 KB
/
ci.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
# This file provides all the buildable and cacheable packages and
# package outputs in your package set. These are what gets built by CI,
# so if you correctly mark packages as
#
# - broken (using `meta.broken`),
# - unfree (using `meta.license.free`),
# - platform-specific (using `meta.platform` and `meta.badPlatforms`), and
# - uncacheable (using `allowSubstitutes`)
#
# then your CI will be able to build and cache only those packages for
# which this is possible.
{
platform ? null,
subsetName ? "all",
pkgs ? import <nixpkgs> (if platform != null then {
localSystem = platform;
packageOverrides = pkgs: {
inherit (import <nixpkgs> {}) fetchurl fetchgit fetchzip; # Don't emulate curl and such
};
} else {})
}:
with builtins;
let
inherit (pkgs) lib;
subsets = {
all = p: true;
base = p: !(lib.any (subset: subset p) (attrValues (removeAttrs subsets ["all" "base"])));
hbmame = p: lib.hasInfix "hbmame" (p.name or "");
mame = p: lib.hasInfix "mame" (p.name or "") && !(subsets.hbmame p);
qemu-screamer = p: lib.hasInfix "qemu" (p.name or "") && lib.hasInfix "screamer" (p.name or "");
};
subset = subsets.${subsetName};
isReserved = n: n == "lib" || n == "overlays" || n == "modules";
isDerivation = p: isAttrs p && p ? type && p.type == "derivation";
isBuildable = p: let
licenseFromMeta = p.meta.license or [];
licenseList = if builtins.isList licenseFromMeta then licenseFromMeta else [licenseFromMeta];
in
lib.meta.availableOn pkgs.hostPlatform p &&
!(p.meta.broken or false) &&
builtins.all (license: license.free or true) licenseList &&
(p.meta.knownVulnerabilities or []) == []
;
isCacheable = p: (p.allowSubstitutes or true);
shouldRecurseForDerivations = p: isAttrs p && p.recurseForDerivations or false;
nameValuePair = n: v: { name = n; value = v; };
concatMap = builtins.concatMap or (f: xs: concatLists (map f xs));
flattenPkgs = s:
let
f = p:
if shouldRecurseForDerivations p then flattenPkgs p
else if isDerivation p then [ p ]
else [ ];
in
concatMap f (attrValues s);
outputsOf = p: map (o: p.${o}) p.outputs;
nurAttrs' = import ./default.nix { inherit pkgs; };
nurAttrs = nurAttrs' // lib.optionalAttrs (nurAttrs'?_ciOnly) {
_ciOnly = lib.recurseIntoAttrs nurAttrs'._ciOnly;
};
nurPkgs =
flattenPkgs
(listToAttrs
(map (n: nameValuePair n nurAttrs.${n})
(filter (n: !isReserved n)
(attrNames nurAttrs))));
in
rec {
buildPkgs = filter isBuildable nurPkgs;
cachePkgs' = filter isCacheable buildPkgs;
cachePkgs = filter subset buildPkgs;
buildOutputs = concatMap outputsOf buildPkgs;
cacheOutputs = concatMap outputsOf cachePkgs;
}