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 | 453b999 | 2023-03-05 05:48:42 +0000 | [diff] [blame] | 7 | |
TheCodedProf | 4a7c25d | 2023-06-07 17:09:45 -0400 | [diff] [blame] | 8 | inputs.pnpm2nix.inputs.nixpkgs.follows = "nixpkgs"; |
| 9 | |
| 10 | outputs = { self, nixpkgs, flake-utils, clicks-server, pnpm2nix }: |
TheCodedProf | 3021937 | 2023-06-11 14:15:30 -0400 | [diff] [blame^] | 11 | flake-utils.lib.eachDefaultSystem |
| 12 | (system: |
| 13 | let |
| 14 | pkgs = nixpkgs.legacyPackages.${system}; |
| 15 | nodejs = pkgs.nodejs_20; |
| 16 | nodePackages = pkgs.nodePackages_latest; |
| 17 | lib = pkgs.lib; |
| 18 | in |
| 19 | rec { |
| 20 | devShells.default = pkgs.mkShell { |
| 21 | packages = [ nodejs nodePackages.pnpm pkgs.pkg-config pkgs.fontconfig.dev ]; |
| 22 | shellHook = '' |
| 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 | ''; |
| 34 | }; |
| 35 | }) // { |
| 36 | packages.x86_64-linux = |
| 37 | let |
| 38 | pkgs = nixpkgs.legacyPackages.x86_64-linux; |
| 39 | nodejs = pkgs.nodejs_20; |
| 40 | nodePackages = pkgs.nodePackages_latest; |
| 41 | lib = pkgs.lib; |
| 42 | in |
| 43 | rec { |
| 44 | node_modules = lib.pipe |
| 45 | { |
| 46 | src = ./.; |
| 47 | linkDevDependencies = true; |
| 48 | overrides = pnpm2nix.defaultPnpmOverrides.x86_64-linux // { |
| 49 | canvas = (drv: drv.overrideAttrs (oldAttrs: { |
| 50 | nativeBuildInputs = oldAttrs.nativeBuildInputs ++ [ pkgs.pkg-config ]; |
| 51 | buildInputs = oldAttrs.buildInputs ++ [ |
| 52 | pkgs.pixman |
| 53 | pkgs.cairo.dev |
| 54 | pkgs.libpng.dev |
| 55 | pkgs.gnome2.pango.dev |
| 56 | pkgs.glib.dev |
| 57 | pkgs.harfbuzz.dev |
| 58 | pkgs.freetype.dev |
| 59 | ]; |
| 60 | })); |
TheCodedProf | 4a7c25d | 2023-06-07 17:09:45 -0400 | [diff] [blame] | 61 | |
TheCodedProf | 3021937 | 2023-06-11 14:15:30 -0400 | [diff] [blame^] | 62 | "@tensorflow/tfjs-node" = (drv: drv.overrideAttrs (oldAttrs: { |
| 63 | buildInputs = oldAttrs.buildInputs ++ [ |
| 64 | pkgs.libtensorflow |
| 65 | ]; |
TheCodedProf | 4a7c25d | 2023-06-07 17:09:45 -0400 | [diff] [blame] | 66 | |
TheCodedProf | 3021937 | 2023-06-11 14:15:30 -0400 | [diff] [blame^] | 67 | preBuild = '' |
| 68 | mkdir -p node_modules/@tensorflow/tfjs-node/deps/lib |
| 69 | ln -s ${pkgs.libtensorflow}/lib/libtensorflow.so.2 node_modules/@tensorflow/tfjs-node/deps/lib/libtensorflow.so.2.9.1 |
| 70 | ''; |
| 71 | })); |
| 72 | }; |
| 73 | } [ |
| 74 | (pnpm2nix.mkPnpmPackage.x86_64-linux) |
| 75 | (drv: builtins.readFile "${drv}/nix-support/propagated-build-inputs") |
| 76 | (path: "${path}/node_modules") |
| 77 | ]; |
TheCodedProf | 4a7c25d | 2023-06-07 17:09:45 -0400 | [diff] [blame] | 78 | |
TheCodedProf | 3021937 | 2023-06-11 14:15:30 -0400 | [diff] [blame^] | 79 | nucleus = |
| 80 | let |
| 81 | packageJSON = (builtins.fromJSON (builtins.readFile ./package.json)); |
| 82 | in |
| 83 | pkgs.stdenv.mkDerivation { |
| 84 | pname = "nucleus"; |
| 85 | version = packageJSON.version; |
TheCodedProf | 4a7c25d | 2023-06-07 17:09:45 -0400 | [diff] [blame] | 86 | |
TheCodedProf | 3021937 | 2023-06-11 14:15:30 -0400 | [diff] [blame^] | 87 | src = ./.; |
TheCodedProf | 4a7c25d | 2023-06-07 17:09:45 -0400 | [diff] [blame] | 88 | |
TheCodedProf | 3021937 | 2023-06-11 14:15:30 -0400 | [diff] [blame^] | 89 | buildInputs = [ nodejs nodePackages.pnpm ]; |
| 90 | nativeBuildInputs = [ nodePackages.pnpm nodePackages.typescript pkgs.python3 ]; |
TheCodedProf | 4a7c25d | 2023-06-07 17:09:45 -0400 | [diff] [blame] | 91 | |
TheCodedProf | 3021937 | 2023-06-11 14:15:30 -0400 | [diff] [blame^] | 92 | buildPhase = '' |
| 93 | ${pkgs.python3}/bin/python3 ${./scripts/fix-pnpm-bin.py} ${node_modules} ./bin |
| 94 | export PATH=$PATH:./bin |
| 95 | ln -s ${node_modules} node_modules |
| 96 | pnpm run build |
| 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 | installPhase = '' |
| 100 | mkdir -p $out |
| 101 | |
| 102 | cp dist $out -r |
| 103 | cp node_modules $out -r |
| 104 | cp bin $out/.bin -r |
| 105 | cp package.json $out |
| 106 | cp LICENSE $out |
| 107 | |
| 108 | mkdir -p $out/bin |
| 109 | echo "#!/usr/bin/env bash" > $out/bin/nucleus |
| 110 | echo "cd $out" >> $out/bin/nucleus |
| 111 | echo "export PATH=$PATH:$out/node_modules/.bin" >> $out/bin/nucleus |
| 112 | echo "${packageJSON.scripts.start}" >> $out/bin/nucleus |
| 113 | chmod +x $out/bin/nucleus |
| 114 | ''; |
| 115 | }; |
| 116 | |
| 117 | dockerImage = pkgs.dockerTools.streamLayeredImage { |
| 118 | name = "nucleus"; |
| 119 | tag = "latest"; |
| 120 | contents = [ nucleus ]; |
| 121 | config.Cmd = [ "${nucleus}/bin/nucleus" ]; |
| 122 | }; |
| 123 | |
| 124 | default = nucleus; |
| 125 | }; |
| 126 | }; |
Skyler Grey | 9b6992a | 2023-06-09 12:46:05 +0200 | [diff] [blame] | 127 | } |