From b8dc89ae8128022a7aca7134f80bb29a662fa6c4 Mon Sep 17 00:00:00 2001 From: Toast <39011842+toast003@users.noreply.github.com> Date: Sat, 15 Nov 2025 03:35:58 +0100 Subject: [PATCH] Nix: build dependencies from source --- contrib/package/nix/copyparty/default.nix | 41 +++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/contrib/package/nix/copyparty/default.nix b/contrib/package/nix/copyparty/default.nix index 22ae5bcd..5557ab38 100644 --- a/contrib/package/nix/copyparty/default.nix +++ b/contrib/package/nix/copyparty/default.nix @@ -2,6 +2,9 @@ lib, buildPythonApplication, fetchurl, + runCommand, + compressDrvWeb, + pigz, util-linux, python, setuptools, @@ -20,6 +23,16 @@ partftpy, fusepy, # for partyfuse + # deps in /copyparty/web/deps + marked, + easy-mde, + busy-mp3, + copyparty-fonts, + asmcrypto, + hash-wasm, + prism, + fusepy-copyparty, + # use argon2id-hashed passwords in config files (sha2 is always available) withHashedPasswords ? true, @@ -72,6 +85,26 @@ let pinData = lib.importJSON ./pin.json; runtimeDeps = ([ util-linux ] ++ extraPackages ++ lib.optional withMediaProcessing ffmpeg); + + sitePackages = drv: "${drv.outPath}/lib/python${lib.versions.majorMinor python.version}/site-packages"; + nodeModules = drv: "${drv.outPath}/lib/node_modules"; + webDeps = runCommand "copyparty-webdeps" { + nativeBuildInputs = [ util-linux ]; + } '' + mkdir $out + cp --verbose -r --target-directory $out \ + ${copyparty-fonts}/* ${prism}/* \ + ${sitePackages fusepy-copyparty}/fuse.py \ + ${nodeModules easy-mde}/easymde/dist/* \ + ${nodeModules marked}/marked/marked.min.js + cp ${busy-mp3} $out/busy.mp3.gz + cp ${hash-wasm}/sha512.umd.min.js $out/sha512.hw.js + cp ${nodeModules asmcrypto}/@openpgp/asmcrypto.js/asmcrypto.all.es5.js $out/sha512.ac.js + rename -v ".min" "" $out/* + ''; + smolWebDeps = compressDrvWeb webDeps { + compressors.gz = "${lib.getExe pigz} -11 -I 2048 --force {}"; + }; in buildPythonApplication { pname = "copyparty"; @@ -103,6 +136,14 @@ buildPythonApplication { build-system = [ setuptools ]; + # Build webdeps when building from source + preBuild = lib.optionalString (true) '' + # TODO: remove this when we build this from source. + # This is just so that we can try this without building from source + rm -r copyparty/web/deps/* && touch copyparty/web/deps/__init__.py + + cp -vr ${smolWebDeps}/* copyparty/web/deps/ + ''; meta = { description = "Turn almost any device into a file server"; longDescription = ''