blob: effdcea024e451219dec067a4078a3003c4b5558 [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;
Skyler Grey9357df72023-06-14 19:00:01 +020019
20 shellPackages = [ nodejs nodePackages.pnpm pkgs.pkg-config pkgs.fontconfig.dev pkgs.clamav ];
21
22 enterShellHook = ''
23 unset name
24 export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:${lib.makeSearchPath "/lib/pkgconfig" [
25 pkgs.pixman
26 pkgs.cairo.dev
27 pkgs.libpng.dev
28 pkgs.gnome2.pango.dev
29 pkgs.glib.dev
30 pkgs.harfbuzz.dev
31 pkgs.freetype.dev
32 ]}
33 '';
TheCodedProf30219372023-06-11 14:15:30 -040034 in
35 rec {
Skyler Grey9357df72023-06-14 19:00:01 +020036 devShells.pure = pkgs.mkShell {
37 packages = shellPackages;
38 shellHook = enterShellHook;
39 };
Skyler Grey8e2df922023-06-14 14:02:31 +020040 devShells.default = devenv.lib.mkShell {
41 inherit inputs pkgs;
Skyler Grey9357df72023-06-14 19:00:01 +020042
43
Skyler Grey8e2df922023-06-14 14:02:31 +020044 modules = [
45 ({ pkgs, config, ... }: {
46 # This is your devenv configuration
Skyler Grey9357df72023-06-14 19:00:01 +020047 packages = shellPackages;
48 enterShell = enterShellHook;
Skyler Grey8e2df922023-06-14 14:02:31 +020049
50 services.mongodb = {
51 enable = true;
52 package = pkgs.mongodb-6_0;
53 additionalArgs = [
54 "--port"
55 "27017"
56 "--noauth"
57 ];
58 };
59
Skyler Greydf6ff252023-06-14 18:52:03 +020060 processes.clamav.exec =
61 let
Skyler Grey8e2df922023-06-14 14:02:31 +020062 clamd_config = pkgs.writeText "clamd.conf" ''
Skyler Greydf6ff252023-06-14 18:52:03 +020063 TCPSocket 3310
64 PidFile /tmp/clamav-nucleus.pid
65 DatabaseDirectory ${config.env.DEVENV_STATE}/clamav/db
66 TemporaryDirectory /tmp
67 Foreground true
Skyler Grey8e2df922023-06-14 14:02:31 +020068 '';
69 freshclam_config = pkgs.writeText "freshclam.conf" ''
Skyler Greydf6ff252023-06-14 18:52:03 +020070 DatabaseDirectory ${config.env.DEVENV_STATE}/clamav/db
71 DatabaseMirror database.clamav.net
Skyler Grey8e2df922023-06-14 14:02:31 +020072 '';
Skyler Greydf6ff252023-06-14 18:52:03 +020073 in
74 "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 +020075 })
76 ];
TheCodedProf30219372023-06-11 14:15:30 -040077 };
78 }) // {
79 packages.x86_64-linux =
80 let
81 pkgs = nixpkgs.legacyPackages.x86_64-linux;
82 nodejs = pkgs.nodejs_20;
83 nodePackages = pkgs.nodePackages_latest;
84 lib = pkgs.lib;
85 in
86 rec {
TheCodedProf30219372023-06-11 14:15:30 -040087 nucleus =
88 let
89 packageJSON = (builtins.fromJSON (builtins.readFile ./package.json));
Skyler Greydf6ff252023-06-14 18:52:03 +020090 node_modules = lib.pipe
91 {
92 src = ./.;
93 linkDevDependencies = true;
94 overrides = pnpm2nix.defaultPnpmOverrides.x86_64-linux // {
95 canvas = (drv: drv.overrideAttrs (oldAttrs: {
96 nativeBuildInputs = oldAttrs.nativeBuildInputs ++ [ pkgs.pkg-config ];
97 buildInputs = oldAttrs.buildInputs ++ [
98 pkgs.pixman
99 pkgs.cairo.dev
100 pkgs.libpng.dev
101 pkgs.gnome2.pango.dev
102 pkgs.glib.dev
103 pkgs.harfbuzz.dev
104 pkgs.freetype.dev
105 ];
106 }));
107
108 "@tensorflow/tfjs-node" = (drv: drv.overrideAttrs (oldAttrs: {
109 buildInputs = oldAttrs.buildInputs ++ [
110 pkgs.libtensorflow
111 ];
112
113 preBuild = ''
114 mkdir -p node_modules/@tensorflow/tfjs-node/deps/lib
115 ln -s ${pkgs.libtensorflow}/lib/libtensorflow.so.2 node_modules/@tensorflow/tfjs-node/deps/lib/libtensorflow.so.2.9.1
116 '';
117 }));
118 };
119 } [
120 (pnpm2nix.mkPnpmPackage.x86_64-linux)
121 (drv: builtins.readFile "${drv}/nix-support/propagated-build-inputs")
122 (path: "${path}/node_modules")
123 ];
124
TheCodedProf30219372023-06-11 14:15:30 -0400125 in
126 pkgs.stdenv.mkDerivation {
127 pname = "nucleus";
128 version = packageJSON.version;
TheCodedProf4a7c25d2023-06-07 17:09:45 -0400129
TheCodedProf30219372023-06-11 14:15:30 -0400130 src = ./.;
TheCodedProf4a7c25d2023-06-07 17:09:45 -0400131
TheCodedProf30219372023-06-11 14:15:30 -0400132 buildInputs = [ nodejs nodePackages.pnpm ];
133 nativeBuildInputs = [ nodePackages.pnpm nodePackages.typescript pkgs.python3 ];
TheCodedProf4a7c25d2023-06-07 17:09:45 -0400134
TheCodedProf30219372023-06-11 14:15:30 -0400135 buildPhase = ''
136 ${pkgs.python3}/bin/python3 ${./scripts/fix-pnpm-bin.py} ${node_modules} ./bin
137 export PATH=$PATH:./bin
138 ln -s ${node_modules} node_modules
139 pnpm run build
140 '';
TheCodedProf4a7c25d2023-06-07 17:09:45 -0400141
TheCodedProf30219372023-06-11 14:15:30 -0400142 installPhase = ''
143 mkdir -p $out
144
145 cp dist $out -r
146 cp node_modules $out -r
147 cp bin $out/.bin -r
148 cp package.json $out
149 cp LICENSE $out
150
151 mkdir -p $out/bin
152 echo "#!/usr/bin/env bash" > $out/bin/nucleus
153 echo "cd $out" >> $out/bin/nucleus
154 echo "export PATH=$PATH:$out/node_modules/.bin" >> $out/bin/nucleus
155 echo "${packageJSON.scripts.start}" >> $out/bin/nucleus
156 chmod +x $out/bin/nucleus
157 '';
158 };
159
160 dockerImage = pkgs.dockerTools.streamLayeredImage {
161 name = "nucleus";
162 tag = "latest";
163 contents = [ nucleus ];
164 config.Cmd = [ "${nucleus}/bin/nucleus" ];
165 };
166
167 default = nucleus;
168 };
169 };
Skyler Grey9b6992a2023-06-09 12:46:05 +0200170}