blob: 49b72d0ca84877cd05ed03b9fd63dc06ee9a411b [file] [log] [blame]
Skyler Grey453b9992023-03-05 05:48:42 +00001{
2 description = "A basic flake with a shell";
TheCodedProf4a7c25d2023-06-07 17:09:45 -04003 inputs.nixpkgs.follows = "clicks-server/nixpkgs";
Skyler Grey453b9992023-03-05 05:48:42 +00004 inputs.flake-utils.url = "github:numtide/flake-utils";
Skyler Grey9b6992a2023-06-09 12:46:05 +02005 inputs.clicks-server.url = "git+ssh://git@github.com/clicksminuteper/nixfiles";
6 inputs.pnpm2nix.url = "git+ssh://git@github.com/clicksminuteper/pnpm2nix";
Skyler Grey8e2df922023-06-14 14:02:31 +02007 inputs.devenv.url = "github:cachix/devenv";
Skyler Grey453b9992023-03-05 05:48:42 +00008
TheCodedProf4a7c25d2023-06-07 17:09:45 -04009 inputs.pnpm2nix.inputs.nixpkgs.follows = "nixpkgs";
10
Skyler Grey8e2df922023-06-14 14:02:31 +020011 outputs = { self, devenv, nixpkgs, flake-utils, clicks-server, pnpm2nix, ... }@inputs:
TheCodedProf30219372023-06-11 14:15:30 -040012 flake-utils.lib.eachDefaultSystem
13 (system:
14 let
15 pkgs = nixpkgs.legacyPackages.${system};
16 nodejs = pkgs.nodejs_20;
17 nodePackages = pkgs.nodePackages_latest;
18 lib = pkgs.lib;
19 in
20 rec {
Skyler Grey8e2df922023-06-14 14:02:31 +020021 devShells.default = devenv.lib.mkShell {
22 inherit inputs pkgs;
23 modules = [
24 ({ pkgs, config, ... }: {
25 # This is your devenv configuration
26 packages = [ nodejs nodePackages.pnpm pkgs.pkg-config pkgs.fontconfig.dev pkgs.clamav ];
27
28 enterShell = ''
29 unset name
30 export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:${lib.makeSearchPath "/lib/pkgconfig" [
31 pkgs.pixman
32 pkgs.cairo.dev
33 pkgs.libpng.dev
34 pkgs.gnome2.pango.dev
35 pkgs.glib.dev
36 pkgs.harfbuzz.dev
37 pkgs.freetype.dev
38 ]}
39 '';
40
41 services.mongodb = {
42 enable = true;
43 package = pkgs.mongodb-6_0;
44 additionalArgs = [
45 "--port"
46 "27017"
47 "--noauth"
48 ];
49 };
50
Skyler Greydf6ff252023-06-14 18:52:03 +020051 processes.clamav.exec =
52 let
Skyler Grey8e2df922023-06-14 14:02:31 +020053 clamd_config = pkgs.writeText "clamd.conf" ''
Skyler Greydf6ff252023-06-14 18:52:03 +020054 TCPSocket 3310
55 PidFile /tmp/clamav-nucleus.pid
56 DatabaseDirectory ${config.env.DEVENV_STATE}/clamav/db
57 TemporaryDirectory /tmp
58 Foreground true
Skyler Grey8e2df922023-06-14 14:02:31 +020059 '';
60 freshclam_config = pkgs.writeText "freshclam.conf" ''
Skyler Greydf6ff252023-06-14 18:52:03 +020061 DatabaseDirectory ${config.env.DEVENV_STATE}/clamav/db
62 DatabaseMirror database.clamav.net
Skyler Grey8e2df922023-06-14 14:02:31 +020063 '';
Skyler Greydf6ff252023-06-14 18:52:03 +020064 in
65 "mkdir -p $DEVENV_STATE/clamav/db && ${pkgs.clamav}/bin/freshclam --config ${freshclam_config} || true; ${pkgs.clamav}/bin/clamd -c ${clamd_config}";
Skyler Grey8e2df922023-06-14 14:02:31 +020066 })
67 ];
TheCodedProf30219372023-06-11 14:15:30 -040068 };
69 }) // {
70 packages.x86_64-linux =
71 let
72 pkgs = nixpkgs.legacyPackages.x86_64-linux;
73 nodejs = pkgs.nodejs_20;
74 nodePackages = pkgs.nodePackages_latest;
75 lib = pkgs.lib;
76 in
77 rec {
TheCodedProf30219372023-06-11 14:15:30 -040078 nucleus =
79 let
80 packageJSON = (builtins.fromJSON (builtins.readFile ./package.json));
Skyler Greydf6ff252023-06-14 18:52:03 +020081 node_modules = lib.pipe
82 {
83 src = ./.;
84 linkDevDependencies = true;
85 overrides = pnpm2nix.defaultPnpmOverrides.x86_64-linux // {
86 canvas = (drv: drv.overrideAttrs (oldAttrs: {
87 nativeBuildInputs = oldAttrs.nativeBuildInputs ++ [ pkgs.pkg-config ];
88 buildInputs = oldAttrs.buildInputs ++ [
89 pkgs.pixman
90 pkgs.cairo.dev
91 pkgs.libpng.dev
92 pkgs.gnome2.pango.dev
93 pkgs.glib.dev
94 pkgs.harfbuzz.dev
95 pkgs.freetype.dev
96 ];
97 }));
98
99 "@tensorflow/tfjs-node" = (drv: drv.overrideAttrs (oldAttrs: {
100 buildInputs = oldAttrs.buildInputs ++ [
101 pkgs.libtensorflow
102 ];
103
104 preBuild = ''
105 mkdir -p node_modules/@tensorflow/tfjs-node/deps/lib
106 ln -s ${pkgs.libtensorflow}/lib/libtensorflow.so.2 node_modules/@tensorflow/tfjs-node/deps/lib/libtensorflow.so.2.9.1
107 '';
108 }));
109 };
110 } [
111 (pnpm2nix.mkPnpmPackage.x86_64-linux)
112 (drv: builtins.readFile "${drv}/nix-support/propagated-build-inputs")
113 (path: "${path}/node_modules")
114 ];
115
TheCodedProf30219372023-06-11 14:15:30 -0400116 in
117 pkgs.stdenv.mkDerivation {
118 pname = "nucleus";
119 version = packageJSON.version;
TheCodedProf4a7c25d2023-06-07 17:09:45 -0400120
TheCodedProf30219372023-06-11 14:15:30 -0400121 src = ./.;
TheCodedProf4a7c25d2023-06-07 17:09:45 -0400122
TheCodedProf30219372023-06-11 14:15:30 -0400123 buildInputs = [ nodejs nodePackages.pnpm ];
124 nativeBuildInputs = [ nodePackages.pnpm nodePackages.typescript pkgs.python3 ];
TheCodedProf4a7c25d2023-06-07 17:09:45 -0400125
TheCodedProf30219372023-06-11 14:15:30 -0400126 buildPhase = ''
127 ${pkgs.python3}/bin/python3 ${./scripts/fix-pnpm-bin.py} ${node_modules} ./bin
128 export PATH=$PATH:./bin
129 ln -s ${node_modules} node_modules
130 pnpm run build
131 '';
TheCodedProf4a7c25d2023-06-07 17:09:45 -0400132
TheCodedProf30219372023-06-11 14:15:30 -0400133 installPhase = ''
134 mkdir -p $out
135
136 cp dist $out -r
137 cp node_modules $out -r
138 cp bin $out/.bin -r
139 cp package.json $out
140 cp LICENSE $out
141
142 mkdir -p $out/bin
143 echo "#!/usr/bin/env bash" > $out/bin/nucleus
144 echo "cd $out" >> $out/bin/nucleus
145 echo "export PATH=$PATH:$out/node_modules/.bin" >> $out/bin/nucleus
146 echo "${packageJSON.scripts.start}" >> $out/bin/nucleus
147 chmod +x $out/bin/nucleus
148 '';
149 };
150
151 dockerImage = pkgs.dockerTools.streamLayeredImage {
152 name = "nucleus";
153 tag = "latest";
154 contents = [ nucleus ];
155 config.Cmd = [ "${nucleus}/bin/nucleus" ];
156 };
157
158 default = nucleus;
159 };
160 };
Skyler Grey9b6992a2023-06-09 12:46:05 +0200161}