| { |
| description = "A basic flake with a shell"; |
| inputs.nixpkgs.follows = "clicks-server/nixpkgs"; |
| inputs.flake-utils.url = "github:numtide/flake-utils"; |
| inputs.clicks-server.url = "git+ssh://git@github.com/clicksminuteper/nixfiles"; |
| inputs.pnpm2nix.url = "git+ssh://git@github.com/clicksminuteper/pnpm2nix"; |
| |
| inputs.pnpm2nix.inputs.nixpkgs.follows = "nixpkgs"; |
| |
| outputs = { self, nixpkgs, flake-utils, clicks-server, pnpm2nix }: |
| flake-utils.lib.eachDefaultSystem |
| (system: |
| let |
| pkgs = nixpkgs.legacyPackages.${system}; |
| nodejs = pkgs.nodejs_20; |
| nodePackages = pkgs.nodePackages_latest; |
| lib = pkgs.lib; |
| in |
| rec { |
| devShells.default = pkgs.mkShell { |
| packages = [ nodejs nodePackages.pnpm pkgs.pkg-config pkgs.fontconfig.dev ]; |
| shellHook = '' |
| unset name |
| export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:${lib.makeSearchPath "/lib/pkgconfig" [ |
| pkgs.pixman |
| pkgs.cairo.dev |
| pkgs.libpng.dev |
| pkgs.gnome2.pango.dev |
| pkgs.glib.dev |
| pkgs.harfbuzz.dev |
| pkgs.freetype.dev |
| ]} |
| ''; |
| }; |
| }) // { |
| packages.x86_64-linux = |
| let |
| pkgs = nixpkgs.legacyPackages.x86_64-linux; |
| nodejs = pkgs.nodejs_20; |
| nodePackages = pkgs.nodePackages_latest; |
| lib = pkgs.lib; |
| in |
| rec { |
| node_modules = lib.pipe |
| { |
| src = ./.; |
| linkDevDependencies = true; |
| overrides = pnpm2nix.defaultPnpmOverrides.x86_64-linux // { |
| canvas = (drv: drv.overrideAttrs (oldAttrs: { |
| nativeBuildInputs = oldAttrs.nativeBuildInputs ++ [ pkgs.pkg-config ]; |
| buildInputs = oldAttrs.buildInputs ++ [ |
| pkgs.pixman |
| pkgs.cairo.dev |
| pkgs.libpng.dev |
| pkgs.gnome2.pango.dev |
| pkgs.glib.dev |
| pkgs.harfbuzz.dev |
| pkgs.freetype.dev |
| ]; |
| })); |
| |
| "@tensorflow/tfjs-node" = (drv: drv.overrideAttrs (oldAttrs: { |
| buildInputs = oldAttrs.buildInputs ++ [ |
| pkgs.libtensorflow |
| ]; |
| |
| preBuild = '' |
| mkdir -p node_modules/@tensorflow/tfjs-node/deps/lib |
| ln -s ${pkgs.libtensorflow}/lib/libtensorflow.so.2 node_modules/@tensorflow/tfjs-node/deps/lib/libtensorflow.so.2.9.1 |
| ''; |
| })); |
| }; |
| } [ |
| (pnpm2nix.mkPnpmPackage.x86_64-linux) |
| (drv: builtins.readFile "${drv}/nix-support/propagated-build-inputs") |
| (path: "${path}/node_modules") |
| ]; |
| |
| nucleus = |
| let |
| packageJSON = (builtins.fromJSON (builtins.readFile ./package.json)); |
| in |
| pkgs.stdenv.mkDerivation { |
| pname = "nucleus"; |
| version = packageJSON.version; |
| |
| src = ./.; |
| |
| buildInputs = [ nodejs nodePackages.pnpm ]; |
| nativeBuildInputs = [ nodePackages.pnpm nodePackages.typescript pkgs.python3 ]; |
| |
| buildPhase = '' |
| ${pkgs.python3}/bin/python3 ${./scripts/fix-pnpm-bin.py} ${node_modules} ./bin |
| export PATH=$PATH:./bin |
| ln -s ${node_modules} node_modules |
| pnpm run build |
| ''; |
| |
| installPhase = '' |
| mkdir -p $out |
| |
| cp dist $out -r |
| cp node_modules $out -r |
| cp bin $out/.bin -r |
| cp package.json $out |
| cp LICENSE $out |
| |
| mkdir -p $out/bin |
| echo "#!/usr/bin/env bash" > $out/bin/nucleus |
| echo "cd $out" >> $out/bin/nucleus |
| echo "export PATH=$PATH:$out/node_modules/.bin" >> $out/bin/nucleus |
| echo "${packageJSON.scripts.start}" >> $out/bin/nucleus |
| chmod +x $out/bin/nucleus |
| ''; |
| }; |
| |
| dockerImage = pkgs.dockerTools.streamLayeredImage { |
| name = "nucleus"; |
| tag = "latest"; |
| contents = [ nucleus ]; |
| config.Cmd = [ "${nucleus}/bin/nucleus" ]; |
| }; |
| |
| default = nucleus; |
| }; |
| }; |
| } |