| 1 | { stdenv, lib, rustPlatform, runCommand, nodejs_24, pnpm_10, 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 | (lib.fileset.difference ../service (lib.fileset.unions |
| 10 | (builtins.filter builtins.pathExists (map (name: ../service + "/${name}") |
| 11 | (builtins.fromJSON (builtins.readFile ../config/excluded-services.json)))))) |
| 12 | ]; |
| 13 | }; |
| 14 | web = stdenv.mkDerivation (finalAttrs: { |
| 15 | pname = "home-dashboard-web"; |
| 16 | version = "0.1.0"; |
| 17 | src = lib.fileset.toSource { |
| 18 | root = ../.; |
| 19 | fileset = lib.fileset.unions [ |
| 20 | ../dashboard/web ../dashboard/vendor ../dashboard/package.json ../dashboard/pnpm-lock.yaml |
| 21 | ../dashboard/tsconfig.json ../dashboard/vite.config.ts |
| 22 | ]; |
| 23 | }; |
| 24 | sourceRoot = "source/dashboard"; |
| 25 | pnpmDeps = fetchPnpmDeps { |
| 26 | inherit (finalAttrs) pname version src sourceRoot; |
| 27 | pnpm = pnpm_10; |
| 28 | fetcherVersion = 3; |
| 29 | hash = "sha256-zux7++pfJ9YJAMPjnvW94Z2m884Ypnc6BK9iHJxRFnA="; |
| 30 | }; |
| 31 | nativeBuildInputs = [ nodejs_24 pnpm_10 pnpmConfigHook ]; |
| 32 | buildPhase = "pnpm run build"; |
| 33 | installPhase = "cp -r dist $out"; |
| 34 | }); |
| 35 | server = rustPlatform.buildRustPackage { |
| 36 | pname = "home-dashboard-server"; |
| 37 | version = "0.1.0"; |
| 38 | src = lib.fileset.toSource { |
| 39 | root = ../dashboard; |
| 40 | fileset = lib.fileset.unions [ |
| 41 | ../dashboard/src ../dashboard/web/sso/github.svg ../dashboard/ai ../dashboard/tests ../dashboard/Cargo.toml ../dashboard/Cargo.lock |
| 42 | ../dashboard/agent/install.sh ../dashboard/agent/install.ps1 |
| 43 | ]; |
| 44 | }; |
| 45 | cargoLock.lockFile = ../dashboard/Cargo.lock; |
| 46 | nativeBuildInputs = [ pkg-config ]; |
| 47 | buildInputs = [ sqlite openssl ]; |
| 48 | LIBSQLITE3_SYS_USE_PKG_CONFIG = "1"; |
| 49 | }; |
| 50 | dashboard = runCommand "home-dashboard-0.1.0" { |
| 51 | passthru.image = dockerTools.buildLayeredImage { |
| 52 | name = "studio-dashboard"; |
| 53 | contents = [ dashboard coreutils nativePkl youtubePython yt-dlp ffmpeg dockerTools.caCertificates ]; |
| 54 | config = { |
| 55 | User = "65534:65534"; |
| 56 | Cmd = [ "${dashboard}/bin/home-dashboard" ]; |
| 57 | WorkingDir = "${dashboard}/lib/home-dashboard"; |
| 58 | Env = [ |
| 59 | "STUDIO_LISTEN_ADDRESS=0.0.0.0" "PORT=7072" |
| 60 | "STUDIO_PROXY_TOKEN_FILE=/run/secrets/dashboard-proxy.token" |
| 61 | "STUDIO_REPO=${source}" |
| 62 | "STUDIO_YT_PYTHON=${youtubePython}/bin/python3" |
| 63 | "PATH=${lib.makeBinPath [ coreutils nativePkl youtubePython yt-dlp ffmpeg ]}" |
| 64 | ]; |
| 65 | }; |
| 66 | }; |
| 67 | } '' |
| 68 | mkdir -p $out/bin $out/lib/home-dashboard |
| 69 | ln -s ${server}/bin/home-dashboard $out/bin/home-dashboard |
| 70 | ln -s ${web} $out/lib/home-dashboard/dist |
| 71 | ln -s ${../dashboard/server} $out/lib/home-dashboard/server |
| 72 | ln -s ${../dashboard/agent} $out/lib/home-dashboard/agent |
| 73 | ''; |
| 74 | in dashboard |