-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdefault.nix
More file actions
138 lines (122 loc) · 3.93 KB
/
Copy pathdefault.nix
File metadata and controls
138 lines (122 loc) · 3.93 KB
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
let
pkgs = import <nixpkgs> {};
stdenv = pkgs.stdenv;
lib = pkgs.lib;
typhonGit = pkgs.fetchFromGitHub {
owner = "monte-language";
repo = "typhon";
rev = "e87524f";
sha256 = "0nswbi64jgn02gjrl8had7gprvg99gmk8m9xw8mqkylxam22gal1";
};
typhon = import typhonGit {};
# callPackage = pkgs.newScope self;
ps = self: {
inherit lib;
makeMontePackage = src: let
typhonVm = typhon.typhonVm;
mast = typhon.mast;
json = lib.importJSON "${src}/mt.json";
name = json.name;
paths = json.paths;
hasEntrypoint = json ? entrypoint;
entrypoint = if hasEntrypoint then json.entrypoint else "";
entrypointBin = baseNameOf entrypoint;
dependencies = lib.attrNames json.dependencies;
filteredSrc = if builtins.elem "." paths
then src
else builtins.filterSource (path: type:
lib.any (p: lib.hasPrefix p path) paths) src;
# We tie the knot here, but we'll need to collect the dependency search
# paths. We emit and read an $out/nix-support/setup-hook script via
# setupHook, which exports the dependent paths into $MONTE_PATH.
propagatedBuildInputs = map (d: self.${d}) dependencies;
dependencySearchPaths = lib.concatStringsSep " "
(map (x: "-l ${x}") propagatedBuildInputs);
in stdenv.mkDerivation {
inherit name propagatedBuildInputs;
src = filteredSrc;
setupHook = ./monte-setup-hook.sh;
montePaths = dependencySearchPaths;
buildInputs = [ typhonVm mast ];
buildPhase = ''
for srcP in ${lib.concatStringsSep " " paths}; do
for srcF in $(find ./$srcP -name \*.mt); do
destF=''${srcF%%.mt}.mast
${typhonVm}/mt-typhon -l ${mast}/mast ${mast}/loader run montec -mix $srcF $destF
fail=$?
if [ $fail -ne 0 ]; then
exit $fail
fi
done
done
'';
doCheck = hasEntrypoint;
checkPhase = ''
${typhonVm}/mt-typhon ${dependencySearchPaths} -l ${mast}/mast -l . ${mast}/loader test ${entrypointBin}
'';
installPhase = ''
mkdir -p $out
for p in ${lib.concatStringsSep " " paths}; do
cp -r $p $out/$p
done
'' + (if hasEntrypoint then ''
mkdir -p $out/bin
tee $out/bin/${entrypointBin} <<EOF
#!${pkgs.stdenv.shell}
case \$1 in
--test)
shift
OPERATION=test
;;
--bench)
shift
OPERATION=bench
;;
--dot)
shift
OPERATION=dot
;;
--run)
shift
OPERATION=run
;;
*)
OPERATION=run
;;
esac
LOCALPKGPATHS="$MONTE_PATH "
for p in ${lib.concatStringsSep " " paths}; do
LOCALPKGPATHS+=" -l $out/$p"
done
${typhonVm}/mt-typhon ${dependencySearchPaths} \$LOCALPKGPATHS -l ${mast}/mast ${mast}/loader \$OPERATION ${entrypoint} "\$@"
EOF
chmod +x $out/bin/${entrypointBin}
'' else "");
};
mtFromGitHub = s: self.makeMontePackage (pkgs.fetchFromGitHub s);
airbrus = self.mtFromGitHub {
owner = "MostAwesomeDude";
repo = "airbrus";
rev = "6e9bcee";
sha256 = "1r1p03r66zxf59c5q7w6rrpll819vk7hz9sn40v0k8hnmvyip1w8";
};
IRC = self.mtFromGitHub {
owner = "monte-language";
repo = "mt-irc";
rev = "3657b6e";
sha256 = "1gy7fh237s8lfpy582q9ijgark9ybrb0ljwx38cknr13y0k2yj3r";
};
loopingCall = self.mtFromGitHub {
owner = "monte-language";
repo = "mt-loopingCall";
rev = "2c362d6";
sha256 = "142rg4r12z96mvpv4yimwz82ggvfym0lf315wrg44k280mrwp2bz";
};
tokenBucket = self.mtFromGitHub {
owner = "monte-language";
repo = "mt-tokenBucket";
rev = "d286a6c";
sha256 = "05c07fyn9zqj8gm9jacpzjmmfzvjhs582jplcapds85r4hcv41zl";
};
};
in lib.fix ps