forked from dfinity/ic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrepo-deps.nix
54 lines (49 loc) · 1.56 KB
/
repo-deps.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
# See the ./repo-deps script in this directory for a motivation for and
# documentation of this file.
{ file }:
let
repoRoot = toString ../.;
hasPrefix = pref: str:
builtins.substring 0 (builtins.stringLength pref) str == pref;
hasSuffix = suffix: content:
let
lenContent = builtins.stringLength content;
lenSuffix = builtins.stringLength suffix;
in
lenContent >= lenSuffix && builtins.substring (lenContent - lenSuffix) lenContent content == suffix;
traceIfRepoFile = path: x:
let
pathStr = toString path;
in
if hasPrefix repoRoot pathStr
then builtins.trace (builtins.substring (builtins.stringLength repoRoot + 1) (builtins.stringLength pathStr) pathStr) x
else x;
overrides = {
import = path: overrides.scopedImport overrides path;
scopedImport = attrs: path:
let
realPath =
if hasSuffix ".nix" path
then path
else path + "/default.nix";
in
traceIfRepoFile realPath (builtins.scopedImport (overrides // attrs) path);
builtins = builtins // {
readFile = file: traceIfRepoFile file (builtins.readFile file);
readDir = dir: traceIfRepoFile dir (builtins.readDir dir);
path = args: traceIfRepoFile args.path (builtins.path args);
fetchGit = args:
if builtins.isPath args
then traceIfRepoFile args (builtins.fetchGit args)
else builtins.fetchGit args;
};
};
imported =
let
raw = overrides.scopedImport overrides file;
in
if builtins.isFunction raw
then raw { }
else raw;
in
imported