blob: b24354d9ce61c510d675df8f7aa2d398a32e9e91 [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
51 processes.clamav.exec = let
52 clamd_config = pkgs.writeText "clamd.conf" ''
53 TCPSocket 3310
54 PidFile /tmp/clamav-nucleus.pid
55 DatabaseDirectory ${config.env.DEVENV_STATE}/clamav/db
56 TemporaryDirectory /tmp
57 Foreground true
58 '';
59 freshclam_config = pkgs.writeText "freshclam.conf" ''
60 DatabaseDirectory ${config.env.DEVENV_STATE}/clamav/db
61 DatabaseMirror database.clamav.net
62 '';
63 in "mkdir -p $DEVENV_STATE/clamav/db && ${pkgs.clamav}/bin/freshclam --config ${freshclam_config} || true; ${pkgs.clamav}/bin/clamd -c ${clamd_config}";
64 })
65 ];
TheCodedProf30219372023-06-11 14:15:30 -040066 };
67 }) // {
68 packages.x86_64-linux =
69 let
70 pkgs = nixpkgs.legacyPackages.x86_64-linux;
71 nodejs = pkgs.nodejs_20;
72 nodePackages = pkgs.nodePackages_latest;
73 lib = pkgs.lib;
74 in
75 rec {
76 node_modules = lib.pipe
77 {
78 src = ./.;
79 linkDevDependencies = true;
80 overrides = pnpm2nix.defaultPnpmOverrides.x86_64-linux // {
81 canvas = (drv: drv.overrideAttrs (oldAttrs: {
82 nativeBuildInputs = oldAttrs.nativeBuildInputs ++ [ pkgs.pkg-config ];
83 buildInputs = oldAttrs.buildInputs ++ [
84 pkgs.pixman
85 pkgs.cairo.dev
86 pkgs.libpng.dev
87 pkgs.gnome2.pango.dev
88 pkgs.glib.dev
89 pkgs.harfbuzz.dev
90 pkgs.freetype.dev
91 ];
92 }));
TheCodedProf4a7c25d2023-06-07 17:09:45 -040093
TheCodedProf30219372023-06-11 14:15:30 -040094 "@tensorflow/tfjs-node" = (drv: drv.overrideAttrs (oldAttrs: {
95 buildInputs = oldAttrs.buildInputs ++ [
96 pkgs.libtensorflow
97 ];
TheCodedProf4a7c25d2023-06-07 17:09:45 -040098
TheCodedProf30219372023-06-11 14:15:30 -040099 preBuild = ''
100 mkdir -p node_modules/@tensorflow/tfjs-node/deps/lib
101 ln -s ${pkgs.libtensorflow}/lib/libtensorflow.so.2 node_modules/@tensorflow/tfjs-node/deps/lib/libtensorflow.so.2.9.1
102 '';
103 }));
104 };
105 } [
106 (pnpm2nix.mkPnpmPackage.x86_64-linux)
107 (drv: builtins.readFile "${drv}/nix-support/propagated-build-inputs")
108 (path: "${path}/node_modules")
109 ];
TheCodedProf4a7c25d2023-06-07 17:09:45 -0400110
TheCodedProf30219372023-06-11 14:15:30 -0400111 nucleus =
112 let
113 packageJSON = (builtins.fromJSON (builtins.readFile ./package.json));
114 in
115 pkgs.stdenv.mkDerivation {
116 pname = "nucleus";
117 version = packageJSON.version;
TheCodedProf4a7c25d2023-06-07 17:09:45 -0400118
TheCodedProf30219372023-06-11 14:15:30 -0400119 src = ./.;
TheCodedProf4a7c25d2023-06-07 17:09:45 -0400120
TheCodedProf30219372023-06-11 14:15:30 -0400121 buildInputs = [ nodejs nodePackages.pnpm ];
122 nativeBuildInputs = [ nodePackages.pnpm nodePackages.typescript pkgs.python3 ];
TheCodedProf4a7c25d2023-06-07 17:09:45 -0400123
TheCodedProf30219372023-06-11 14:15:30 -0400124 buildPhase = ''
125 ${pkgs.python3}/bin/python3 ${./scripts/fix-pnpm-bin.py} ${node_modules} ./bin
126 export PATH=$PATH:./bin
127 ln -s ${node_modules} node_modules
128 pnpm run build
129 '';
TheCodedProf4a7c25d2023-06-07 17:09:45 -0400130
TheCodedProf30219372023-06-11 14:15:30 -0400131 installPhase = ''
132 mkdir -p $out
133
134 cp dist $out -r
135 cp node_modules $out -r
136 cp bin $out/.bin -r
137 cp package.json $out
138 cp LICENSE $out
139
140 mkdir -p $out/bin
141 echo "#!/usr/bin/env bash" > $out/bin/nucleus
142 echo "cd $out" >> $out/bin/nucleus
143 echo "export PATH=$PATH:$out/node_modules/.bin" >> $out/bin/nucleus
144 echo "${packageJSON.scripts.start}" >> $out/bin/nucleus
145 chmod +x $out/bin/nucleus
146 '';
147 };
148
149 dockerImage = pkgs.dockerTools.streamLayeredImage {
150 name = "nucleus";
151 tag = "latest";
152 contents = [ nucleus ];
153 config.Cmd = [ "${nucleus}/bin/nucleus" ];
154 };
155
156 default = nucleus;
157 };
158 };
Skyler Grey9b6992a2023-06-09 12:46:05 +0200159}