generated from valmisson/tauri-app-template
/
parse_dependencies.nix
300 lines (296 loc) · 11.1 KB
/
parse_dependencies.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
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
#
# summary
# this file exports a function that does a few basic things
# 1. parses the nix.toml file and return nix package objects
# 2. exports some basic information about the package dependencies to a json file
# 3. returns a "main" object that has all the basic builtin or builtin-like functionality
(rec {
#
# create a standard library for convienience
#
frozenStd = (builtins.import
(builtins.fetchTarball
({url="https://github.com/NixOS/nixpkgs/archive/8917ffe7232e1e9db23ec9405248fd1944d0b36f.tar.gz";})
)
({})
);
main = (frozenStd.lib.mergeAttrs
(frozenStd.lib.mergeAttrs
(frozenStd.buildPackages) # <- for fetchFromGitHub, installShellFiles, getAttrFromPath, etc
(frozenStd.lib.mergeAttrs
({ stdenv = frozenStd.stdenv; })
(frozenStd.lib) # <- for mergeAttrs, optionals, getAttrFromPath, etc
)
)
(builtins) # <- for import, fetchTarball, etc
);
#
# pull info from the config files
#
nixSettings = (main.fromTOML
(main.readFile
(main.getEnv
"__FORNIX_NIX_SETTINGS_PATH"
)
)
);
#
# load the nix.toml cause were going to extract basically everything from there
#
packageToml = (main.fromTOML
(main.readFile
(main.getEnv
("__FORNIX_NIX_PACKAGES_FILE_PATH")
)
)
);
#
# load the store with all the packages, and load it with the config
#
defaultFrom = (main.fetchTarball
({url="https://github.com/NixOS/nixpkgs/archive/${nixSettings.defaultFrom}.tar.gz";})
);
mainPackages = (main.import
(defaultFrom)
({ config = nixSettings.config;})
);
packagesForThisMachine = (main.filter
(eachPackage:
(main.all
# if all are true
(x: x)
(main.optionals
# if package depends on something
(main.hasAttr "onlyIf" eachPackage)
# basically convert something like ["stdev", "isLinux"] to main.stdenv.isLinux
(main.map
(eachCondition:
(main.getAttrFromPath
(eachCondition)
(main)
)
)
(eachPackage.onlyIf)
)
)
)
)
(packageToml.packages)
);
#
# reorganize the list of packages from:
# [ { load: "blah", from:"blah-hash" }, ... ]
# into a list like:
# [ { name: "blah", commitHash:"blah-hash", source: (*an object*) }, ... ]
#
tomlPackagesWithSources = (main.map
(each:
({
name = (main.concatMapStringsSep
(".")
(each: each)
(each.load)
);
commitHash = each.from;
asNativeBuildInput = (
(main.hasAttr
("asNativeBuildInput")
(each)
)
&&
each.asNativeBuildInput
);
value =
# if it says where (e.g. from)
if
(main.hasAttr
("from")
(each)
)
# then load it from that place
then
(rec {
package = (main.getAttrFromPath
(each.load)
(main.import
# if its a string, assume its a nixpkg commit hash
(
if
(main.isString
(each.from)
)
then
(main.fetchTarball
({url="https://github.com/NixOS/nixpkgs/archive/${each.from}.tar.gz";})
)
# otherwise assume its the details for a github repo
else
(main.fetchGit
(each.from.fetchGit)
)
)
(
if
(
(main.isString
(each.from)
)
||
(!main.hasAttr
("options")
(each.from)
)
)
then
({})
# otherwise assume its the details for a github repo
else
(each.from.options)
)
)
);
return = (
if
(main.hasAttr
("override")
(each)
)
then
(package.override
(each.override)
)
else
package
);
}.return)
# otherwise just default to getting it from mainPackages
else
(main.getAttrFromPath
(each.load)
(mainPackages)
)
;
})
)
(packagesForThisMachine)
);
listedDepedencyPackages = (main.listToAttrs
(tomlPackagesWithSources)
);
packages = (main.mergeAttrs
mainPackages
listedDepedencyPackages
);
tomlAndBuiltinPackagesWithSources = (tomlPackagesWithSources ++
[
{
name = "glib";
value = packages.glib;
}
{
name = "cc";
value = main.stdenv.cc.cc;
}
]
);
buildInputs = (main.map
(each: each.value)
(main.filter
(each: !each.asNativeBuildInput)
(tomlPackagesWithSources)
)
);
nativeBuildInputs = (main.map
(each: each.value)
(main.filter
(each: each.asNativeBuildInput)
(tomlPackagesWithSources)
)
);
depedencyPackages = (main.listToAttrs
(tomlAndBuiltinPackagesWithSources)
);
packagePathsAsJson = (main.toJSON
({
packagePathFor = depedencyPackages;
libPathFor = (main.listToAttrs
(main.map
(each:
({
name = each.name;
value = "${main.makeLibraryPath [ each.value ]}";
})
)
(tomlAndBuiltinPackagesWithSources)
)
);
})
);
return = (main.mergeAttrs
(main)
({
nixPath = "${defaultFrom}";
packages = packages;
project = {
buildInputs = buildInputs;
nativeBuildInputs = nativeBuildInputs;
protectHomeShellCode = ''
#
# find the fornix_core
#
path_to_fornix_core=""
file_name="settings/fornix_core"
folder_to_look_in="$PWD"
while :
do
# check if file exists
if [ -f "$folder_to_look_in/$file_name" ]
then
path_to_fornix_core="$folder_to_look_in/$file_name"
break
else
if [ "$folder_to_look_in" = "/" ]
then
break
else
folder_to_look_in="$(dirname "$folder_to_look_in")"
fi
fi
done
if [ -z "$path_to_fornix_core" ]
then
#
# what to do if file never found
#
echo "Im part of parse_dependencies.nix, a script running with a pwd of:$PWD"
echo "Im looking for settings/fornix_core in a parent folder"
echo "Im exiting now because I wasnt able to find it"
echo "thats all the information I have"
exit
fi
export FORNIX_NEXT_RUN_DONT_DO_MANUAL_START="true"
. "$path_to_fornix_core"
# ensure that the folder exists
mkdir -p "$(dirname "$__FORNIX_NIX_PATH_EXPORT_FILE")"
echo ${main.escapeShellArg (packagePathsAsJson)} > "$__FORNIX_NIX_PATH_EXPORT_FILE"
if [ -n "$FORNIX_HOME" ]
then
# we don't want to give nix or other apps our home folder
if ! [ "$HOME" = "$FORNIX_HOME" ]
then
if [ "$FORNIX_DEBUG" = "true" ]; then
echo "replacing: HOME with FORNIX_HOME"
fi
mkdir -p "$FORNIX_HOME/.cache/"
ln -s "$HOME/.cache/nix/" "$FORNIX_HOME/.cache/" &>/dev/null
# so make the home folder the same as the project folder
export HOME="$FORNIX_HOME"
# make it explicit which nixpkgs we're using
export NIX_PATH="nixpkgs=${defaultFrom}:."
fi
fi
'';
};
})
);
}).return