Skyler Grey | 453b999 | 2023-03-05 05:48:42 +0000 | [diff] [blame] | 1 | { |
| 2 | description = "A basic flake with a shell"; |
TheCodedProf | 4a7c25d | 2023-06-07 17:09:45 -0400 | [diff] [blame] | 3 | inputs.nixpkgs.follows = "clicks-server/nixpkgs"; |
Skyler Grey | 453b999 | 2023-03-05 05:48:42 +0000 | [diff] [blame] | 4 | inputs.flake-utils.url = "github:numtide/flake-utils"; |
Skyler Grey | 9b6992a | 2023-06-09 12:46:05 +0200 | [diff] [blame] | 5 | inputs.clicks-server.url = "git+ssh://git@github.com/clicksminuteper/nixfiles"; |
| 6 | inputs.pnpm2nix.url = "git+ssh://git@github.com/clicksminuteper/pnpm2nix"; |
Skyler Grey | 8e2df92 | 2023-06-14 14:02:31 +0200 | [diff] [blame] | 7 | inputs.devenv.url = "github:cachix/devenv"; |
Skyler Grey | 453b999 | 2023-03-05 05:48:42 +0000 | [diff] [blame] | 8 | |
TheCodedProf | 4a7c25d | 2023-06-07 17:09:45 -0400 | [diff] [blame] | 9 | inputs.pnpm2nix.inputs.nixpkgs.follows = "nixpkgs"; |
| 10 | |
Skyler Grey | 8e2df92 | 2023-06-14 14:02:31 +0200 | [diff] [blame] | 11 | outputs = { self, devenv, nixpkgs, flake-utils, clicks-server, pnpm2nix, ... }@inputs: |
TheCodedProf | 3021937 | 2023-06-11 14:15:30 -0400 | [diff] [blame] | 12 | 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 Grey | 9357df7 | 2023-06-14 19:00:01 +0200 | [diff] [blame] | 19 | |
| 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 | ''; |
TheCodedProf | 3021937 | 2023-06-11 14:15:30 -0400 | [diff] [blame] | 34 | in |
| 35 | rec { |
Skyler Grey | 9357df7 | 2023-06-14 19:00:01 +0200 | [diff] [blame] | 36 | devShells.pure = pkgs.mkShell { |
| 37 | packages = shellPackages; |
| 38 | shellHook = enterShellHook; |
| 39 | }; |
Skyler Grey | 8e2df92 | 2023-06-14 14:02:31 +0200 | [diff] [blame] | 40 | devShells.default = devenv.lib.mkShell { |
| 41 | inherit inputs pkgs; |
Skyler Grey | 9357df7 | 2023-06-14 19:00:01 +0200 | [diff] [blame] | 42 | |
| 43 | |
Skyler Grey | 8e2df92 | 2023-06-14 14:02:31 +0200 | [diff] [blame] | 44 | modules = [ |
| 45 | ({ pkgs, config, ... }: { |
| 46 | # This is your devenv configuration |
Skyler Grey | 9357df7 | 2023-06-14 19:00:01 +0200 | [diff] [blame] | 47 | packages = shellPackages; |
| 48 | enterShell = enterShellHook; |
Skyler Grey | 8e2df92 | 2023-06-14 14:02:31 +0200 | [diff] [blame] | 49 | |
| 50 | services.mongodb = { |
| 51 | enable = true; |
| 52 | package = pkgs.mongodb-6_0; |
| 53 | additionalArgs = [ |
| 54 | "--port" |
| 55 | "27017" |
| 56 | "--noauth" |
| 57 | ]; |
| 58 | }; |
| 59 | |
Skyler Grey | df6ff25 | 2023-06-14 18:52:03 +0200 | [diff] [blame] | 60 | processes.clamav.exec = |
| 61 | let |
Skyler Grey | 8e2df92 | 2023-06-14 14:02:31 +0200 | [diff] [blame] | 62 | clamd_config = pkgs.writeText "clamd.conf" '' |
Skyler Grey | df6ff25 | 2023-06-14 18:52:03 +0200 | [diff] [blame] | 63 | TCPSocket 3310 |
| 64 | PidFile /tmp/clamav-nucleus.pid |
| 65 | DatabaseDirectory ${config.env.DEVENV_STATE}/clamav/db |
| 66 | TemporaryDirectory /tmp |
| 67 | Foreground true |
Skyler Grey | 8e2df92 | 2023-06-14 14:02:31 +0200 | [diff] [blame] | 68 | ''; |
| 69 | freshclam_config = pkgs.writeText "freshclam.conf" '' |
Skyler Grey | df6ff25 | 2023-06-14 18:52:03 +0200 | [diff] [blame] | 70 | DatabaseDirectory ${config.env.DEVENV_STATE}/clamav/db |
| 71 | DatabaseMirror database.clamav.net |
Skyler Grey | 8e2df92 | 2023-06-14 14:02:31 +0200 | [diff] [blame] | 72 | ''; |
Skyler Grey | df6ff25 | 2023-06-14 18:52:03 +0200 | [diff] [blame] | 73 | in |
| 74 | "mkdir -p $DEVENV_STATE/clamav/db && ${pkgs.clamav}/bin/freshclam --config ${freshclam_config} || true; ${pkgs.clamav}/bin/clamd -c ${clamd_config}"; |
Skyler Grey | 8e2df92 | 2023-06-14 14:02:31 +0200 | [diff] [blame] | 75 | }) |
| 76 | ]; |
TheCodedProf | 3021937 | 2023-06-11 14:15:30 -0400 | [diff] [blame] | 77 | }; |
| 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 { |
TheCodedProf | 3021937 | 2023-06-11 14:15:30 -0400 | [diff] [blame] | 87 | nucleus = |
| 88 | let |
| 89 | packageJSON = (builtins.fromJSON (builtins.readFile ./package.json)); |
Skyler Grey | df6ff25 | 2023-06-14 18:52:03 +0200 | [diff] [blame] | 90 | 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 | |
TheCodedProf | 3021937 | 2023-06-11 14:15:30 -0400 | [diff] [blame] | 125 | in |
| 126 | pkgs.stdenv.mkDerivation { |
| 127 | pname = "nucleus"; |
| 128 | version = packageJSON.version; |
TheCodedProf | 4a7c25d | 2023-06-07 17:09:45 -0400 | [diff] [blame] | 129 | |
TheCodedProf | 3021937 | 2023-06-11 14:15:30 -0400 | [diff] [blame] | 130 | src = ./.; |
TheCodedProf | 4a7c25d | 2023-06-07 17:09:45 -0400 | [diff] [blame] | 131 | |
TheCodedProf | 3021937 | 2023-06-11 14:15:30 -0400 | [diff] [blame] | 132 | buildInputs = [ nodejs nodePackages.pnpm ]; |
| 133 | nativeBuildInputs = [ nodePackages.pnpm nodePackages.typescript pkgs.python3 ]; |
TheCodedProf | 4a7c25d | 2023-06-07 17:09:45 -0400 | [diff] [blame] | 134 | |
TheCodedProf | 3021937 | 2023-06-11 14:15:30 -0400 | [diff] [blame] | 135 | 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 | ''; |
TheCodedProf | 4a7c25d | 2023-06-07 17:09:45 -0400 | [diff] [blame] | 141 | |
TheCodedProf | 3021937 | 2023-06-11 14:15:30 -0400 | [diff] [blame] | 142 | 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 Grey | 9b6992a | 2023-06-09 12:46:05 +0200 | [diff] [blame] | 170 | } |