invidious: init at unstable-2021-10-15

This also adds a derivation for lsquic, but places it inside invidious’
directory. That is because lsquic.cr (the library used by invidious)
requires a specific lsquic version that is probably not useful for other
derivations.

Co-authored-by: Simon Bruder <simon@sbruder.de>

authored by Silvan Mosberger Simon Bruder and committed by Simon Bruder c5286421 c6064b7c

+230
+99
pkgs/servers/invidious/default.nix
···
··· 1 + { lib, crystal, fetchFromGitHub, librsvg, pkg-config, libxml2, openssl, sqlite, lsquic, nixosTests }: 2 + let 3 + # When updating, always update the following: 4 + # * the git revision 5 + # * the version attribute 6 + # * the source hash (sha256) 7 + # If the shards.lock file changed, also the following: 8 + # * shards.nix (by running `crystal2nix` in invidious’ source tree) 9 + # * If the lsquic.cr dependency changed: lsquic in lsquic.nix (version, sha256) 10 + # * If the lsquic version changed: boringssl' in lsquic.nix (version, sha256) 11 + rev = "21b96a31599e890fe063e3e24cf5f3a995779a69"; 12 + in 13 + crystal.buildCrystalPackage rec { 14 + pname = "invidious"; 15 + version = "unstable-2021-10-15"; 16 + 17 + src = fetchFromGitHub { 18 + owner = "iv-org"; 19 + repo = pname; 20 + inherit rev; 21 + sha256 = "sha256-Rp3YqjHbP6szohlaEpgopFNdLK31yrcHtyKCeVz76CA="; 22 + }; 23 + 24 + postPatch = 25 + let 26 + # Replacing by the value (templates) of the variables ensures that building 27 + # fails if upstream changes the way the metadata is formatted. 28 + branchTemplate = ''{{ "#{`git branch | sed -n '/* /s///p'`.strip}" }}''; 29 + commitTemplate = ''{{ "#{`git rev-list HEAD --max-count=1 --abbrev-commit`.strip}" }}''; 30 + versionTemplate = ''{{ "#{`git log -1 --format=%ci | awk '{print $1}' | sed s/-/./g`.strip}" }}''; 31 + # This always uses the latest commit which invalidates the cache even if 32 + # the assets were not changed 33 + assetCommitTemplate = ''{{ "#{`git rev-list HEAD --max-count=1 --abbrev-commit -- assets`.strip}" }}''; 34 + in 35 + '' 36 + # Use the version metadata from the derivation instead of using git at 37 + # build-time 38 + substituteInPlace src/invidious.cr \ 39 + --replace ${lib.escapeShellArg branchTemplate} '"master"' \ 40 + --replace ${lib.escapeShellArg commitTemplate} '"${lib.substring 0 7 rev}"' \ 41 + --replace ${lib.escapeShellArg versionTemplate} '"${lib.replaceChars ["-"] ["."] (lib.substring 9 10 version)}"' \ 42 + --replace ${lib.escapeShellArg assetCommitTemplate} '"${lib.substring 0 7 rev}"' 43 + 44 + # Patch the assets and locales paths to be absolute 45 + substituteInPlace src/invidious.cr \ 46 + --replace 'public_folder "assets"' 'public_folder "${placeholder "out"}/share/invidious/assets"' 47 + substituteInPlace src/invidious/helpers/i18n.cr \ 48 + --replace 'File.read("locales/' 'File.read("${placeholder "out"}/share/invidious/locales/' 49 + 50 + # Reference sql initialisation/migration scripts by absolute path 51 + substituteInPlace src/invidious/helpers/helpers.cr \ 52 + --replace 'config/sql' '${placeholder "out"}/share/invidious/config/sql' 53 + 54 + substituteInPlace src/invidious/users.cr \ 55 + --replace 'Process.run(%(rsvg-convert' 'Process.run(%(${lib.getBin librsvg}/bin/rsvg-convert' 56 + ''; 57 + 58 + nativeBuildInputs = [ pkg-config ]; 59 + buildInputs = [ libxml2 openssl sqlite ]; 60 + 61 + format = "crystal"; 62 + shardsFile = ./shards.nix; 63 + crystalBinaries.invidious.src = "src/invidious.cr"; 64 + 65 + postConfigure = '' 66 + # lib includes nix store paths which can’t be patched, so the links have to 67 + # be dereferenced first. 68 + cp -rL lib lib2 69 + rm -r lib 70 + mv lib2 lib 71 + chmod +w -R lib 72 + cp ${lsquic}/lib/liblsquic.a lib/lsquic/src/lsquic/ext 73 + ''; 74 + 75 + postInstall = '' 76 + mkdir -p $out/share/invidious/config 77 + 78 + # Copy static parts 79 + cp -r assets locales $out/share/invidious 80 + cp -r config/sql $out/share/invidious/config 81 + ''; 82 + 83 + # Invidious tries to open config/config.yml and connect to the database, even 84 + # when running --help. This specifies a minimal configuration in an 85 + # environment variable. Even though the database is bogus, --help still 86 + # works. 87 + installCheckPhase = '' 88 + INVIDIOUS_CONFIG="database_url: sqlite3:///dev/null" $out/bin/invidious --help 89 + ''; 90 + 91 + passthru.tests = { inherit (nixosTests) invidious; }; 92 + 93 + meta = with lib; { 94 + description = "An open source alternative front-end to YouTube"; 95 + homepage = "https://invidious.io/"; 96 + license = licenses.agpl3; 97 + maintainers = with maintainers; [ infinisil sbruder ]; 98 + }; 99 + }
+58
pkgs/servers/invidious/lsquic.nix
···
··· 1 + { lib, boringssl, stdenv, fetchgit, fetchFromGitHub, cmake, zlib, perl, libevent }: 2 + let 3 + # lsquic requires a specific boringssl version (noted in its README) 4 + boringssl' = boringssl.overrideAttrs (old: rec { 5 + version = "251b5169fd44345f455438312ec4e18ae07fd58c"; 6 + src = fetchgit { 7 + url = "https://boringssl.googlesource.com/boringssl"; 8 + rev = version; 9 + sha256 = "sha256-EU6T9yQCdOLx98Io8o01rEsgxDFF/Xoy42LgPopD2/A="; 10 + }; 11 + }); 12 + in 13 + stdenv.mkDerivation rec { 14 + pname = "lsquic"; 15 + version = "2.18.1"; 16 + 17 + src = fetchFromGitHub { 18 + owner = "litespeedtech"; 19 + repo = pname; 20 + rev = "v${version}"; 21 + sha256 = "sha256-hG8cUvhbCNeMOsKkaJlgGpzUrIx47E/WhmPIdI5F3qM="; 22 + fetchSubmodules = true; 23 + }; 24 + 25 + nativeBuildInputs = [ cmake perl ]; 26 + buildInputs = [ boringssl' libevent zlib ]; 27 + 28 + cmakeFlags = [ 29 + "-DBORINGSSL_DIR=${boringssl'}" 30 + "-DBORINGSSL_LIB_crypto=${boringssl'}/lib/libcrypto.a" 31 + "-DBORINGSSL_LIB_ssl=${boringssl'}/lib/libssl.a" 32 + "-DZLIB_LIB=${zlib}/lib/libz.so" 33 + ]; 34 + 35 + # adapted from lsquic.cr’s Dockerfile 36 + # (https://github.com/iv-org/lsquic.cr/blob/master/docker/Dockerfile) 37 + installPhase = '' 38 + runHook preInstall 39 + 40 + mkdir combinedlib 41 + cd combinedlib 42 + ar -x ${boringssl'}/lib/libssl.a 43 + ar -x ${boringssl'}/lib/libcrypto.a 44 + ar -x ../src/liblsquic/liblsquic.a 45 + ar rc liblsquic.a *.o 46 + ranlib liblsquic.a 47 + install -D liblsquic.a $out/lib/liblsquic.a 48 + 49 + runHook postInstall 50 + ''; 51 + 52 + meta = with lib; { 53 + description = "A library for QUIC and HTTP/3 (version for Invidious)"; 54 + homepage = "https://github.com/litespeedtech/lsquic"; 55 + maintainers = with maintainers; [ infinisil sbruder ]; 56 + license = with licenses; [ openssl isc mit bsd3 ]; # statically links against boringssl, so has to include its licenses 57 + }; 58 + }
+68
pkgs/servers/invidious/shards.nix
···
··· 1 + { 2 + athena-negotiation = { 3 + owner = "athena-framework"; 4 + repo = "negotiation"; 5 + rev = "v0.1.1"; 6 + sha256 = "1vkk59lqrxb0l8kyzs114i3c18zb2bdiah2xhazkk8q7x6fz4yzk"; 7 + }; 8 + backtracer = { 9 + owner = "sija"; 10 + repo = "backtracer.cr"; 11 + rev = "v1.2.1"; 12 + sha256 = "02r1l7rn2wsljkx495s5s7j04zgn73m2kx0hkzs7620camvlwbqq"; 13 + }; 14 + db = { 15 + owner = "crystal-lang"; 16 + repo = "crystal-db"; 17 + rev = "v0.10.1"; 18 + sha256 = "03c5h14z6h2mxnx949lihnyqjd19hcj38iasdwq9fp95h8cld376"; 19 + }; 20 + exception_page = { 21 + owner = "crystal-loot"; 22 + repo = "exception_page"; 23 + rev = "v0.2.0"; 24 + sha256 = "0nlgnh5iykbr1v2132342k2mz6s2laws6nkgqsqlwhhcr4gb4jcx"; 25 + }; 26 + kemal = { 27 + owner = "kemalcr"; 28 + repo = "kemal"; 29 + rev = "v1.1.0"; 30 + sha256 = "07vlvddy4mba9li2bvskzqzywwq55cyvlgkz13q6dsl4zfgc96ca"; 31 + }; 32 + kilt = { 33 + owner = "jeromegn"; 34 + repo = "kilt"; 35 + rev = "v0.6.1"; 36 + sha256 = "0dpc15y9m8c5l9zdfif6jlf7zmkrlm9w4m2igi5xa22fdjwamwfp"; 37 + }; 38 + lsquic = { 39 + owner = "iv-org"; 40 + repo = "lsquic.cr"; 41 + rev = "v2.18.1-2"; 42 + sha256 = "0bljk0pwbjb813dfwrhgi00w2ai09k868xvak4hfzdkbmpc7id6y"; 43 + }; 44 + pg = { 45 + owner = "will"; 46 + repo = "crystal-pg"; 47 + rev = "v0.24.0"; 48 + sha256 = "07i5bqkv5j6y6f8v5cpqdxc5wzzrvgv3ds24znv4mzv6nc84csn4"; 49 + }; 50 + protodec = { 51 + owner = "iv-org"; 52 + repo = "protodec"; 53 + rev = "v0.1.4"; 54 + sha256 = "15azh9izxqgwpgkpicmivfdz31wkibnwy09rwhxsg0lyc4wf8xj9"; 55 + }; 56 + radix = { 57 + owner = "luislavena"; 58 + repo = "radix"; 59 + rev = "v0.4.1"; 60 + sha256 = "1l08cydkdidq9yyil1wl240hvk41iycv04jrg6nx5mkvzw4z1bzg"; 61 + }; 62 + sqlite3 = { 63 + owner = "crystal-lang"; 64 + repo = "crystal-sqlite3"; 65 + rev = "v0.18.0"; 66 + sha256 = "03nnvpchhq9f9ywsm3pk2rrj4a3figw7xs96zdziwgr5znkz6x93"; 67 + }; 68 + }
+5
pkgs/top-level/all-packages.nix
··· 6401 6402 intermodal = callPackage ../tools/misc/intermodal { }; 6403 6404 invoice2data = callPackage ../tools/text/invoice2data { }; 6405 6406 inxi = callPackage ../tools/system/inxi { };
··· 6401 6402 intermodal = callPackage ../tools/misc/intermodal { }; 6403 6404 + invidious = callPackage ../servers/invidious { 6405 + # needs a specific version of lsquic 6406 + lsquic = callPackage ../servers/invidious/lsquic.nix { }; 6407 + }; 6408 + 6409 invoice2data = callPackage ../tools/text/invoice2data { }; 6410 6411 inxi = callPackage ../tools/system/inxi { };