blob: 33d06988a9a120d17f5bdb509a7a2dbf0912617f [file] [log] [blame]
Skyler Grey453b9992023-03-05 05:48:42 +00001{
2 description = "A basic flake with a shell";
TheCodedProf4a7c25d2023-06-07 17:09:45 -04003 inputs.nixpkgs.follows = "clicks-server/nixpkgs";
Skyler Grey453b9992023-03-05 05:48:42 +00004 inputs.flake-utils.url = "github:numtide/flake-utils";
Skyler Grey9b6992a2023-06-09 12:46:05 +02005 inputs.clicks-server.url = "git+ssh://git@github.com/clicksminuteper/nixfiles";
6 inputs.pnpm2nix.url = "git+ssh://git@github.com/clicksminuteper/pnpm2nix";
Skyler Grey453b9992023-03-05 05:48:42 +00007
TheCodedProf4a7c25d2023-06-07 17:09:45 -04008 inputs.pnpm2nix.inputs.nixpkgs.follows = "nixpkgs";
9
10 outputs = { self, nixpkgs, flake-utils, clicks-server, pnpm2nix }:
TheCodedProf30219372023-06-11 14:15:30 -040011 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 }));
TheCodedProf4a7c25d2023-06-07 17:09:45 -040061
TheCodedProf30219372023-06-11 14:15:30 -040062 "@tensorflow/tfjs-node" = (drv: drv.overrideAttrs (oldAttrs: {
63 buildInputs = oldAttrs.buildInputs ++ [
64 pkgs.libtensorflow
65 ];
TheCodedProf4a7c25d2023-06-07 17:09:45 -040066
TheCodedProf30219372023-06-11 14:15:30 -040067 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 ];
TheCodedProf4a7c25d2023-06-07 17:09:45 -040078
TheCodedProf30219372023-06-11 14:15:30 -040079 nucleus =
80 let
81 packageJSON = (builtins.fromJSON (builtins.readFile ./package.json));
82 in
83 pkgs.stdenv.mkDerivation {
84 pname = "nucleus";
85 version = packageJSON.version;
TheCodedProf4a7c25d2023-06-07 17:09:45 -040086
TheCodedProf30219372023-06-11 14:15:30 -040087 src = ./.;
TheCodedProf4a7c25d2023-06-07 17:09:45 -040088
TheCodedProf30219372023-06-11 14:15:30 -040089 buildInputs = [ nodejs nodePackages.pnpm ];
90 nativeBuildInputs = [ nodePackages.pnpm nodePackages.typescript pkgs.python3 ];
TheCodedProf4a7c25d2023-06-07 17:09:45 -040091
TheCodedProf30219372023-06-11 14:15:30 -040092 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 '';
TheCodedProf4a7c25d2023-06-07 17:09:45 -040098
TheCodedProf30219372023-06-11 14:15:30 -040099 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 Grey9b6992a2023-06-09 12:46:05 +0200127}