diff options
Diffstat (limited to 'pkgs/by-name/au')
-rw-r--r-- | pkgs/by-name/au/audiobookshelf/package.nix | 80 | ||||
-rw-r--r-- | pkgs/by-name/au/audiobookshelf/source.json | 9 | ||||
-rwxr-xr-x | pkgs/by-name/au/audiobookshelf/update.nu | 30 | ||||
-rw-r--r-- | pkgs/by-name/au/audiobookshelf/wrapper.nix | 61 |
4 files changed, 180 insertions, 0 deletions
diff --git a/pkgs/by-name/au/audiobookshelf/package.nix b/pkgs/by-name/au/audiobookshelf/package.nix new file mode 100644 index 0000000000000..01d49a5fee690 --- /dev/null +++ b/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/pkgs/by-name/au/audiobookshelf/source.json b/pkgs/by-name/au/audiobookshelf/source.json new file mode 100644 index 0000000000000..74a3875871706 --- /dev/null +++ b/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/pkgs/by-name/au/audiobookshelf/update.nu b/pkgs/by-name/au/audiobookshelf/update.nu new file mode 100755 index 0000000000000..25166c9cf1d11 --- /dev/null +++ b/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/pkgs/by-name/au/audiobookshelf/wrapper.nix b/pkgs/by-name/au/audiobookshelf/wrapper.nix new file mode 100644 index 0000000000000..787ee5ac49178 --- /dev/null +++ b/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" \'' |