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 | |
| 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 | ]; |
TheCodedProf | 3021937 | 2023-06-11 14:15:30 -0400 | [diff] [blame] | 66 | }; |
| 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 | })); |
TheCodedProf | 4a7c25d | 2023-06-07 17:09:45 -0400 | [diff] [blame] | 93 | |
TheCodedProf | 3021937 | 2023-06-11 14:15:30 -0400 | [diff] [blame] | 94 | "@tensorflow/tfjs-node" = (drv: drv.overrideAttrs (oldAttrs: { |
| 95 | buildInputs = oldAttrs.buildInputs ++ [ |
| 96 | pkgs.libtensorflow |
| 97 | ]; |
TheCodedProf | 4a7c25d | 2023-06-07 17:09:45 -0400 | [diff] [blame] | 98 | |
TheCodedProf | 3021937 | 2023-06-11 14:15:30 -0400 | [diff] [blame] | 99 | 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 | ]; |
TheCodedProf | 4a7c25d | 2023-06-07 17:09:45 -0400 | [diff] [blame] | 110 | |
TheCodedProf | 3021937 | 2023-06-11 14:15:30 -0400 | [diff] [blame] | 111 | nucleus = |
| 112 | let |
| 113 | packageJSON = (builtins.fromJSON (builtins.readFile ./package.json)); |
| 114 | in |
| 115 | pkgs.stdenv.mkDerivation { |
| 116 | pname = "nucleus"; |
| 117 | version = packageJSON.version; |
TheCodedProf | 4a7c25d | 2023-06-07 17:09:45 -0400 | [diff] [blame] | 118 | |
TheCodedProf | 3021937 | 2023-06-11 14:15:30 -0400 | [diff] [blame] | 119 | src = ./.; |
TheCodedProf | 4a7c25d | 2023-06-07 17:09:45 -0400 | [diff] [blame] | 120 | |
TheCodedProf | 3021937 | 2023-06-11 14:15:30 -0400 | [diff] [blame] | 121 | buildInputs = [ nodejs nodePackages.pnpm ]; |
| 122 | nativeBuildInputs = [ nodePackages.pnpm nodePackages.typescript pkgs.python3 ]; |
TheCodedProf | 4a7c25d | 2023-06-07 17:09:45 -0400 | [diff] [blame] | 123 | |
TheCodedProf | 3021937 | 2023-06-11 14:15:30 -0400 | [diff] [blame] | 124 | 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 | ''; |
TheCodedProf | 4a7c25d | 2023-06-07 17:09:45 -0400 | [diff] [blame] | 130 | |
TheCodedProf | 3021937 | 2023-06-11 14:15:30 -0400 | [diff] [blame] | 131 | 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 Grey | 9b6992a | 2023-06-09 12:46:05 +0200 | [diff] [blame] | 159 | } |