-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflake.nix
222 lines (187 loc) · 6.88 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
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
{
description = "automation-service";
inputs = {
# updated 2024-10-20
# # for PureScript 0.15.11
# nixpkgs.url = "nixpkgs/9957cd48326fe8dbd52fdc50dd2502307f188b0d";
# PureScript 0.15.15
nixpkgs.url = "nixpkgs/4eb33fe664af7b41a4c446f87d20c9a0a6321fa3";
flake-utils.url = "github:numtide/flake-utils";
mkSpagoDerivation.url = "github:jeslie0/mkSpagoDerivation";
ps-overlay.url = "github:thomashoneyman/purescript-overlay";
};
outputs = { self, nixpkgs, flake-utils, mkSpagoDerivation, ps-overlay }:
flake-utils.lib.eachSystem ["x86_64-linux"] (system:
# with nixpkgs.legacyPackages.${system};
let
pkgs = import nixpkgs {
inherit system;
overlays = [ mkSpagoDerivation.overlays.default
ps-overlay.overlays.default ];
};
t = pkgs.lib.trivial;
hl = pkgs.haskell.lib;
haskellPackages = pkgs.haskell.packages.ghc964;
name = "automation-service";
node_version = pkgs.nodejs_22;
automation-service-npm-deps =
pkgs.buildNpmPackage {
name = "automation-service-npm-deps";
# prefetch-npm-deps package-lock.json
npmDepsHash = "sha256-X5In3SxY2ANptnAQ4ORNHjCdhkDpnv/j6KKmpSg3Ico=";
src = ./ui;
nodejs = node_version;
# need this for spago and logging
makeCacheWriteable = true;
dontNpmBuild = true;
env = {
PUPPETEER_SKIP_DOWNLOAD = true;
};
installPhase = ''
runHook preInstall
mkdir -p $out/lib
cp -r node_modules $out/lib
runHook postInstall
'';
};
automation-service-ui =
pkgs.mkSpagoDerivation {
spagoYaml = ./ui/spago.yaml;
spagoLock = ./ui/spago.lock;
src = ./ui;
nativeBuildInputs = [
automation-service-npm-deps
node_version
pkgs.chromium
pkgs.esbuild
pkgs.purs
pkgs.spago-unstable
pkgs.which
];
version = "0.1.0";
buildPhase = ''
runHook preBuild
ln -sf ${automation-service-npm-deps}/lib/node_modules ./node_modules
cp node_modules/mocha/mocha.js node_modules/mocha/mocha.css test/browser/
spago bundle -p automation-service-test
# > \Error: Failed to launch the browser process!
# > [342:342:0206/014943.932611:FATAL:setuid_sandbox_host.cc(163)]
# The SUID sandbox helper binary was found, but is not
# configured correctly. Rather than run without
# sandboxing I'm aborting now. You need to make sure
# that /nix/store/499bwk374kxvq6kylfwqgcx70h40zyas-chromium-129.0.6668.100-sandbox/bin/__chromium-suid-sandbox
# is owned by root and has mode 4755.
#
# '--no-sandbox' is the hacky unsafe solution to the above. See e.g.
# https://github.com/flathub/com.visualstudio.code/issues/223
npx mocha-headless-chrome \
-t 60000 \
-e $(which chromium) \
-a no-sandbox \
-a disable-setuid-sandbox \
-a allow-file-access-from-files \
-f test/browser/index.html
# dump out chrome logs to the file chrome_debug.log in
# the current directory
# npx mocha-headless-chrome -t 60000 -p raf -e $(which chromium) -a v=1 -a enable-logging -a user-data-dir=./ -a no-sandbox -a disable-setuid-sandbox -a allow-file-access-from-files -f test/browser/index.html
# cat chrome_debug.log
spago bundle -p automation-service
cd css
npx sass .
cd ..
runHook postBuild
'';
installPhase = ''
runHook preInstall
mkdir -p $out/ui
cp -r . $out/ui/.
runHook postInstall
'';
};
automation-service = devTools:
let
addBuildTools = (t.flip hl.addBuildTools) (devTools ++ [
automation-service-ui
pkgs.zlib
]);
in
haskellPackages.developPackage {
# this prevents CHANGELOG/LICENSE/etc. from being found
# root = lib.sourceFilesBySuffices ./. [ ".cabal" ".hs" ];
root = ./.;
name = name;
returnShellEnv = !(devTools == []);
# https://hydra.nixos.org/build/225575437
# https://github.com/ddellacosta/automation-service/issues/8
overrides = _self: super: {
astro = hl.dontCheck (hl.markUnbroken super.astro);
};
modifier = (t.flip t.pipe) [
addBuildTools
hl.dontHaddock
hl.enableExecutableProfiling
(drv: hl.overrideCabal drv (attrs: {
configureFlags = [
"--ghc-options=-fprof-auto -fno-prof-count-entries"
];
}))
];
};
in {
packages = {
automation-service = automation-service [ ];
automation-service-npm-deps = automation-service-npm-deps;
automation-service-ui = automation-service-ui;
default = pkgs.dockerTools.buildImage {
name = "automation-service";
created = "now";
extraCommands = ''
mkdir ./app
chmod 755 ./app
cp -r ${automation-service-ui}/ui ./app/ui
'';
copyToRoot = pkgs.buildEnv {
name = "image-root";
paths = [
pkgs.bashInteractive
pkgs.busybox
pkgs.coreutils
pkgs.vim
self.packages.${system}.automation-service
];
pathsToLink = [
"/bin"
];
};
config = {
WorkingDir = "/app";
Cmd = [ "/bin/automation-service" ];
Volumes = {
"/app" = {};
};
};
};
};
devShell = automation-service (with haskellPackages; [
cabal-fmt
cabal-install
ghc-events
ghcid
haskell-language-server
hlint
node_version
pkgs.chromium
pkgs.esbuild
pkgs.jq
pkgs.lua
pkgs.mosquitto
pkgs.prefetch-npm-deps
pkgs.purs
pkgs.skopeo # for calculating sha256 of docker image
pkgs.spago-unstable
pkgs.watchexec
stylish-haskell
# threadscope # marked as broken :-(
]);
});
}