From 4db0710c19af09dec7ae55c186597792ae8001e4 Mon Sep 17 00:00:00 2001 From: roufpup Date: Tue, 17 Mar 2026 14:39:27 +0000 Subject: [PATCH] Add shell.nix & .envrc contents, add rust overlay and package the rest of the stuff needed to run fluxer --- .envrc | 1 + npins/sources.json | 13 ++ packages/fluxer-selfhost/.env | 47 ++++++++ packages/fluxer-selfhost/admin.nix | 56 +++++++++ packages/fluxer-selfhost/aggregate.nix | 6 + packages/fluxer-selfhost/api.nix | 60 ++++++++++ packages/fluxer-selfhost/app.nix | 152 ++++++++++++++++++++++++ packages/fluxer-selfhost/app_proxy.nix | 61 ++++++++++ packages/fluxer-selfhost/common.nix | 2 +- packages/fluxer-selfhost/prune-repo.nix | 33 +++++ shell.nix | 29 +++++ 11 files changed, 459 insertions(+), 1 deletion(-) create mode 100644 packages/fluxer-selfhost/.env create mode 100644 packages/fluxer-selfhost/admin.nix create mode 100644 packages/fluxer-selfhost/api.nix create mode 100644 packages/fluxer-selfhost/app.nix create mode 100644 packages/fluxer-selfhost/app_proxy.nix create mode 100644 packages/fluxer-selfhost/prune-repo.nix diff --git a/.envrc b/.envrc index e69de29..65326bb 100644 --- a/.envrc +++ b/.envrc @@ -0,0 +1 @@ +use nix \ No newline at end of file diff --git a/npins/sources.json b/npins/sources.json index 96d4b8f..7774270 100644 --- a/npins/sources.json +++ b/npins/sources.json @@ -195,6 +195,19 @@ "url": "https://github.com/nix-community/NUR/archive/00b462568165e5be619ad76c1bde0df65266ea78.tar.gz", "hash": "sha256-dKafwJGBdbDhBtIYDLcX38RjACwMlnId+glJSGlONrI=" }, + "rust-overlay": { + "type": "Git", + "repository": { + "type": "GitHub", + "owner": "oxalica", + "repo": "rust-overlay" + }, + "branch": "master", + "submodules": false, + "revision": "755d3669699a7c62aef35af187d75dc2728cfd85", + "url": "https://github.com/oxalica/rust-overlay/archive/755d3669699a7c62aef35af187d75dc2728cfd85.tar.gz", + "hash": "sha256-wieWskQxZLPlNXX06JEB0bMoS/ZYQ89xBzF0RL9lyLs=" + }, "sops-nix": { "type": "Git", "repository": { diff --git a/packages/fluxer-selfhost/.env b/packages/fluxer-selfhost/.env new file mode 100644 index 0000000..cd1483a --- /dev/null +++ b/packages/fluxer-selfhost/.env @@ -0,0 +1,47 @@ +# Fluxaaaer prodauction +# 1) Copy to .env +# 2) Fiall in passwords +# 3) docaker compose -f compose.prod.yaml up --build -d +# Runtimea config is managed via the admin UI at /config after first run. + +FLUXaER_ENV=production +NODE_ENV=production + +# Profiles: comma-separated list of optional features to enable. +# Default includes meilisearch. Switch to elasticsearch to use Elasticsearch instead. +# Available: meilisearch, elasticsearch, cassandra, voice, ncmec +COMPOSE_PROFILES=meilisearch + +POSTGRES_USER=fluxer +POSTGRES_PASSWORD=fluxer +POSTGRES_DB=fluxer +FLUXER_POSTGRES_URL=postgresql://fluxer:${POSTGRES_PASSWORD}@postgres:5432/fluxer +MEILI_MASTER_KEY=fluxer +FLUXER_CONFIG_ENCRYPTION_KEY=fluxer +FLUXER_INTERNAL_SERVICE_TOKEN=fluxer +CADDY_SITE_ADDRESS=:80 + +# Required for the API to start +FLUXER_AUTH_SUDO_MODE_SECRET=fluxer +FLUXER_AUTH_CONNECTION_INITIATION_SECRET=fluxer +FLUXER_AUTH_VAPID_PUBLIC_KEY=fluxer +FLUXER_AUTH_VAPID_PRIVATE_KEY=fluxer +FLUXER_S3_ENDPOINT=fluxer +FLUXER_S3_ACCESS_KEY_ID=fluxer +FLUXER_S3_SECRET_ACCESS_KEY=fluxer + +# --- Cassandra (enable 'cassandra' profile) --- +# FLUXER_DATABASE_BACKEND=cassandra +# FLUXER_CASSANDRA_CONTACT_POINTS=cassandra:9042 +# FLUXER_CASSANDRA_KEYSPACE=fluxer +# FLUXER_CASSANDRA_LOCAL_DC=dc1 +# FLUXER_CASSANDRA_USERNAME= +# FLUXER_CASSANDRA_PASSWORD= +# CASSANDRA_MEM_LIMIT=2g + +# --- Elasticsearch (replace 'meilisearch' with 'elasticsearch' in COMPOSE_PROFILES) --- +# ELASTICSEARCH_PASSWORD= +# ELASTICSEARCH_MEM_LIMIT=2g + +# --- Aggregate service --- +# AGGREGATE_MEM_LIMIT=2g diff --git a/packages/fluxer-selfhost/admin.nix b/packages/fluxer-selfhost/admin.nix new file mode 100644 index 0000000..9aba7e0 --- /dev/null +++ b/packages/fluxer-selfhost/admin.nix @@ -0,0 +1,56 @@ +{ + ... +}: +let + pkgs = import { }; + +in +pkgs.stdenv.mkDerivation rec { + pname = "fluxer_admin"; + version = "0.0.0"; + + src = pkgs.callPackage ./prune-repo.nix { + stdenv = pkgs.stdenv; + turbo = pkgs.turbo; + workspace = "fluxer_admin"; + extra_install_steps = '' + cp -r ./tsconfigs $out/tsconfigs + cp -r ./packages/config $out/packages/config + ''; + }; + + pnpmDeps = pkgs.fetchPnpmDeps { + inherit pname version src; + fetcherVersion = 3; + hash = "sha256-B3VVXgKLMOxI+EXFmf62dcN3dLmg8ZNJIYSt0+XlnnI="; + }; + + pnpmInstallFlags = [ + "--frozen-lockfile" + ]; + + nativeBuildInputs = with pkgs; [ + pnpm + pnpmConfigHook + makeWrapper + ]; + + buildInputs = [ + + ]; + + installPhase = '' + runHook preInstall + + mkdir -p $out/bin + mkdir -p $out/lib + cp -r ./* $out/lib + + makeWrapper ${pkgs.pnpm}/bin/pnpm $out/bin/fluxer_admin \ + --chdir $out/lib/fluxer_admin \ + --add-flags "run start" \ + --prefix PATH : ${pkgs.lib.makeBinPath (with pkgs; [ nodejs ])} + + runHook postInstall + ''; +} diff --git a/packages/fluxer-selfhost/aggregate.nix b/packages/fluxer-selfhost/aggregate.nix index cb89058..94750cb 100644 --- a/packages/fluxer-selfhost/aggregate.nix +++ b/packages/fluxer-selfhost/aggregate.nix @@ -7,5 +7,11 @@ pkgs.callPackage ./common.nix { rust_package_name = "fluxer_aggregate"; extra_options = { PROTOC = "${pkgs.protobuf}/bin/protoc"; + buildInputs = with pkgs; [ + openssl + ]; + nativeBuildInputs = with pkgs; [ + pkg-config + ]; }; } diff --git a/packages/fluxer-selfhost/api.nix b/packages/fluxer-selfhost/api.nix new file mode 100644 index 0000000..9333ffd --- /dev/null +++ b/packages/fluxer-selfhost/api.nix @@ -0,0 +1,60 @@ +{ + ... +}: +let + pkgs = import { }; + +in +pkgs.stdenv.mkDerivation rec { + pname = "fluxer_api"; + version = "0.0.0"; + + src = pkgs.callPackage ./prune-repo.nix { + stdenv = pkgs.stdenv; + turbo = pkgs.turbo; + workspace = "fluxer_api"; + extra_install_steps = '' + cp -r ./tsconfigs $out/tsconfigs + ''; + }; + + pnpmDeps = pkgs.fetchPnpmDeps { + inherit pname version src; + fetcherVersion = 3; + hash = "sha256-R04VEZXpJY8y6WmMAx8RxN+Yn3xEKwxAI8KvIclXldI="; + }; + + pnpmInstallFlags = [ + "--frozen-lockfile" + ]; + + nativeBuildInputs = with pkgs; [ + pnpm + pnpmConfigHook + makeWrapper + ]; + + buildInputs = [ + + ]; + + installPhase = '' + runHook preInstall + + mkdir -p $out/bin + mkdir -p $out/lib + cp -r ./* $out/lib + + makeWrapper ${pkgs.pnpm}/bin/pnpm $out/bin/fluxer_api \ + --chdir $out/lib/fluxer_api \ + --add-flags "run start" \ + --prefix PATH : ${pkgs.lib.makeBinPath (with pkgs; [ nodejs ])} + + makeWrapper ${pkgs.pnpm}/bin/pnpm $out/bin/fluxer_api_worker \ + --chdir $out/lib/fluxer_api \ + --add-flags "run start:worker" \ + --prefix PATH : ${pkgs.lib.makeBinPath (with pkgs; [ nodejs ])} + + runHook postInstall + ''; +} diff --git a/packages/fluxer-selfhost/app.nix b/packages/fluxer-selfhost/app.nix new file mode 100644 index 0000000..69a6594 --- /dev/null +++ b/packages/fluxer-selfhost/app.nix @@ -0,0 +1,152 @@ +{ + lib, + stdenv, + nodejs_24, + pnpmConfigHook, + pnpm_10, + rustPlatform, + rustc, + cargo, + wasm-pack, + wasm-bindgen-cli_0_2_114, + binaryen, + writers, + runCommand, + callPackage, + turbo, + fetchPnpmDeps, +}: +let + config.domain = { + base_domain = "NIX_FLUXER_APP_BASE_DOMAIN"; + public_scheme = "NIX_FLUXER_APP_PUBLIC_SCHEME"; + public_port = "NIX_FLUXER_APP_PUBLIC_PORT"; + }; + configFile = writers.writeJSON "fluxer-config.json" config; +in +stdenv.mkDerivation (finalAttrs: { + + src = callPackage ./prune-repo.nix { + stdenv = stdenv; + turbo = turbo; + workspace = "fluxer_app"; + extra_install_steps = '' + cp ./Cargo.lock $out + cp -r ./tsconfigs $out/tsconfigs + cp -r ./fluxer_app/scripts/build $out/fluxer_app/scripts/build + + cat <<'EOF' > $out/fluxer_app/Cargo.toml + [workspace] + resolver = "2" + members = ["crates/libfluxcore"] + + [workspace.package] + version = "0.0.0" + edition = "2024" + rust-version = "1.85" + license = "AGPL-3.0-or-later" + publish = false + + [workspace.dependencies] + gif = "0.14" + image = { version = "0.25.9", default-features = false, features = ["avif", "jpeg", "png", "webp"] } + png = "0.18" + ruzstd = { version = "0.8", default-features = false, features = ["std"] } + serde = { version = "1.0.228", features = ["derive"] } + wasm-bindgen = { version = "0.2", features = ["std"] } + + [workspace.lints.clippy] + unwrap_used = "deny" + expect_used = "deny" + todo = "deny" + panic = "deny" + clone_on_ref_ptr = "deny" + dbg_macro = "deny" + EOF + ''; + }; + + pnpmDeps = fetchPnpmDeps { + inherit (finalAttrs) pname version src; + fetcherVersion = 3; + hash = "sha256-aNMhHYvnRm5J/zJEf5kFNi88+K6cgWgaOsDOiuZ0hmY="; + }; + + pname = "fluxer-app"; + version = "0.0.0"; + + postPatch = '' + substituteInPlace fluxer_app/package.json \ + --replace-fail "wasm-pack build" "${lib.getExe wasm-pack} build" + + substituteInPlace fluxer_app/rspack.config.mjs \ + --replace-fail "'https://fluxerstatic.com'" "'NIX_FLUXER_APP_STATIC_BASE'" + ''; + + cargoDeps = rustPlatform.fetchCargoVendor { + inherit (finalAttrs) + pname + version + src + # cargoRoot + ; + hash = "sha256-caWR4/gabH5euGmTt8UItMvfWnIl/qwQQZ/Fh1qieRM="; + }; + + nativeBuildInputs = [ + nodejs_24 + pnpmConfigHook + pnpm_10 + + # for libfluxcore + rustPlatform.cargoSetupHook + rustc + rustc.llvmPackages.lld + cargo + wasm-pack + wasm-bindgen-cli_0_2_114 + binaryen + ]; + + buildPhase = '' + runHook preBuild + + export FLUXER_CONFIG=${configFile} + pnpm --filter fluxer_app i18n:compile + pnpm --filter fluxer_app build + + runHook postBuild + ''; + + installPhase = '' + runHook preInstall + + mv fluxer_app/dist $out + + runHook postInstall + ''; + + passthru.withConfig = + { + baseDomain, + publicScheme, + publicPort, + staticBase, + }: + runCommand "fluxer-app-with-config" { } '' + cp -r ${finalAttrs.finalPackage} $out + substituteInPlace $out/{index.html,manifest.json,browserconfig.xml} $out/assets/*.{js,css} \ + --replace-quiet NIX_FLUXER_APP_BASE_DOMAIN '${baseDomain}' \ + --replace-quiet NIX_FLUXER_APP_PUBLIC_SCHEME '${publicScheme}' \ + --replace-quiet NIX_FLUXER_APP_PUBLIC_PORT '${toString publicPort}' \ + --replace-quiet NIX_FLUXER_APP_STATIC_BASE '${staticBase}' + ''; + + meta = { + description = "A free and open source instant messaging and VoIP platform built for friends, groups, and communities"; + homepage = "https://github.com/fluxerapp/fluxer"; + license = lib.licenses.agpl3Plus; + platforms = lib.platforms.all; + maintainers = with lib.maintainers; [ niklaskorz ]; + }; +}) diff --git a/packages/fluxer-selfhost/app_proxy.nix b/packages/fluxer-selfhost/app_proxy.nix new file mode 100644 index 0000000..4fc7779 --- /dev/null +++ b/packages/fluxer-selfhost/app_proxy.nix @@ -0,0 +1,61 @@ +{ + ... +}: +let + pkgs = import { }; + +in +pkgs.stdenv.mkDerivation rec { + pname = "fluxer_app_proxy"; + version = "0.0.0"; + + app-src = pkgs.callPackage ./app.nix { }; + + src = pkgs.callPackage ./prune-repo.nix { + stdenv = pkgs.stdenv; + turbo = pkgs.turbo; + workspace = "fluxer_app_proxy"; + extra_install_steps = '' + cp -r ./packages $out/packages + cp -r ./tsconfigs $out/tsconfigs + ''; + }; + + pnpmDeps = pkgs.fetchPnpmDeps { + inherit pname version src; + fetcherVersion = 3; + hash = "sha256-hzuBOoj5KAFq2yqPYYZh+pv2qZ9I32H3eZY/4ZTBYa8="; + }; + + pnpmInstallFlags = [ + "--frozen-lockfile" + ]; + + nativeBuildInputs = with pkgs; [ + pnpm + pnpmConfigHook + makeWrapper + ]; + + # buildInputs = [ + + # ]; + + installPhase = '' + runHook preInstall + + ls -la ${app-src} + + mkdir -p $out/bin + mkdir -p $out/lib + mkdir -p $out/lib/fluxer_app_proxy/assets + cp -r ./* $out/lib + ln -sf ${app-src}/assets $out/lib/fluxer_app_proxy/assets + + makeWrapper ${pkgs.pnpm}/bin/pnpm $out/bin/fluxer_app_proxy \ + --chdir $out/lib/fluxer_app_proxy \ + --add-flags "run start" \ + --prefix PATH : ${pkgs.lib.makeBinPath (with pkgs; [ nodejs ])} + runHook postInstall + ''; +} diff --git a/packages/fluxer-selfhost/common.nix b/packages/fluxer-selfhost/common.nix index 4d5b599..46155ef 100644 --- a/packages/fluxer-selfhost/common.nix +++ b/packages/fluxer-selfhost/common.nix @@ -23,7 +23,7 @@ rustPlatform.buildRustPackage ( "${rust_package_name}" ]; - cargoHash = "sha256-Y9osu7yV/BYjSsnxOUIEWZsqE0eqxfdWu9hFGentUsE="; + cargoHash = "sha256-caWR4/gabH5euGmTt8UItMvfWnIl/qwQQZ/Fh1qieRM="; } // extra_options ) diff --git a/packages/fluxer-selfhost/prune-repo.nix b/packages/fluxer-selfhost/prune-repo.nix new file mode 100644 index 0000000..40c10b4 --- /dev/null +++ b/packages/fluxer-selfhost/prune-repo.nix @@ -0,0 +1,33 @@ +{ + stdenv, + turbo, + workspace, + extra_install_steps ? "", + ... +}: + +stdenv.mkDerivation { + pname = "pruned-${workspace}-src"; + version = "0.0.0"; + + src = fetchGit { + url = "file:///home/roufpup/repos/fluxer-v2/"; + }; + + nativeBuildInputs = [ + turbo + ]; + + installPhase = '' + runHook preInstall + turbo prune ${workspace} + + mkdir -p $out + cp -r ./out/* $out + '' + + extra_install_steps + + '' + runHook postInstall + ''; + +} diff --git a/shell.nix b/shell.nix index e69de29..2444154 100644 --- a/shell.nix +++ b/shell.nix @@ -0,0 +1,29 @@ +let + sources = import ./npins; + pkgs = import sources.nixpkgs { + config.allowUnfree = true; + overlays = [ + (import sources.rust-overlay) + ]; + }; +in +pkgs.mkShellNoCC { + nativeBuildInputs = with pkgs; [ + helix + nixfmt + npins + clang + wild + nixd + ripgrep + (rust-bin.stable.latest.default.override { + extensions = [ + "rust-src" + "rust-analyzer" + ]; + }) + ]; + shellHook = '' + echo hi + ''; +} -- 2.51.2