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; |
| 19 | in |
| 20 | rec { |
Skyler Grey | 8e2df92 | 2023-06-14 14:02:31 +0200 | [diff] [blame] | 21 | 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 Grey | df6ff25 | 2023-06-14 18:52:03 +0200 | [diff] [blame^] | 51 | processes.clamav.exec = |
| 52 | let |
Skyler Grey | 8e2df92 | 2023-06-14 14:02:31 +0200 | [diff] [blame] | 53 | clamd_config = pkgs.writeText "clamd.conf" '' |
Skyler Grey | df6ff25 | 2023-06-14 18:52:03 +0200 | [diff] [blame^] | 54 | TCPSocket 3310 |
| 55 | PidFile /tmp/clamav-nucleus.pid |
| 56 | DatabaseDirectory ${config.env.DEVENV_STATE}/clamav/db |
| 57 | TemporaryDirectory /tmp |
| 58 | Foreground true |
Skyler Grey | 8e2df92 | 2023-06-14 14:02:31 +0200 | [diff] [blame] | 59 | ''; |
| 60 | freshclam_config = pkgs.writeText "freshclam.conf" '' |
Skyler Grey | df6ff25 | 2023-06-14 18:52:03 +0200 | [diff] [blame^] | 61 | DatabaseDirectory ${config.env.DEVENV_STATE}/clamav/db |
| 62 | DatabaseMirror database.clamav.net |
Skyler Grey | 8e2df92 | 2023-06-14 14:02:31 +0200 | [diff] [blame] | 63 | ''; |
Skyler Grey | df6ff25 | 2023-06-14 18:52:03 +0200 | [diff] [blame^] | 64 | in |
| 65 | "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] | 66 | }) |
| 67 | ]; |
TheCodedProf | 3021937 | 2023-06-11 14:15:30 -0400 | [diff] [blame] | 68 | }; |
| 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 { |
TheCodedProf | 3021937 | 2023-06-11 14:15:30 -0400 | [diff] [blame] | 78 | nucleus = |
| 79 | let |
| 80 | packageJSON = (builtins.fromJSON (builtins.readFile ./package.json)); |
Skyler Grey | df6ff25 | 2023-06-14 18:52:03 +0200 | [diff] [blame^] | 81 | 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 | |
TheCodedProf | 3021937 | 2023-06-11 14:15:30 -0400 | [diff] [blame] | 116 | in |
| 117 | pkgs.stdenv.mkDerivation { |
| 118 | pname = "nucleus"; |
| 119 | version = packageJSON.version; |
TheCodedProf | 4a7c25d | 2023-06-07 17:09:45 -0400 | [diff] [blame] | 120 | |
TheCodedProf | 3021937 | 2023-06-11 14:15:30 -0400 | [diff] [blame] | 121 | src = ./.; |
TheCodedProf | 4a7c25d | 2023-06-07 17:09:45 -0400 | [diff] [blame] | 122 | |
TheCodedProf | 3021937 | 2023-06-11 14:15:30 -0400 | [diff] [blame] | 123 | buildInputs = [ nodejs nodePackages.pnpm ]; |
| 124 | nativeBuildInputs = [ nodePackages.pnpm nodePackages.typescript pkgs.python3 ]; |
TheCodedProf | 4a7c25d | 2023-06-07 17:09:45 -0400 | [diff] [blame] | 125 | |
TheCodedProf | 3021937 | 2023-06-11 14:15:30 -0400 | [diff] [blame] | 126 | 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 | ''; |
TheCodedProf | 4a7c25d | 2023-06-07 17:09:45 -0400 | [diff] [blame] | 132 | |
TheCodedProf | 3021937 | 2023-06-11 14:15:30 -0400 | [diff] [blame] | 133 | 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 Grey | 9b6992a | 2023-06-09 12:46:05 +0200 | [diff] [blame] | 161 | } |