about summary refs log tree commit diff
path: root/nixpkgs/pkgs/by-name/au/audiobookshelf
diff options
context:
space:
mode:
Diffstat (limited to 'nixpkgs/pkgs/by-name/au/audiobookshelf')
-rw-r--r--nixpkgs/pkgs/by-name/au/audiobookshelf/package.nix80
-rw-r--r--nixpkgs/pkgs/by-name/au/audiobookshelf/source.json9
-rwxr-xr-xnixpkgs/pkgs/by-name/au/audiobookshelf/update.nu30
-rw-r--r--nixpkgs/pkgs/by-name/au/audiobookshelf/wrapper.nix61
4 files changed, 180 insertions, 0 deletions
diff --git a/nixpkgs/pkgs/by-name/au/audiobookshelf/package.nix b/nixpkgs/pkgs/by-name/au/audiobookshelf/package.nix
new file mode 100644
index 000000000000..01d49a5fee69
--- /dev/null
+++ b/nixpkgs/pkgs/by-name/au/audiobookshelf/package.nix
@@ -0,0 +1,80 @@
+{
+  lib,
+  stdenv,
+  fetchFromGitHub,
+  runCommand,
+  buildNpmPackage,
+  nodejs_18,
+  tone,
+  ffmpeg-full,
+  util-linux,
+  python3,
+  getopt
+}:
+
+let
+  nodejs = nodejs_18;
+
+  source = builtins.fromJSON (builtins.readFile ./source.json);
+  pname = "audiobookshelf";
+
+  src = fetchFromGitHub {
+    owner = "advplyr";
+    repo = pname;
+    rev = "refs/tags/v${source.version}";
+    inherit (source) hash;
+  };
+
+  client = buildNpmPackage {
+    pname = "${pname}-client";
+    inherit (source) version;
+
+    src = runCommand "cp-source" {} ''
+      cp -r ${src}/client $out
+    '';
+
+    NODE_OPTIONS = "--openssl-legacy-provider";
+
+    npmBuildScript = "generate";
+    npmDepsHash = source.clientDepsHash;
+  };
+
+  wrapper = import ./wrapper.nix {
+    inherit stdenv ffmpeg-full tone pname nodejs getopt;
+  };
+
+in buildNpmPackage {
+  inherit pname src;
+  inherit (source) version;
+
+  buildInputs = [ util-linux ];
+  nativeBuildInputs = [ python3 ];
+
+  dontNpmBuild = true;
+  npmInstallFlags = [ "--only-production" ];
+  npmDepsHash = source.depsHash;
+
+  installPhase = ''
+    mkdir -p $out/opt/client
+    cp -r index.js server package* node_modules $out/opt/
+    cp -r ${client}/lib/node_modules/${pname}-client/dist $out/opt/client/dist
+    mkdir $out/bin
+
+    echo '${wrapper}' > $out/bin/${pname}
+    echo "  exec ${nodejs}/bin/node $out/opt/index.js" >> $out/bin/${pname}
+
+    chmod +x $out/bin/${pname}
+  '';
+
+  passthru.updateScript = ./update.nu;
+
+  meta = with lib; {
+    homepage = "https://www.audiobookshelf.org/";
+    description = "Self-hosted audiobook and podcast server";
+    changelog = "https://github.com/advplyr/audiobookshelf/releases/tag/v${source.version}";
+    license = licenses.gpl3;
+    maintainers = [ maintainers.jvanbruegge maintainers.adamcstephens ];
+    platforms = platforms.linux;
+    mainProgram = "audiobookshelf";
+  };
+}
diff --git a/nixpkgs/pkgs/by-name/au/audiobookshelf/source.json b/nixpkgs/pkgs/by-name/au/audiobookshelf/source.json
new file mode 100644
index 000000000000..74a387587170
--- /dev/null
+++ b/nixpkgs/pkgs/by-name/au/audiobookshelf/source.json
@@ -0,0 +1,9 @@
+{
+  "owner": "advplyr",
+  "repo": "audiobookshelf",
+  "rev": "90f4833c9e0957f08799af15966d1909516b335e",
+  "hash": "sha256-m+CwUV3Bu9sHvRKCA1vFXYYRx48bxZ8N3BornO1tLQ0=",
+  "version": "2.7.2",
+  "depsHash": "sha256-1623oXtkOp43xQvHI3GbJpEQLvgr5WD5FpfNO+d0RR8=",
+  "clientDepsHash": "sha256-ugf9C/L5aBTO7gCy561kV06Ihb/mg/ZW916NKngIYXI="
+}
diff --git a/nixpkgs/pkgs/by-name/au/audiobookshelf/update.nu b/nixpkgs/pkgs/by-name/au/audiobookshelf/update.nu
new file mode 100755
index 000000000000..25166c9cf1d1
--- /dev/null
+++ b/nixpkgs/pkgs/by-name/au/audiobookshelf/update.nu
@@ -0,0 +1,30 @@
+#!/usr/bin/env nix-shell
+#!nix-shell -i nu -p nushell common-updater-scripts prefetch-npm-deps
+
+def main [] {
+  let sourceFile = $"(pwd)/pkgs/by-name/au/audiobookshelf/source.json"
+  let tags = list-git-tags --url=https://github.com/advplyr/audiobookshelf | lines | sort --natural | str replace v ''
+
+  let latest_tag = $tags | last
+  let current_version = open $sourceFile | get version
+
+  if $latest_tag != $current_version {
+    let source = nix-prefetch-github advplyr audiobookshelf --rev $"v($latest_tag)" | from json | merge { version: $latest_tag, depsHash: "", clientDepsHash: ""}
+    $source | save --force $sourceFile
+
+    let srcPath = nix-build $env.PWD -A audiobookshelf.src | complete | get stdout | lines | first
+
+    print $srcPath
+    ls $srcPath
+
+    $source | merge {
+      depsHash: (prefetch-npm-deps $"($srcPath)/package-lock.json"),
+      clientDepsHash: (prefetch-npm-deps $"($srcPath)/client/package-lock.json")
+    } | save --force $sourceFile
+
+    # appease the editorconfig CI check
+    echo "\n" | save --append $sourceFile
+  }
+
+  {before: $current_version, after: $latest_tag}
+}
diff --git a/nixpkgs/pkgs/by-name/au/audiobookshelf/wrapper.nix b/nixpkgs/pkgs/by-name/au/audiobookshelf/wrapper.nix
new file mode 100644
index 000000000000..787ee5ac4917
--- /dev/null
+++ b/nixpkgs/pkgs/by-name/au/audiobookshelf/wrapper.nix
@@ -0,0 +1,61 @@
+{ stdenv, ffmpeg-full, tone, pname, nodejs, getopt }: ''
+    #!${stdenv.shell}
+
+    port=8000
+    host=0.0.0.0
+    config=$(pwd)/config
+    metadata=$(pwd)/metadata
+
+    LONGOPTS=host:,port:,config:,metadata:,help
+    args=$(${getopt}/bin/getopt -l "$LONGOPTS" -o h -- "$@")
+
+    eval set -- "$args"
+
+    while [ $# -ge 1 ]; do
+      case "$1" in
+        --)
+          # No more options left.
+          shift
+          break
+          ;;
+        --host)
+          host="$2"
+          shift
+          ;;
+        --port)
+          port="$2"
+          shift
+          ;;
+        --config)
+          if [[ "''${2:0:1}" = "/" ]]; then
+            config="$2"
+          else
+            config="$(pwd)/$2"
+          fi
+          shift
+          ;;
+        --metadata)
+          if [[ "''${2:0:1}" = "/" ]]; then
+            metadata="$2"
+          else
+            metadata="$(pwd)/$2"
+          fi
+          shift
+          ;;
+        --help|-h)
+          echo "Usage: audiobookshelf [--host <host>] [--port <port>] [--metadata <dir>] [--config <dir>]"
+          exit 0
+          ;;
+      esac
+      shift
+    done
+
+    NODE_ENV=production \
+      SOURCE=nixpkgs \
+      FFMPEG_PATH=${ffmpeg-full}/bin/ffmpeg \
+      FFPROBE_PATH=${ffmpeg-full}/bin/ffprobe \
+      TONE_PATH=${tone}/bin/tone \
+      CONFIG_PATH="$config" \
+      METADATA_PATH="$metadata" \
+      PORT="$port" \
+      HOST="$host" \''