aboutsummaryrefslogtreecommitdiffstats
path: root/nix
diff options
context:
space:
mode:
authorBenedikt Peetz <benedikt.peetz@b-peetz.de>2025-08-31 23:44:08 +0200
committerBenedikt Peetz <benedikt.peetz@b-peetz.de>2025-08-31 23:44:08 +0200
commit84d9a86be8ee216b47920ff3f98b567aa1d296c0 (patch)
treeec7fdb3a3ab0725b843225894e0535d3391d09a6 /nix
downloadserver-84d9a86be8ee216b47920ff3f98b567aa1d296c0.zip
chore: Initial commit
Diffstat (limited to 'nix')
-rw-r--r--nix/package.nix140
1 files changed, 140 insertions, 0 deletions
diff --git a/nix/package.nix b/nix/package.nix
new file mode 100644
index 0000000..a9e925d
--- /dev/null
+++ b/nix/package.nix
@@ -0,0 +1,140 @@
+# rocie - An enterprise grocery management system
+#
+# Copyright (C) 2024 Benedikt Peetz <benedikt.peetz@b-peetz.de>
+# Copyright (C) 2025 Benedikt Peetz <benedikt.peetz@b-peetz.de>
+# SPDX-License-Identifier: GPL-3.0-or-later
+#
+# This file is part of Rocie.
+#
+# You should have received a copy of the License along with this program.
+# If not, see <https://www.gnu.org/licenses/gpl-3.0.txt>.
+
+{
+ lib,
+ rustPlatform,
+ installShellFiles,
+ # buildInputs
+ mpv-unwrapped,
+ ffmpeg,
+ openssl,
+ libffi,
+ zlib,
+ curl,
+ # NativeBuildInputs
+ makeWrapper,
+ llvmPackages_latest,
+ glibc,
+ sqlite,
+ fd,
+ pkg-config,
+ SDL2,
+ python3,
+ # Passthru
+ tree-sitter-yts,
+}: let
+ python = python3.withPackages (ps: [ps.yt-dlp]);
+in
+ rustPlatform.buildRustPackage (finalAttrs: {
+ pname = "yt";
+ inherit
+ ((builtins.fromTOML (builtins.readFile
+ ../Cargo.toml)).workspace.package)
+ version
+ ;
+
+ src = lib.cleanSourceWith {
+ src = lib.cleanSource ./..;
+ filter = name: type:
+ (type == "directory")
+ || (builtins.elem (builtins.baseNameOf name) [
+ "Cargo.toml"
+ "Cargo.lock"
+ "mkdb.sh"
+ "help.str"
+ "raw_error_warning.txt"
+ "golden.txt"
+ ])
+ || (lib.strings.hasSuffix ".rs" (builtins.baseNameOf name))
+ || (lib.strings.hasSuffix ".h" (builtins.baseNameOf name))
+ || (lib.strings.hasSuffix ".sql" (builtins.baseNameOf name));
+ };
+
+ nativeBuildInputs = [
+ installShellFiles
+ makeWrapper
+ sqlite
+ fd
+ pkg-config
+ ];
+
+ buildInputs = [
+ mpv-unwrapped.dev
+ ffmpeg
+ openssl
+ libffi
+ zlib
+ curl.dev
+ python
+ ];
+
+ checkInputs = [
+ # Needed for the tests in `libmpv2`
+ SDL2
+ ];
+
+ env = let
+ clang_version =
+ lib.versions.major
+ llvmPackages_latest.clang-unwrapped.version;
+ in {
+ # Needed for the compile time sqlite checks.
+ DATABASE_URL = "sqlite://database.sqlx";
+
+ # Required by yt_dlp
+ FFMPEG_LOCATION = "${lib.getExe ffmpeg}";
+
+ # Tell pyo3 which python to use.
+ PYO3_PYTHON = lib.getExe python;
+
+ # Needed for the libmpv2.
+ C_INCLUDE_PATH = "${glibc.dev}/include";
+ LIBCLANG_INCLUDE_PATH = "${llvmPackages_latest.clang-unwrapped.lib}/lib/clang/${clang_version}/include";
+ LIBCLANG_PATH = "${llvmPackages_latest.clang-unwrapped.lib}/lib/libclang.so";
+ };
+
+ doCheck = true;
+ checkFlags = [
+ # All of these tests try to connect to the internet to download test data.
+ "--skip=select::base::test_base"
+ "--skip=select::file::test_file"
+ "--skip=select::options::test_options"
+ "--skip=subscriptions::import_export::test_import_export"
+ "--skip=subscriptions::naming_subscriptions::test_naming_subscriptions"
+ "--skip=videos::downloading::test_downloading"
+ ];
+
+ prePatch = ''
+ # Generate the sqlite db, so that we can run the comp-time sqlite checks.
+ bash ./scripts/mkdb.sh
+ '';
+
+ passthru = {
+ inherit tree-sitter-yts;
+ };
+
+ cargoLock = {
+ lockFile = ../Cargo.lock;
+ };
+
+ postInstall = ''
+ installShellCompletion --cmd yt \
+ --bash <(COMPLETE=bash $out/bin/yt) \
+ --fish <(COMPLETE=fish $out/bin/yt) \
+ --zsh <(COMPLETE=zsh $out/bin/yt)
+
+ # NOTE: We cannot clear the path, because we need access to the $EDITOR. <2025-04-04>
+ wrapProgram $out/bin/yt \
+ --prefix PATH : ${lib.makeBinPath finalAttrs.buildInputs} \
+ --set YTDLP_NO_PLUGINS 1
+ '';
+ })