forked from zhaofengli/attic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ci-installer.nix
82 lines (72 loc) · 2.33 KB
/
ci-installer.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
# Generates a script to bootstrap the Attic client with a substituter for
# CI usage. Will be simplier when Attic is in cache.nixos.org.
{ self
, writeText
, writeScript
, substituter ? "https://staging.attic.rs/attic-ci"
, trustedPublicKey ? "attic-ci:U5Sey4mUxwBXM3iFapmP0/ogODXywKLRNgRPQpEXxbo="
}:
let
cacheNixosOrg = "https://cache.nixos.org";
cacheNixosOrgKey = "cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY=";
bootstrapHeader = ''
let
maybeStorePath = if builtins ? langVersion && builtins.lessThan 1 builtins.langVersion
then builtins.storePath
else x: x;
mkFakeDerivation = attrs: outputs:
let
outputNames = builtins.attrNames outputs;
common = attrs // outputsSet //
{ type = "derivation";
outputs = outputNames;
all = outputsList;
};
outputToAttrListElement = outputName:
{ name = outputName;
value = common // {
inherit outputName;
outPath = maybeStorePath (builtins.getAttr outputName outputs);
drvPath = maybeStorePath (builtins.getAttr outputName outputs);
};
};
outputsList = map outputToAttrListElement outputNames;
outputsSet = builtins.listToAttrs outputsList;
in outputsSet;
in
'';
makeBootstrap = system: let
package =
if system == "x86_64-linux" then self.packages.${system}.attic-client-static
else self.packages.${system}.attic-client;
in ''
"${system}" = (mkFakeDerivation {
name = "${package.name}";
system = "${system}";
} {
out = "${package.out}";
}).out;
'';
bootstrapExpr = ''
{ system ? builtins.currentSystem }:
${bootstrapHeader}
{
${makeBootstrap "x86_64-linux"}
${makeBootstrap "aarch64-linux"}
${makeBootstrap "x86_64-darwin"}
${makeBootstrap "aarch64-darwin"}
}.''${system}
'';
bootstrapScript = writeScript "install-attic-ci.sh" ''
#!/usr/bin/env bash
set -euo pipefail
expr=$(mktemp)
cleanup() {
rm -f "$expr"
}
cat >"$expr" <<'EOF'
${bootstrapExpr}
EOF
nix-env --substituters "${substituter} ${cacheNixosOrg}" --trusted-public-keys "${trustedPublicKey} ${cacheNixosOrgKey}" -if "$expr"
'';
in bootstrapScript