-
Notifications
You must be signed in to change notification settings - Fork 1
/
default.nix
68 lines (58 loc) · 1.8 KB
/
default.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
let
pkg =
{ patchelf, stdenv, writeText, zip, exe }:
let
jsMain= writeText "run-exe.js" ''
var spawn = require('child_process').spawn;
process.env['PATH'] =
process.env['PATH'] + ':' + process.env['LAMBDA_TASK_ROOT'];
process.env['LD_LIBRARY_PATH'] = process.env['LAMBDA_TASK_ROOT'];
exports.handler = function(input, context) {
var child = spawn("./exe", []);
child.stdin.write(JSON.stringify(input));
child.stdin.end();
child.on('close', function (code) {
if (code !== 0) { context.done(code, 'Error in process'); }
context.done(null, 'Process complete!');
});
child.on('error', function (err) {
context.done(err, 'Error in process');
});
// Log process stdout and stderr
child.stdout.on('data', function(buf) { console.log(buf.toString()); });
child.stderr.on('data', function(buf) { console.error(buf.toString()); });
};
'';
in
stdenv.mkDerivation {
name = "lambda-zip";
buildCommand = ''
pushd `mktemp -d`
cp ${jsMain} main.js
cp ${exe} exe
mkdir lib
# copy libraries
cp `ldd exe | grep -F '=> /' | awk '{print $3}'` lib/
# copy interpreter
cp `${patchelf}/bin/patchelf --print-interpreter exe` lib/ld.so
chmod +w exe
${patchelf}/bin/patchelf --set-interpreter lib/ld.so exe
${patchelf}/bin/patchelf --set-rpath lib exe
chmod -w exe
${zip}/bin/zip -r -9 out.zip ./
mv out.zip $out
popd
'';
};
in
{ pkgs ? import <nixpkgs> {} }:
let
hs = pkgs.haskell.packages.ghc802;
hsLib = pkgs.haskell.lib;
foo = hsLib.overrideCabal (hs.callPackage ./foo/pkg.nix {}) (old: {
isLibrary = false;
enableSharedLibraries = false;
enableSharedExecutables = false;
});
in
pkgs.callPackage pkg { exe = "${foo}/bin/foo"; }