From dbbba9625bc8cf79ad0c1f5982c7454e1f34b7c2 Mon Sep 17 00:00:00 2001 From: ed Date: Mon, 17 Apr 2023 13:17:53 +0200 Subject: [PATCH] nix: make deps optional + update docs --- .gitignore | 3 ++ README.md | 21 +++++++++- contrib/package/nix/copyparty/default.nix | 49 +++++++++++++++-------- scripts/toc.sh | 4 +- 4 files changed, 58 insertions(+), 19 deletions(-) diff --git a/.gitignore b/.gitignore index 0d646f50..7be5af78 100644 --- a/.gitignore +++ b/.gitignore @@ -21,6 +21,9 @@ copyparty.egg-info/ # winmerge *.bak +# apple pls +.DS_Store + # derived copyparty/res/COPYING.txt copyparty/web/deps/ diff --git a/README.md b/README.md index 24b9f47d..dcbfcfab 100644 --- a/README.md +++ b/README.md @@ -69,6 +69,8 @@ turn almost any device into a file server with resumable uploads/downloads using * [themes](#themes) * [complete examples](#complete-examples) * [reverse-proxy](#reverse-proxy) - running copyparty next to other websites + * [nix package](#nix-package) - `nix profile install github:9001/copyparty` + * [nixos module](#nixos-module) * [browser support](#browser-support) - TLDR: yes * [client examples](#client-examples) - interact with copyparty using non-browser clients * [folder sync](#folder-sync) - sync folders to/from copyparty @@ -101,8 +103,7 @@ just run **[copyparty-sfx.py](https://github.com/9001/copyparty/releases/latest/ * or install through pypi (python3 only): `python3 -m pip install --user -U copyparty` * or if you cannot install python, you can use [copyparty.exe](#copypartyexe) instead -* or install through nix: `nix profile install github:9001/copyparty` - * requires a [flake-enabled](https://nixos.wiki/wiki/Flakes) installation of nix +* or [install through nix](#nix-package), or [on NixOS](#nixos-module) * or if you are on android, [install copyparty in termux](#install-on-android) * or if you prefer to [use docker](./scripts/docker/) 🐋 you can do that too * docker has all deps built-in, so skip this step: @@ -1165,7 +1166,20 @@ example webserver configs: * [nginx config](contrib/nginx/copyparty.conf) -- entire domain/subdomain * [apache2 config](contrib/apache/copyparty.conf) -- location-based + +## nix package + +`nix profile install github:9001/copyparty` + +requires a [flake-enabled](https://nixos.wiki/wiki/Flakes) installation of nix + +some recommended dependencies are enabled by default; [override the package](https://github.com/9001/copyparty/blob/hovudstraum/contrib/package/nix/copyparty/default.nix#L3-L22) if you want to add/remove some features/deps + +`ffmpeg-full` was chosen over `ffmpeg-headless` mainly because we need `withWebp` (and `withOpenmpt` is also nice) and being able to use a cached build felt more important than optimizing for size at the time -- PRs welcome if you disagree 👍 + + ## nixos module + for this setup, you will need a [flake-enabled](https://nixos.wiki/wiki/Flakes) installation of NixOS. ```nix @@ -1254,6 +1268,9 @@ services.copyparty = { }; ``` +the passwordFile at /run/keys/copyparty/ could for example be generated by [agenix](https://github.com/ryantm/agenix), or you could just dump it in the nix store instead if that's acceptable + + # browser support TLDR: yes diff --git a/contrib/package/nix/copyparty/default.nix b/contrib/package/nix/copyparty/default.nix index c405f3fd..8171d69a 100644 --- a/contrib/package/nix/copyparty/default.nix +++ b/contrib/package/nix/copyparty/default.nix @@ -1,24 +1,41 @@ -{ lib, stdenv, makeWrapper, fetchurl, utillinux, python, jinja2, mutagen, pillow -, pyvips, pyftpdlib, pyopenssl, impacket, ffmpeg }: +{ lib, stdenv, makeWrapper, fetchurl, utillinux, python, jinja2, impacket, pyftpdlib, pyopenssl, pillow, pyvips, ffmpeg, mutagen, + +# create thumbnails with Pillow; faster than FFmpeg / MediaProcessing +withThumbnails ? true, + +# create thumbnails with PyVIPS; even faster, uses more memory +# -- can be combined with Pillow to support more filetypes +withFastThumbnails ? false, + +# enable FFmpeg; thumbnails for most filetypes (also video and audio), extract audio metadata, transcode audio to opus +# -- possibly dangerous if you allow anonymous uploads, since FFmpeg has a huge attack surface +# -- can be combined with Thumbnails and/or FastThumbnails, since FFmpeg is slower than both +withMediaProcessing ? true, + +# if MediaProcessing is not enabled, you probably want this instead (less accurate, but much safer and faster) +withBasicAudioMetadata ? false, + +# enable FTPS support in the FTP server +withFTPS ? false, + +# samba/cifs server; dangerous and buggy, enable if you really need it +withSMB ? false, + +}: let pinData = lib.importJSON ./pin.json; pyEnv = python.withPackages (ps: with ps; [ - # mandatory jinja2 - # thumbnails - pyvips - # alternative thumbnails, but not needed in the presence of pyvips and ffmpeg - # pillow pyheif-pillow-opener pillow-avif-plugin - # audio metadata - mutagen - # ftp server - pyftpdlib - pyopenssl - # smb server - impacket - ]); + ] + ++ lib.optional withSMB impacket + ++ lib.optional withFTPS pyopenssl + ++ lib.optional withThumbnails pillow + ++ lib.optional withFastThumbnails pyvips + ++ lib.optional withMediaProcessing ffmpeg + ++ lib.optional withBasicAudioMetadata mutagen + ); in stdenv.mkDerivation { pname = "copyparty"; version = pinData.version; @@ -32,7 +49,7 @@ in stdenv.mkDerivation { installPhase = '' install -Dm755 $src $out/share/copyparty-sfx.py makeWrapper ${pyEnv.interpreter} $out/bin/copyparty \ - --set PATH '${lib.makeBinPath [ utillinux ffmpeg ]}:$PATH' \ + --set PATH '${lib.makeBinPath ([ utillinux ] ++ lib.optional withMediaProcessing ffmpeg)}:$PATH' \ --add-flags "$out/share/copyparty-sfx.py" ''; } diff --git a/scripts/toc.sh b/scripts/toc.sh index 00fb299b..6b847033 100755 --- a/scripts/toc.sh +++ b/scripts/toc.sh @@ -16,7 +16,9 @@ cat $f | awk ' h=0 }; }; - /^#/{s=1;pr()} /^#* *(install on android|dev env setup|just the sfx|complete release|optional gpl stuff)|`$/{s=0} + /^#/{s=1;rs=0;pr()} + /^#* *(nix package)/{rs=1} + /^#* *(install on android|dev env setup|just the sfx|complete release|optional gpl stuff|nixos module)|`$/{s=rs} /^#/{ lv=length($1); sub(/[^ ]+ /,"");