blob: b24354d9ce61c510d675df8f7aa2d398a32e9e91 [file] [log] [blame]
{
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.devenv.url = "github:cachix/devenv";
inputs.pnpm2nix.inputs.nixpkgs.follows = "nixpkgs";
outputs = { self, devenv, nixpkgs, flake-utils, clicks-server, pnpm2nix, ... }@inputs:
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 = devenv.lib.mkShell {
inherit inputs pkgs;
modules = [
({ pkgs, config, ... }: {
# This is your devenv configuration
packages = [ nodejs nodePackages.pnpm pkgs.pkg-config pkgs.fontconfig.dev pkgs.clamav ];
enterShell = ''
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
]}
'';
services.mongodb = {
enable = true;
package = pkgs.mongodb-6_0;
additionalArgs = [
"--port"
"27017"
"--noauth"
];
};
processes.clamav.exec = let
clamd_config = pkgs.writeText "clamd.conf" ''
TCPSocket 3310
PidFile /tmp/clamav-nucleus.pid
DatabaseDirectory ${config.env.DEVENV_STATE}/clamav/db
TemporaryDirectory /tmp
Foreground true
'';
freshclam_config = pkgs.writeText "freshclam.conf" ''
DatabaseDirectory ${config.env.DEVENV_STATE}/clamav/db
DatabaseMirror database.clamav.net
'';
in "mkdir -p $DEVENV_STATE/clamav/db && ${pkgs.clamav}/bin/freshclam --config ${freshclam_config} || true; ${pkgs.clamav}/bin/clamd -c ${clamd_config}";
})
];
};
}) // {
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;
};
};
}