-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathflake.nix
91 lines (68 loc) · 2.66 KB
/
flake.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
{
description = "My Nix flake";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-22.11";
unstable.url = "github:nixos/nixpkgs/nixos-unstable";
snowfall-lib = {
url = "github:snowfallorg/lib";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs = inputs:
inputs.snowfall-lib.mkFlake {
inherit inputs;
src = ./.;
outputs-builder = channels:
let
inherit (channels.nixpkgs) lib buildNpmPackage writeShellScript nodejs substitute;
inherit (lib) getExe;
run-node-script = writeShellScript "run-node-script" ''
export NODE_PATH="@nodePath@"
export STATIC_DIR="@staticDir@"
${getExe nodejs} @nodeScript@
'';
in
{
packages = rec {
default = scrumfish-backend;
scrumfish-frontend = buildNpmPackage {
pname = "scrumfish-frontend";
version = inputs.self.sourceInfo.shortRev or "dirty";
src = ./frontend;
npmFlags = [ "--ignore-scripts" ];
npmDepsHash = "sha256-sdh4Y08I6m6IARazTSYznBct0bENb2G6Mfqimway9ns";
postBuild = ''
NO_MODULE_SCRIPT="<script nomodule src=\"\\/scripts\\/bundle.js\"><\\/script>"
MODULE_SCRIPT="<script type=\"module\" src=\"\\/scripts\\/bundle.modern.js\"><\\/script>"
sed -i "s/<\!-- INJECT:SCRIPT -->/''${NO_MODULE_SCRIPT}''${MODULE_SCRIPT}/g" ./public/index.html
'';
installPhase = ''
mv public $out
'';
};
scrumfish-backend = buildNpmPackage {
pname = "scrumfish-backend";
version = inputs.self.sourceInfo.shortRev or "dirty";
src = ./backend;
npmFlags = [ "--ignore-scripts" ];
staticDir = scrumfish-frontend;
npmDepsHash = "sha256-oaXXs98HWlYXlRlMGgUdXeZBU9eoYkXGxAUHdLqBYIk";
dontNpmBuild = true;
installPhase = ''
bin_target=$out/bin/scrumfish
libexec_target=$out/libexec/scrumfish
mkdir -p $(dirname $bin_target)
mkdir -p $libexec_target
mv src $libexec_target/
mv node_modules $libexec_target/
substitute ${run-node-script} $bin_target \
--replace "@nodePath@" "$libexec_target/node_modules" \
--replace "@staticDir@" "$staticDir" \
--replace "@nodeScript@" "$libexec_target/src/index.js"
chmod +x $bin_target
'';
};
};
};
};
}