-
Notifications
You must be signed in to change notification settings - Fork 0
/
flake.nix
170 lines (151 loc) · 6.05 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
{
description = "A basic flake with a shell";
inputs.nixpkgs.follows = "clicks-server/nixpkgs";
inputs.flake-utils.url = "github:numtide/flake-utils";
inputs.clicks-server.url = "git+ssh://[email protected]/clicksminuteper/nixfiles";
inputs.pnpm2nix.url = "git+ssh://[email protected]/clicksminuteper/pnpm2nix";
inputs.devenv.url = "github:cachix/devenv";
inputs.pnpm2nix.inputs.nixpkgs.follows = "nixpkgs";
outputs = { self, devenv, nixpkgs, flake-utils, clicks-server, pnpm2nix, ... }@inputs:
flake-utils.lib.eachDefaultSystem
(system:
let
pkgs = nixpkgs.legacyPackages.${system};
nodejs = pkgs.nodejs_20;
nodePackages = pkgs.nodePackages_latest;
lib = pkgs.lib;
shellPackages = [ nodejs nodePackages.pnpm pkgs.pkg-config pkgs.fontconfig.dev pkgs.clamav ];
enterShellHook = ''
unset name
export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:${lib.makeSearchPath "/lib/pkgconfig" [
pkgs.pixman
pkgs.cairo.dev
pkgs.libpng.dev
pkgs.gnome2.pango.dev
pkgs.glib.dev
pkgs.harfbuzz.dev
pkgs.freetype.dev
]}
'';
in
rec {
devShells.pure = pkgs.mkShell {
packages = shellPackages;
shellHook = enterShellHook;
};
devShells.default = devenv.lib.mkShell {
inherit inputs pkgs;
modules = [
({ pkgs, config, ... }: {
# This is your devenv configuration
packages = shellPackages;
enterShell = enterShellHook;
services.mongodb = {
enable = true;
package = pkgs.mongodb-6_0;
additionalArgs = [
"--port"
"27017"
"--noauth"
];
};
processes.clamav.exec =
let
clamd_config = pkgs.writeText "clamd.conf" ''
TCPSocket 3310
PidFile /tmp/clamav-nucleus.pid
DatabaseDirectory ${config.env.DEVENV_STATE}/clamav/db
TemporaryDirectory /tmp
Foreground true
'';
freshclam_config = pkgs.writeText "freshclam.conf" ''
DatabaseDirectory ${config.env.DEVENV_STATE}/clamav/db
DatabaseMirror database.clamav.net
'';
in
"mkdir -p $DEVENV_STATE/clamav/db && ${pkgs.clamav}/bin/freshclam --config ${freshclam_config} || true; ${pkgs.clamav}/bin/clamd -c ${clamd_config}";
})
];
};
}) // {
packages.x86_64-linux =
let
pkgs = nixpkgs.legacyPackages.x86_64-linux;
nodejs = pkgs.nodejs_20;
nodePackages = pkgs.nodePackages_latest;
lib = pkgs.lib;
in
rec {
nucleus =
let
packageJSON = (builtins.fromJSON (builtins.readFile ./package.json));
node_modules = lib.pipe
{
src = ./.;
linkDevDependencies = true;
overrides = pnpm2nix.defaultPnpmOverrides.x86_64-linux // {
canvas = (drv: drv.overrideAttrs (oldAttrs: {
nativeBuildInputs = oldAttrs.nativeBuildInputs ++ [ pkgs.pkg-config ];
buildInputs = oldAttrs.buildInputs ++ [
pkgs.pixman
pkgs.cairo.dev
pkgs.libpng.dev
pkgs.gnome2.pango.dev
pkgs.glib.dev
pkgs.harfbuzz.dev
pkgs.freetype.dev
];
}));
"@tensorflow/tfjs-node" = (drv: drv.overrideAttrs (oldAttrs: {
buildInputs = oldAttrs.buildInputs ++ [
pkgs.libtensorflow
];
preBuild = ''
mkdir -p node_modules/@tensorflow/tfjs-node/deps/lib
ln -s ${pkgs.libtensorflow}/lib/libtensorflow.so.2 node_modules/@tensorflow/tfjs-node/deps/lib/libtensorflow.so.2.9.1
'';
}));
};
} [
(pnpm2nix.mkPnpmPackage.x86_64-linux)
(drv: builtins.readFile "${drv}/nix-support/propagated-build-inputs")
(path: "${path}/node_modules")
];
in
pkgs.stdenv.mkDerivation {
pname = "nucleus";
version = packageJSON.version;
src = ./.;
buildInputs = [ nodejs nodePackages.pnpm ];
nativeBuildInputs = [ nodePackages.pnpm nodePackages.typescript pkgs.python3 ];
buildPhase = ''
${pkgs.python3}/bin/python3 ${./scripts/fix-pnpm-bin.py} ${node_modules} ./bin
export PATH=$PATH:./bin
ln -s ${node_modules} node_modules
pnpm run build
'';
installPhase = ''
mkdir -p $out
cp dist $out -r
cp node_modules $out -r
cp bin $out/.bin -r
cp package.json $out
cp LICENSE $out
mkdir -p $out/bin
echo "#!/usr/bin/env bash" > $out/bin/nucleus
echo "cd $out" >> $out/bin/nucleus
echo "export PATH=$PATH:$out/node_modules/.bin" >> $out/bin/nucleus
echo "${packageJSON.scripts.start}" >> $out/bin/nucleus
chmod +x $out/bin/nucleus
'';
};
dockerImage = pkgs.dockerTools.streamLayeredImage {
name = "nucleus";
tag = "latest";
contents = [ nucleus ];
config.Cmd = [ "${nucleus}/bin/nucleus" ];
};
default = nucleus;
};
};
}