-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebfiles.nix
227 lines (185 loc) · 5.88 KB
/
webfiles.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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
{ stdenv
, pkgs
, url
, nixpkgs
, self
, system
, c2vi-config
, vicConfig
, getTarballClosure
, getVicorinix
, ... }:
let
closure-x86_64-linux = getTarballClosure pkgs "x86_64-linux";
closure-aarch64-linux = getTarballClosure pkgs "aarch64-linux";
#victorinix-l = let pkgs = nixpkgs.legacyPackages.x86_64-linux; in pkgs.rustPlatform.buildRustPackage rec {
victorinix-l = getVicorinix pkgs "x86_64-linux" "l" "sha256-0kAb+sieN+Ipnr8E3CS3oy+9+4qvUQU3rXrhpJyGTIM=";
victorinix-la = getVicorinix pkgs "aarch64-multiplatform" "la" "sha256-eB/+tcI5+pWSMq2fIKI3qPcuRKOg0r1C3/wm999G8CE=";
victorinix-s = pkgs.writeTextFile {
name = "victorinix-s";
executable = true;
text = ''
#!/bin/sh
# This is a quick script that downloads the correct victorinix binary to ./vic
# Programms needed in $PATH or /bin:
# - sh (at /bin/sh)
# - uname
# - chmod
# - wget or curl or python with urllib
##########################
# check for needed things
# add /bin to path, so that even if there is no path specified we can run if /bin/uname and /bin/chmod exist
PATH=$PATH:/bin
dev_null_replacement=$(command -v uname)
if [[ "$?" == "0" ]]; then echo uname found; else echo uname not found; exit 1; fi
dev_null_replacement=$(command -v chmod)
if [[ "$?" == "0" ]]; then echo chmod found; else echo chmod not found; exit 1; fi
##########################
# determine right executable
arch=$(uname -m)
kernel=$(uname -s)
exepath=""
if [[ "$arch" == "x86_64" ]] && [[ "$kernel" == "Linux" ]]; then
exepath="l/vic"
elif [[ "$arch" == "aarch64" ]] && [[ "$kernel" == "Linux" ]]; then
exepath="la/vic"
else
echo "system (kernel: $kernel, arch: $arch) not supported"
exit 1
fi
##########################
# get executable
echo downloading victorinix binary at ${url}/$exepath
function download_with_python(){
python=$1
$python -c '
# i hate you python with your indents!!!
from urllib.request import urlopen
import sys
with urlopen("${url}" + "/" + sys.argv[1]) as response:
body = response.read()
f = open("./vic", "wb")
f.write(body)
f.close()
' $exepath
}
function try_wget(){
echo do we have wget??
dev_null_replacement=$(command -v wget)
found=$?
if [[ "$found" == "0" ]]; then
wget ${url}/$exepath
else
echo wget not found
fi
return $found
}
function try_curl(){
echo do we have curl??
dev_null_replacement=$(command -v curl)
found=$?
if [[ "$found" == "0" ]]; then
curl ${url}/$exepath -o ./vic
else
echo curl not found
fi
return $found
}
function try_python(){
echo do we have python??
dev_null_replacement=$(command -v python)
found=$?
if [[ "$found" == "0" ]]; then
download_with_python python
else
echo python not found
fi
return $found
}
function try_python3(){
echo do we have python3??
dev_null_replacement=$(command -v python3)
found=$?
if [[ "$found" == "0" ]]; then
download_with_python python3
else
echo python3 not found
fi
return $found
}
function try_python2(){
echo do we have python2??
dev_null_replacement=$(command -v python2)
found=$?
if [[ "$found" == "0" ]]; then
download_with_python python2
else
echo python2 not found
fi
return $found
}
function android_init_pre_download(){
cd /data/local
}
function are_we_on_android(){
dev_null_replacement=$(command -v getprop)
if [[ "$?" == "0" ]]; then
dev_null_replacement=$(getprop ro.build.version.release)
if [[ "$?" == "0" ]]; then
return 0
fi
fi
return 1
}
# pre download platform specific init
are_we_on_android && android_init_pre_download
# download vic
try_wget || try_curl || try_python || try_python3 || try_python2 || (echo ERROR: out of ways to download the victor binary; exit 1)
##########################
# make it executable
chmod +x ./vic
# on android spawn a new sub-process, to keep the PWD at /data/local
are_we_on_android && echo on ANDROID HISTORY LOST because we are in a sub-process, to keep the cd to /data/local && sh
'';
};
webfilesBuildPhase = closure: ''
mkdir -p tar-tmp
mkdir -p tar-tmp/nix
while read path
do
echo path: $path
mkdir -p tar-tmp$path
cp -r --no-preserve=mode,ownership $path/* tar-tmp$path
done < ${closure.info}/store-paths
cp ${closure.proot}/bin/proot tar-tmp/nix/proot
echo -en '${closure.nix}/bin/' > tar-tmp/nix/nix-path
echo -en '${closure.busybox}/bin/' > tar-tmp/nix/busybox-path
echo -en '${closure.cacert}/bin/' > tar-tmp/nix/cacert-path
echo iiiiiiiiiiiiiiiii
ls tar-tmp/nix
echo iiiiiiiiiiiiiiiii
tar -z -c -f $out/tars/${closure.system}.tar.gz -C tar-tmp --mode="a+rwx" .
rm -rf tar-tmp
'';
in
stdenv.mkDerivation {
name = "victorinix-webfiles";
dontUnpack = true;
# so that /bin/sh does not get patched to a nix store path in victorinix-s
dontPatchShebangs = true;
buildPhase = ''
mkdir -p $out
mkdir -p $out/l
mkdir -p $out/la
cp ${victorinix-s} $out/s
cp ${victorinix-l}/bin/victorinix $out/l/vic
cp ${victorinix-la}/bin/victorinix $out/la/vic
mkdir -p $out/tars
# make tars
'' + webfilesBuildPhase closure-x86_64-linux
+ webfilesBuildPhase closure-aarch64-linux
;
#${pkgs.gnutar}/bin/tar -C ./nix-store -czf $out/tars/x86_64-linux.tar.gz .
nativeBuildInputs = [
];
}