-
Notifications
You must be signed in to change notification settings - Fork 2
/
default.nix
143 lines (133 loc) · 4.7 KB
/
default.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
{ pkgs ? import <nixpkgs> { config = {}; overlays = []; } }:
rec {
base = {
pname = "styx";
version = "0.0.10";
vendorHash = "sha256-Enhe29MNy+Nqim7OelHl5gv+vcrHSx51FzGgs/6Hy4A=";
src = pkgs.lib.sourceByRegex ./. [
"^go\\.(mod|sum)$"
"^(ci|cmd|common|daemon|erofs|manifester|pb|keys|tests)($|/.*)"
];
subPackages = [ "cmd/styx" ];
doCheck = false;
ldflags = baseLdFlags;
};
baseLdFlags = [
"-X github.com/dnr/styx/common.NixBin=${pkgs.nix}/bin/nix"
"-X github.com/dnr/styx/common.XzBin=${pkgs.xz}/bin/xz"
"-X github.com/dnr/styx/common.Version=${base.version}"
];
daemonLdFlags = baseLdFlags ++ [
"-X github.com/dnr/styx/common.GzipBin=${pkgs.gzip}/bin/gzip"
"-X github.com/dnr/styx/common.FilefragBin=${pkgs.e2fsprogs}/bin/filefrag"
];
staticLdFlags = [
# "-s" "-w" # only saves 3.6% of image size
"-X github.com/dnr/styx/common.XzBin=${xzStaticBin}/bin/xz"
# GzipBin is not used by manifester or differ, only local
"-X github.com/dnr/styx/common.Version=${base.version}"
];
styx-local = pkgs.buildGoModule (base // {
ldflags = daemonLdFlags;
});
styx-lambda = pkgs.buildGoModule (base // {
tags = [ "lambda.norpc" ];
ldflags = staticLdFlags;
});
styx-test = pkgs.buildGoModule (base // {
pname = "styxtest";
buildPhase = ''
go test -ldflags="$ldflags" -c -o styxtest ./tests
'';
installPhase = ''
mkdir -p $out/bin $out/keys
install styxtest $out/bin/
cp keys/testsuite* $out/keys/
'';
ldflags = daemonLdFlags ++ [
"-X github.com/dnr/styx/tests.TestdataDir=${testdata}"
];
});
testdata = let
paths = [
"cd1nbildgzzfryjg82njnn36i4ynyf8h-bash-interactive-5.1-p16-man"
"8vyj9c6g424mz0v3kvzkskhvzhwj6288-bash-interactive-5.2-p15-man"
"3a7xq2qhxw2r7naqmc53akmx7yvz0mkf-less-is-more.patch"
"v35ysx9k1ln4c6r7lj74204ss4bw7l5l-openssl-3.0.12-man"
"xd96wmj058ky40aywv72z63vdw9yzzzb-openssl-3.0.12-man"
"1fka6ngkrlmqkhix0gnnb19z58sr0yma-openssl-3.0.13-man"
"z2waz77lsh4pxs0jxgmpf16s7a3g7b7v-openssl-3.0.13-man"
"53qwclnym7a6vzs937jjmsfqxlxlsf2y-opusfile-0.12"
"kcyrz2y8si9ry5p8qkmj0gp41n01sa1y-opusfile-0.12"
"qa22bifihaxyvn6q2a6w9m0nklqrk9wh-opusfile-0.12"
"xpq4yhadyhazkcsggmqd7rsgvxb3kjy4-gnugrep-3.11"
"kbi7qf642gsxiv51yqank8bnx39w3crd-calf-0.90.3" # 18 MB
"d30xd6x3669hg2a6xwjb1r3nb9a99sw2-openblas-0.3.27" # 27 MB
];
hash = "sha256-eSl0bAOueksPX4szbeoqLa3OfUbNtxxOGvfHeoymhmY=";
in pkgs.stdenv.mkDerivation {
name = "styx-test-data";
builder = pkgs.writeShellScript "build-testdata" ''
set -e; . .attrs.sh
PATH=${pkgs.coreutils}/bin:${pkgs.gnused}/bin:${pkgs.wget}/bin:$PATH
out=''${outputs[out]}
mkdir $out && cd $out
${pkgs.lib.concatMapStringsSep "\n" (p: ''
p=${p}; ni=''${p%%-*}.narinfo
wget -nv -x -nH https://cache.nixos.org/$ni
wget -nv -x -nH https://cache.nixos.org/$(sed -ne '/URL/s/.* //p' $ni)
'') paths}
'';
__structuredAttrs = true; # needed for unsafeDiscardReferences
# this is pure data just for tests, even if references happen to match
unsafeDiscardReferences.out = true;
outputHashMode = "recursive";
outputHash = hash;
};
# built by deploy-ci, for heavy CI worker on EC2
charon = pkgs.buildGoModule (base // {
pname = "charon";
subPackages = [ "cmd/charon" ];
});
# for light CI worker on non-AWS server (dd5):
charon-light = pkgs.buildGoModule (base // {
pname = "charon";
subPackages = [ "cmd/charon" ];
ldflags = [ ];
});
# Use static binaries and take only the main binaries to make the image as
# small as possible:
xzStaticBin = pkgs.stdenv.mkDerivation {
name = "xz-binonly";
src = pkgs.pkgsStatic.xz;
installPhase = "mkdir -p $out/bin && cp $src/bin/xz $out/bin/";
};
# for styx lambda manifester and chunk differ:
styx-lambda-image = pkgs.dockerTools.streamLayeredImage {
name = "lambda";
# TODO: can we make it run on arm?
# architecture = "arm64";
contents = [
pkgs.cacert
];
config = {
User = "1000:1000";
Entrypoint = [ "${styx-lambda}/bin/styx" ];
};
};
# for light CI worker on non-AWS server (dd5):
charon-image = pkgs.dockerTools.streamLayeredImage {
name = "charon-worker-light";
contents = [
pkgs.cacert
];
config = {
User = "1000:1000";
Entrypoint = [ "${charon-light}/bin/charon" ];
};
};
# helper to initialize styx with "test-1" params
StyxInitTest1 = pkgs.writeShellScriptBin "StyxInitTest1" ''
styx init --params=https://styx-1.s3.amazonaws.com/params/test-1 --styx_pubkey=styx-test-1:bmMrKgN5yF3dGgOI67TZSfLts5IQHwdrOCZ7XHcaN+w=
'';
}