forked from target/lorri
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.travis.yml.nix
170 lines (159 loc) · 5.87 KB
/
.travis.yml.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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
let
pkgs = import ./nix/nixpkgs.nix;
projectname = "lorri";
cachix-queue-file = "$HOME/push-to-cachix";
cachix-repo = "lorri-test";
# cachix 3 on macOS is broken on travis, see
# https://github.com/cachix/cachix/issues/228#issuecomment-533634704
pushToCachix = { isDarwin }: cachix-queue-file: if isDarwin then [] else [
# read every store path written by previous phases
# from the cachix-queue-file file and push to cachix
''echo "pushing these paths to cachix:"''
''cat ${cachix-queue-file}''
''
if [ -n "$CACHIX_SIGNING_KEY" ]; then
cachix push ${cachix-repo} < ${cachix-queue-file}
fi
''
];
hosts = {
linux = {
os = "linux";
language = "nix";
nix = "2.3.1";
};
macos = {
os = "osx";
#language = "nix";
#nix = "2.3.1";
before_install = [
''wget --retry-connrefused --waitretry=1 -O /tmp/nix-install https://nixos.org/releases/nix/nix-2.3.1/install''
''yes | sh /tmp/nix-install --daemon''
''
if [ -f /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh ]; then
source /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh
elif [ -f ''${TRAVIS_HOME}/.nix-profile/etc/profile.d/nix.sh ]; then
source source ''${TRAVIS_HOME}/.nix-profile/etc/profile.d/nix.sh
fi
''
];
};
};
scripts = {
builds = { isDarwin ? false }: {
name = "nix-build";
script = [
''set -e''
''nix-build''
''nix-env -i ./result''
]
# push build closure to cachix
++ [ ''readlink ./result > ./cachix-file'' ]
++ pushToCachix { inherit isDarwin; } "./cachix-file"
# test lorri self-upgrade
++ [ ''lorri self-upgrade local $(pwd)'' ];
};
lints = { isDarwin ? false }: {
name = "cargo build & linters";
script = [
''set -e''
''nix-build -A allBuildInputs shell.nix > ./shell-inputs''
]
++ pushToCachix { inherit isDarwin; } "./shell-inputs"
++ [
''nix-shell --quiet --arg isDevelopmentShell false --run ci_check''
''cat $(nix-build --quiet ./.travis.yml.nix --no-out-link) > .travis.yml''
''git diff -q ./.travis.yml''
''git diff -q ./Cargo.nix''
''git diff -q ./src/com_target_lorri.rs''
];
};
# cache rust dependency building
cache = name: {
# delete all our own artifacts from the cache dir
# based on https://gist.github.com/jkcclemens/000456ca646bd502cac0dbddcb8fa307
before_cache =
let rmTarget = path: ''rm -rvf "$TRAVIS_BUILD_DIR/target/debug/${path}"'';
in (map rmTarget [
"lib${projectname}.rlib"
# our own binaries/libraries (keep all other deps)
"${projectname}*"
"build/${projectname}-*"
"deps/${projectname}-*"
"deps/lib${projectname}-*"
"incremental/${projectname}-*"
".fingerprint/${projectname}-*"
# build script executable
"incremental/build_script_build-*"
# TODO: the direnv integration test is not deterministic
"direnv-*"
"deps/direnv-*"
"incremental/direnv-*"
]);
# TODO: this might improve things, but we don’t want
# to open another `nix-shell` (because it takes a few seconds)
# ++ [ "cargo clean -p ${projectname}" ];
cache.directories = [ "$HOME/.cargo" "$TRAVIS_BUILD_DIR/target" ];
env = [ "CACHE_NAME=${name}" ];
};
setup-cachix =
{
install = [
# install cachix
''nix-env -iA cachix -f https://cachix.org/api/v1/install''
# setup cachix
''cachix use ${cachix-repo}''
# set cachix into watch-mode (listen for new paths and push in the background)
];
};
macos-cachix-fix = {
# fix on MacOS with cachix v3 (2019-09-20)
# see https://github.com/cachix/cachix/issues/228#issuecomment-531165065
install = [
''echo "trusted-users = root $USER" | sudo tee -a /etc/nix/nix.conf''
''sudo launchctl kickstart -k system/org.nixos.nix-daemon || true''
];
};
};
jobs =
let
# merge the given attributesets;
# lists are concatenated, everything else is an error.
# This is // but with merging of lists (left to right).
mergeShallowConcatLists = pkgs.lib.zipAttrsWith
(_: values:
let first = builtins.head values; in
if builtins.length values == 1 then first else
if builtins.isList first
then builtins.concatLists values
else abort "can only merge lists for now");
in
{
git.depth = false;
language = "minimal";
matrix.include = map mergeShallowConcatLists [
# Verifying lints on macOS and Linux ensures nix-shell works
# on both platforms.
[ hosts.linux scripts.setup-cachix (scripts.lints {}) (scripts.cache "linux") ]
# cachix 3 on macOS is broken on travis, see
# https://github.com/cachix/cachix/issues/228#issuecomment-533634704
[ hosts.macos /*scripts.macos-cachix-fix scripts.setup-cachix*/ (scripts.lints { isDarwin = true; }) (scripts.cache "macos") ]
[ hosts.linux scripts.setup-cachix (scripts.builds {}) ]
# cachix 3 on macOS is broken on travis, see
# https://github.com/cachix/cachix/issues/228#issuecomment-533634704
[ hosts.macos /*scripts.macos-cachix-fix scripts.setup-cachix*/ (scripts.builds { isDarwin = true; }) ]
];
};
in pkgs.runCommand "travis.yml" {
# TODO: move to yj (in newer nixpkgs)
# is a statically compiled golang package,
# so doesn’t incur a dependency on python
buildInputs = [ pkgs.remarshal ];
passAsFile = [ "jobs" ];
jobs = builtins.toJSON jobs;
preferLocalBuild = true;
allowSubstitutes = false;
}
''
remarshal -if json -i $jobsPath -of yaml -o $out --yaml-style ">"
''