| 1 | { stdenv, lib, rustPlatform, runCommand, nodejs_24, pnpm_10, fetchPnpmDeps, pnpmConfigHook, sqlite, 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 = ../dashboard; |
| 19 | fileset = lib.fileset.unions [ |
| 20 | ../dashboard/web ../dashboard/package.json ../dashboard/pnpm-lock.yaml |
| 21 | ../dashboard/tsconfig.json ../dashboard/vite.config.ts |
| 22 | ]; |
| 23 | }; |
| 24 | pnpmDeps = fetchPnpmDeps { |
| 25 | inherit (finalAttrs) pname version src; |
| 26 | pnpm = pnpm_10; |
| 27 | fetcherVersion = 3; |
| 28 | hash = "sha256-xQbdTZIAiwM7Ox+6BsTD57LEJzj10hvqYEpA03W9OGs="; |
| 29 | }; |
| 30 | nativeBuildInputs = [ nodejs_24 pnpm_10 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/tests ../dashboard/Cargo.toml ../dashboard/Cargo.lock |
| 41 | ]; |
| 42 | }; |
| 43 | cargoLock.lockFile = ../dashboard/Cargo.lock; |
| 44 | nativeBuildInputs = [ pkg-config ]; |
| 45 | buildInputs = [ sqlite ]; |
| 46 | LIBSQLITE3_SYS_USE_PKG_CONFIG = "1"; |
| 47 | }; |
| 48 | dashboard = runCommand "home-dashboard-0.1.0" { |
| 49 | passthru.image = dockerTools.buildLayeredImage { |
| 50 | name = "studio-dashboard"; |
| 51 | contents = [ dashboard coreutils nativePkl youtubePython yt-dlp ffmpeg dockerTools.caCertificates ]; |
| 52 | config = { |
| 53 | User = "65534:65534"; |
| 54 | Cmd = [ "${dashboard}/bin/home-dashboard" ]; |
| 55 | WorkingDir = "${dashboard}/lib/home-dashboard"; |
| 56 | Env = [ |
| 57 | "STUDIO_LISTEN_ADDRESS=0.0.0.0" "PORT=7072" |
| 58 | "STUDIO_PROXY_TOKEN_FILE=/run/secrets/dashboard-proxy.token" |
| 59 | "STUDIO_REPO=${source}" |
| 60 | "STUDIO_YT_PYTHON=${youtubePython}/bin/python3" |
| 61 | "PATH=${lib.makeBinPath [ coreutils nativePkl youtubePython yt-dlp ffmpeg ]}" |
| 62 | ]; |
| 63 | }; |
| 64 | }; |
| 65 | } '' |
| 66 | mkdir -p $out/bin $out/lib/home-dashboard |
| 67 | ln -s ${server}/bin/home-dashboard $out/bin/home-dashboard |
| 68 | ln -s ${web} $out/lib/home-dashboard/dist |
| 69 | ln -s ${../dashboard/server} $out/lib/home-dashboard/server |
| 70 | ''; |
| 71 | in dashboard |