-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnode.nix
58 lines (56 loc) · 1.71 KB
/
node.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
{ flake-utils, gitignore, devshell }: { nixpkgs, dir, name, version }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs {
inherit system;
overlays = [
devshell.overlays.default
];
};
nodejs = pkgs.nodejs;
node2nixOutput = import (dir + /default.nix) { inherit pkgs nodejs system; };
# NOTE: may want to try https://github.com/svanderburg/node2nix/issues/301 to limit rebuilds
nodeDeps = node2nixOutput.nodeDependencies;
app = pkgs.stdenv.mkDerivation {
inherit name version;
src = gitignore.lib.gitignoreSource dir;
buildInputs = [ nodejs ];
buildPhase = ''
runHook preBuild
ln -sf ${nodeDeps}/lib/node_modules ./node_modules
export HOME=$(pwd)
export PATH="${nodeDeps}/bin:$PATH"
echo $PATH
npm run build
runHook postBuild
'';
installPhase = ''
runHook preInstall
# Note: you need some sort of `mkdir` on $out for any of the following commands to work
mkdir -p $out/bin
cp package.json $out/package.json
cp -r dist $out/dist
ln -sf ${nodeDeps}/lib/node_modules $out/node_modules
cp dist/index.js $out/bin/apollo-server
chmod a+x $out/bin/apollo-server
runHook postInstall
'';
};
in
with pkgs; {
packages.default = writeShellScriptBin "entrypoint" ''
${nodejs-slim}/bin/node ${app}/bin/apollo-server
'';
devShells.default = pkgs.devshell.mkShell {
packages = [ nodejs node2nix ];
commands = [
{
name = "update-deps";
help = "Update nix deps";
command = ''
node2nix;
'';
}
];
};
})