| 1 | { stdenv, lib, rustPlatform, runCommand, nodejs_24, pnpm_11, fetchPnpmDeps, pnpmConfigHook, sqlite, openssl, pkg-config, dockerTools, coreutils, callPackage, python3, yt-dlp, ffmpeg }: |
| 2 | let |
| 3 | nativePkl = callPackage ./pkl.nix { }; |
| 4 | youtubePython = python3.withPackages (packages: [ packages.pyyaml ]); |
| 5 | source = lib.fileset.toSource { |
| 6 | root = ../.; |
| 7 | fileset = lib.fileset.unions [ |
| 8 | ../config |
| 9 | ../service |
| 10 | ]; |
| 11 | }; |
| 12 | web = stdenv.mkDerivation (finalAttrs: { |
| 13 | pname = "home-dashboard-web"; |
| 14 | version = "0.1.0"; |
| 15 | src = lib.fileset.toSource { |
| 16 | root = ../.; |
| 17 | fileset = lib.fileset.unions [ |
| 18 | ../dashboard/web ../dashboard/vendor ../dashboard/package.json ../dashboard/pnpm-lock.yaml ../dashboard/pnpm-workspace.yaml |
| 19 | ../dashboard/tsconfig.json ../dashboard/vite.config.ts |
| 20 | ../dashboard/src/claude.svg ../dashboard/src/openai.svg |
| 21 | ]; |
| 22 | }; |
| 23 | sourceRoot = "source/dashboard"; |
| 24 | pnpmDeps = fetchPnpmDeps { |
| 25 | inherit (finalAttrs) pname version src sourceRoot; |
| 26 | pnpm = pnpm_11; |
| 27 | fetcherVersion = 3; |
| 28 | hash = "sha256-GLXA5XkcKIPZD2g2xBUejjpPJcupbNOL6YYujv1FB5A="; |
| 29 | }; |
| 30 | nativeBuildInputs = [ nodejs_24 pnpm_11 pnpmConfigHook ]; |
| 31 | buildPhase = "pnpm run build"; |
| 32 | installPhase = "cp -r dist $out"; |
| 33 | }); |
| 34 | server = rustPlatform.buildRustPackage { |
| 35 | pname = "home-dashboard-server"; |
| 36 | version = "0.1.0"; |
| 37 | src = lib.fileset.toSource { |
| 38 | root = ../dashboard; |
| 39 | fileset = lib.fileset.unions [ |
| 40 | ../dashboard/src ../dashboard/web/sso ../dashboard/ai ../dashboard/tests ../dashboard/Cargo.toml ../dashboard/Cargo.lock |
| 41 | ]; |
| 42 | }; |
| 43 | cargoLock.lockFile = ../dashboard/Cargo.lock; |
| 44 | nativeBuildInputs = [ pkg-config ]; |
| 45 | nativeCheckInputs = [ python3 openssl ]; |
| 46 | buildInputs = [ sqlite openssl ]; |
| 47 | LIBSQLITE3_SYS_USE_PKG_CONFIG = "1"; |
| 48 | }; |
| 49 | dashboard = runCommand "home-dashboard-0.1.0" { |
| 50 | passthru.image = dockerTools.buildLayeredImage { |
| 51 | name = "snowglobe-dashboard"; |
| 52 | contents = [ dashboard coreutils nativePkl youtubePython yt-dlp ffmpeg dockerTools.caCertificates ]; |
| 53 | config = { |
| 54 | User = "65534:65534"; |
| 55 | Cmd = [ "${dashboard}/bin/home-dashboard" ]; |
| 56 | WorkingDir = "${dashboard}/lib/home-dashboard"; |
| 57 | Env = [ |
| 58 | "SNOWGLOBE_LISTEN_ADDRESS=0.0.0.0" "PORT=7072" |
| 59 | "SNOWGLOBE_PROXY_TOKEN_FILE=/run/secrets/dashboard-proxy.token" |
| 60 | "SNOWGLOBE_REPO=${source}" |
| 61 | "SNOWGLOBE_YT_PYTHON=${youtubePython}/bin/python3" |
| 62 | "PATH=${lib.makeBinPath [ coreutils nativePkl youtubePython yt-dlp ffmpeg ]}" |
| 63 | ]; |
| 64 | }; |
| 65 | }; |
| 66 | } '' |
| 67 | mkdir -p $out/bin $out/lib/home-dashboard |
| 68 | ln -s ${server}/bin/home-dashboard $out/bin/home-dashboard |
| 69 | ln -s ${web} $out/lib/home-dashboard/dist |
| 70 | ln -s ${../dashboard/server} $out/lib/home-dashboard/server |
| 71 | ''; |
| 72 | in dashboard |