2024-04-29 18:09:38 +00:00
|
|
|
{ lib
|
|
|
|
, callPackage
|
|
|
|
, crystal
|
2024-08-25 20:19:00 +00:00
|
|
|
, fetchFromGitHub
|
2024-04-29 18:09:38 +00:00
|
|
|
, librsvg
|
|
|
|
, pkg-config
|
|
|
|
, libxml2
|
|
|
|
, openssl
|
|
|
|
, shards
|
|
|
|
, sqlite
|
|
|
|
, nixosTests
|
|
|
|
|
2022-03-13 10:35:06 +00:00
|
|
|
# All versions, revisions, and checksums are stored in ./versions.json.
|
|
|
|
# The update process is the following:
|
2024-04-29 18:00:20 +00:00
|
|
|
# * pick the latest tag
|
|
|
|
# * update .invidious.version, .invidious.date, .invidious.commit and .invidious.hash
|
2022-03-13 10:35:06 +00:00
|
|
|
# * prefetch the videojs dependencies with scripts/fetch-player-dependencies.cr
|
2024-02-19 12:24:48 +00:00
|
|
|
# and update .videojs.hash (they are normally fetched during build
|
2022-03-13 10:35:06 +00:00
|
|
|
# but nix's sandboxing does not allow that)
|
|
|
|
# * if shard.lock changed
|
|
|
|
# * recreate shards.nix by running crystal2nix
|
2024-04-29 18:09:38 +00:00
|
|
|
, versions ? lib.importJSON ./versions.json
|
|
|
|
}:
|
|
|
|
let
|
|
|
|
# normally video.js is downloaded at build time
|
|
|
|
videojs = callPackage ./videojs.nix { inherit versions; };
|
2019-08-26 19:13:57 +00:00
|
|
|
in
|
|
|
|
crystal.buildCrystalPackage rec {
|
|
|
|
pname = "invidious";
|
2024-04-29 17:35:26 +00:00
|
|
|
inherit (versions.invidious) version;
|
2019-08-26 19:13:57 +00:00
|
|
|
|
2024-08-25 20:19:00 +00:00
|
|
|
src = fetchFromGitHub {
|
2019-08-26 19:13:57 +00:00
|
|
|
owner = "iv-org";
|
2024-04-29 18:00:20 +00:00
|
|
|
repo = "invidious";
|
2022-06-05 12:44:58 +00:00
|
|
|
fetchSubmodules = true;
|
2024-04-29 18:09:38 +00:00
|
|
|
rev = versions.invidious.rev or "v${version}";
|
2024-04-29 17:35:26 +00:00
|
|
|
inherit (versions.invidious) hash;
|
2019-08-26 19:13:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
postPatch =
|
|
|
|
let
|
|
|
|
# Replacing by the value (templates) of the variables ensures that building
|
|
|
|
# fails if upstream changes the way the metadata is formatted.
|
|
|
|
branchTemplate = ''{{ "#{`git branch | sed -n '/* /s///p'`.strip}" }}'';
|
|
|
|
commitTemplate = ''{{ "#{`git rev-list HEAD --max-count=1 --abbrev-commit`.strip}" }}'';
|
|
|
|
versionTemplate = ''{{ "#{`git log -1 --format=%ci | awk '{print $1}' | sed s/-/./g`.strip}" }}'';
|
|
|
|
# This always uses the latest commit which invalidates the cache even if
|
|
|
|
# the assets were not changed
|
|
|
|
assetCommitTemplate = ''{{ "#{`git rev-list HEAD --max-count=1 --abbrev-commit -- assets`.strip}" }}'';
|
2024-04-29 18:00:20 +00:00
|
|
|
|
|
|
|
inherit (versions.invidious) commit date;
|
2019-08-26 19:13:57 +00:00
|
|
|
in
|
|
|
|
''
|
2022-01-15 16:24:18 +00:00
|
|
|
for d in ${videojs}/*; do ln -s "$d" assets/videojs; done
|
|
|
|
|
2019-08-26 19:13:57 +00:00
|
|
|
# Use the version metadata from the derivation instead of using git at
|
|
|
|
# build-time
|
|
|
|
substituteInPlace src/invidious.cr \
|
2024-04-26 22:54:27 +00:00
|
|
|
--replace-fail ${lib.escapeShellArg branchTemplate} '"master"' \
|
2024-04-29 18:00:20 +00:00
|
|
|
--replace-fail ${lib.escapeShellArg commitTemplate} '"${commit}"' \
|
|
|
|
--replace-fail ${lib.escapeShellArg versionTemplate} '"${date}"' \
|
|
|
|
--replace-fail ${lib.escapeShellArg assetCommitTemplate} '"${commit}"'
|
2019-08-26 19:13:57 +00:00
|
|
|
|
|
|
|
# Patch the assets and locales paths to be absolute
|
|
|
|
substituteInPlace src/invidious.cr \
|
2024-04-26 22:54:27 +00:00
|
|
|
--replace-fail 'public_folder "assets"' 'public_folder "${placeholder "out"}/share/invidious/assets"'
|
2019-08-26 19:13:57 +00:00
|
|
|
substituteInPlace src/invidious/helpers/i18n.cr \
|
2024-04-26 22:54:27 +00:00
|
|
|
--replace-fail 'File.read("locales/' 'File.read("${placeholder "out"}/share/invidious/locales/'
|
2019-08-26 19:13:57 +00:00
|
|
|
|
|
|
|
# Reference sql initialisation/migration scripts by absolute path
|
2022-01-15 16:24:18 +00:00
|
|
|
substituteInPlace src/invidious/database/base.cr \
|
2024-04-26 22:54:27 +00:00
|
|
|
--replace-fail 'config/sql' '${placeholder "out"}/share/invidious/config/sql'
|
2019-08-26 19:13:57 +00:00
|
|
|
|
2022-01-15 16:24:18 +00:00
|
|
|
substituteInPlace src/invidious/user/captcha.cr \
|
2024-04-26 22:54:27 +00:00
|
|
|
--replace-fail 'Process.run(%(rsvg-convert' 'Process.run(%(${lib.getBin librsvg}/bin/rsvg-convert'
|
2019-08-26 19:13:57 +00:00
|
|
|
'';
|
|
|
|
|
2022-01-15 16:24:18 +00:00
|
|
|
nativeBuildInputs = [ pkg-config shards ];
|
2019-08-26 19:13:57 +00:00
|
|
|
buildInputs = [ libxml2 openssl sqlite ];
|
|
|
|
|
|
|
|
format = "crystal";
|
|
|
|
shardsFile = ./shards.nix;
|
2022-01-15 16:24:18 +00:00
|
|
|
crystalBinaries.invidious = {
|
|
|
|
src = "src/invidious.cr";
|
2022-10-14 08:15:49 +00:00
|
|
|
options = [
|
|
|
|
"--release"
|
|
|
|
"--progress"
|
|
|
|
"--verbose"
|
|
|
|
"--no-debug"
|
|
|
|
"-Dskip_videojs_download"
|
|
|
|
];
|
2022-01-15 16:24:18 +00:00
|
|
|
};
|
2019-08-26 19:13:57 +00:00
|
|
|
|
|
|
|
postInstall = ''
|
|
|
|
mkdir -p $out/share/invidious/config
|
|
|
|
|
|
|
|
# Copy static parts
|
|
|
|
cp -r assets locales $out/share/invidious
|
|
|
|
cp -r config/sql $out/share/invidious/config
|
|
|
|
'';
|
|
|
|
|
2023-07-31 21:47:05 +00:00
|
|
|
# Invidious tries to open and validate config/config.yml, even when
|
|
|
|
# running --help. This specifies a minimal configuration in an
|
|
|
|
# environment variable. Even though the database and hmac_key are
|
|
|
|
# bogus, --help still works.
|
2019-08-26 19:13:57 +00:00
|
|
|
installCheckPhase = ''
|
2024-02-19 10:57:13 +00:00
|
|
|
export INVIDIOUS_CONFIG="$(cat <<EOF
|
2023-07-31 21:47:05 +00:00
|
|
|
database_url: sqlite3:///dev/null
|
|
|
|
hmac_key: "this-is-required"
|
|
|
|
EOF
|
2024-02-19 10:57:13 +00:00
|
|
|
)"
|
|
|
|
$out/bin/invidious --help
|
|
|
|
$out/bin/invidious --version
|
2019-08-26 19:13:57 +00:00
|
|
|
'';
|
|
|
|
|
2021-12-15 14:38:00 +00:00
|
|
|
passthru = {
|
|
|
|
tests = { inherit (nixosTests) invidious; };
|
|
|
|
updateScript = ./update.sh;
|
|
|
|
};
|
2019-08-26 19:13:57 +00:00
|
|
|
|
|
|
|
meta = with lib; {
|
|
|
|
description = "Open source alternative front-end to YouTube";
|
2024-03-19 02:14:51 +00:00
|
|
|
mainProgram = "invidious";
|
2019-08-26 19:13:57 +00:00
|
|
|
homepage = "https://invidious.io/";
|
2024-03-19 12:26:06 +00:00
|
|
|
license = licenses.agpl3Plus;
|
2024-04-29 22:09:06 +00:00
|
|
|
maintainers = with maintainers; [
|
|
|
|
_999eagle
|
|
|
|
GaetanLepage
|
|
|
|
sbruder
|
|
|
|
pbsds
|
|
|
|
];
|
2019-08-26 19:13:57 +00:00
|
|
|
};
|
|
|
|
}
|