aboutsummaryrefslogtreecommitdiff
path: root/pkgs/applications/video
diff options
context:
space:
mode:
authormidchildan <git@midchildan.org>2020-10-04 20:38:11 +0900
committermidchildan <git@midchildan.org>2020-10-20 23:18:03 +0900
commit323b47d96e26963c0a3d7aa4724af88c02096e32 (patch)
treec511ff4bd126c54a1471161d1561b4a3f36ec33e /pkgs/applications/video
parent038afc6906b71d3d4a8dc9fea271b68b01cffd5f (diff)
epgstation: add updateScript
Diffstat (limited to 'pkgs/applications/video')
-rw-r--r--pkgs/applications/video/epgstation/default.nix163
-rwxr-xr-xpkgs/applications/video/epgstation/generate.sh34
-rw-r--r--pkgs/applications/video/epgstation/update.nix66
3 files changed, 166 insertions, 97 deletions
diff --git a/pkgs/applications/video/epgstation/default.nix b/pkgs/applications/video/epgstation/default.nix
index e57f46c8c6ad..6a2876c1ed7e 100644
--- a/pkgs/applications/video/epgstation/default.nix
+++ b/pkgs/applications/video/epgstation/default.nix
@@ -1,6 +1,27 @@
-{ stdenv, fetchFromGitHub, makeWrapper, bash, nodejs, nodePackages, gzip }:
+{ stdenv
+, fetchFromGitHub
+, common-updater-scripts
+, genericUpdater
+, writers
+, makeWrapper
+, bash
+, nodejs
+, nodePackages
+, gzip
+, jq
+}:
let
+ # NOTE: use updateScript to bump the package version
+ pname = "EPGStation";
+ version = "1.7.4";
+ src = fetchFromGitHub {
+ owner = "l3tnun";
+ repo = "EPGStation";
+ rev = "v${version}";
+ sha256 = "15z1kdbamj97frp3dfnbm0h8krihmv2xdab4id0rxin29ibrw1k2";
+ };
+
workaround-opencollective-buildfailures = stdenv.mkDerivation {
# FIXME: This should be removed when a complete fix is available
# https://github.com/svanderburg/node2nix/issues/145
@@ -12,67 +33,73 @@ let
chmod +x $out/bin/opencollective-postinstall
'';
};
-in
-nodePackages.epgstation.override (drv: {
- src = fetchFromGitHub {
- owner = "l3tnun";
- repo = "EPGStation";
- rev = "v${drv.version}"; # version specified in ./generate.sh
- sha256 = "15z1kdbamj97frp3dfnbm0h8krihmv2xdab4id0rxin29ibrw1k2";
- };
- buildInputs = [ bash ];
- nativeBuildInputs = [
- workaround-opencollective-buildfailures
- makeWrapper
- nodePackages.node-pre-gyp
- ];
-
- preRebuild = ''
- # Fix for not being able to connect to mysql using domain sockets.
- patch -p1 ${./use-mysql-over-domain-socket.patch}
- '';
-
- postInstall = let
- runtimeDeps = [ nodejs bash ];
- in
- ''
- mkdir -p $out/{bin,libexec,share/doc/epgstation,share/man/man1}
-
- pushd $out/lib/node_modules/EPGStation
-
- npm run build
- npm prune --production
-
- mv config/{enc.sh,enc.js} $out/libexec
- mv LICENSE Readme.md $out/share/doc/epgstation
- mv doc/* $out/share/doc/epgstation
- sed 's/@DESCRIPTION@/${drv.meta.description}/g' ${./epgstation.1} \
- | ${gzip}/bin/gzip > $out/share/man/man1/epgstation.1.gz
- rm -rf doc
-
- # just log to stdout and let journald do its job
- rm -rf logs
-
- # Replace the existing configuration and runtime state directories with
- # symlinks. Without this, they would all be non-writable because they reside
- # in the Nix store. Note that the source path won't be accessible at build
- # time.
- rm -r config data recorded thumbnail
- ln -sfT /etc/epgstation config
- ln -sfT /var/lib/epgstation data
- ln -sfT /var/lib/epgstation/recorded recorded
- ln -sfT /var/lib/epgstation/thumbnail thumbnail
-
- makeWrapper ${nodejs}/bin/npm $out/bin/epgstation \
- --run "cd $out/lib/node_modules/EPGStation" \
- --prefix PATH : ${stdenv.lib.makeBinPath runtimeDeps}
-
- popd
- '';
-
- meta = with stdenv.lib; drv.meta // {
- maintainers = with maintainers; [ midchildan ];
+ pkg = nodePackages.epgstation.override (drv: {
+ inherit src;
+
+ buildInputs = [ bash ];
+ nativeBuildInputs = [
+ workaround-opencollective-buildfailures
+ makeWrapper
+ nodePackages.node-pre-gyp
+ ];
+
+ preRebuild = ''
+ # Fix for not being able to connect to mysql using domain sockets.
+ patch -p1 ${./use-mysql-over-domain-socket.patch}
+ '';
+
+ postInstall = let
+ runtimeDeps = [ nodejs bash ];
+ in
+ ''
+ mkdir -p $out/{bin,libexec,share/doc/epgstation,share/man/man1}
+
+ pushd $out/lib/node_modules/EPGStation
+
+ npm run build
+ npm prune --production
+
+ mv config/{enc.sh,enc.js} $out/libexec
+ mv LICENSE Readme.md $out/share/doc/epgstation
+ mv doc/* $out/share/doc/epgstation
+ sed 's/@DESCRIPTION@/${drv.meta.description}/g' ${./epgstation.1} \
+ | ${gzip}/bin/gzip > $out/share/man/man1/epgstation.1.gz
+ rm -rf doc
+
+ # just log to stdout and let journald do its job
+ rm -rf logs
+
+ # Replace the existing configuration and runtime state directories with
+ # symlinks. Without this, they would all be non-writable because they
+ # reside in the Nix store. Note that the source path won't be accessible
+ # at build time.
+ rm -r config data recorded thumbnail
+ ln -sfT /etc/epgstation config
+ ln -sfT /var/lib/epgstation data
+ ln -sfT /var/lib/epgstation/recorded recorded
+ ln -sfT /var/lib/epgstation/thumbnail thumbnail
+
+ makeWrapper ${nodejs}/bin/npm $out/bin/epgstation \
+ --run "cd $out/lib/node_modules/EPGStation" \
+ --prefix PATH : ${stdenv.lib.makeBinPath runtimeDeps}
+
+ popd
+ '';
+
+ # NOTE: this may take a while since it has to update all packages in
+ # nixpkgs.nodePackages
+ passthru.updateScript = import ./update.nix {
+ inherit (stdenv) lib;
+ inherit (src.meta) homepage;
+ inherit
+ pname
+ version
+ common-updater-scripts
+ genericUpdater
+ writers
+ jq;
+ };
# nodePackages.epgstation is a stub package to fetch npm dependencies and
# is marked as broken to prevent users from installing it directly. This
@@ -80,6 +107,16 @@ nodePackages.epgstation.override (drv: {
# nixpkgs while still allowing us to heavily customize the build. It also
# allows us to provide devDependencies for the epgstation build process
# without doing the same for all the other node packages.
- broken = false;
+ meta = drv.meta // { broken = false; };
+ });
+in
+pkg // {
+ name = "${pname}-${version}";
+
+ meta = with stdenv.lib; pkg.meta // {
+ maintainers = with maintainers; [ midchildan ];
+
+ # NOTE: updateScript relies on this being correct
+ position = toString ./default.nix + ":1";
};
-})
+}
diff --git a/pkgs/applications/video/epgstation/generate.sh b/pkgs/applications/video/epgstation/generate.sh
deleted file mode 100755
index d193a015064c..000000000000
--- a/pkgs/applications/video/epgstation/generate.sh
+++ /dev/null
@@ -1,34 +0,0 @@
-#!/usr/bin/env bash
-
-# Script to generate the Nix package definition for EPGStation. Run this script
-# when bumping the package version.
-
-VERSION="1.7.4"
-URL="https://raw.githubusercontent.com/l3tnun/EPGStation/v$VERSION/package.json"
-JQ_BIN="$(nix-build ../../../.. --no-out-link -A jq)/bin/jq"
-
-set -eu -o pipefail
-cd "$(dirname "${BASH_SOURCE[0]}")"
-
-main() {
- # update package.json
- curl -sSfL "$URL" \
- | jq '. + {"dependencies": (.devDependencies + .dependencies)} | del(.devDependencies)' \
- > package.json
-
- # regenerate node packages to update the actual Nix package
- pushd ../../../development/node-packages \
- && ./generate.sh
- popd
-
- # generate default streaming settings for EPGStation
- pushd ../../../../nixos/modules/services/video/epgstation \
- && cat "$(./generate)" > streaming.json
- popd
-}
-
-jq() {
- "$JQ_BIN" "$@"
-}
-
-main "@"
diff --git a/pkgs/applications/video/epgstation/update.nix b/pkgs/applications/video/epgstation/update.nix
new file mode 100644
index 000000000000..9faa83c64f9e
--- /dev/null
+++ b/pkgs/applications/video/epgstation/update.nix
@@ -0,0 +1,66 @@
+{ pname
+, version
+, homepage
+, lib
+, common-updater-scripts
+, genericUpdater
+, writers
+, jq
+}:
+
+let
+ updater = genericUpdater {
+ inherit pname version;
+ attrPath = lib.toLower pname;
+ rev-prefix = "v";
+ versionLister = "${common-updater-scripts}/bin/list-git-tags ${homepage}";
+ };
+ updateScript = builtins.elemAt updater 0;
+ updateArgs = map (lib.escapeShellArg) (builtins.tail updater);
+in writers.writeBash "update-epgstation" ''
+ set -euxo pipefail
+
+ # bump the version
+ ${updateScript} ${lib.concatStringsSep " " updateArgs}
+
+ cd "${toString ./.}"
+
+ # Get the path to the latest source. Note that we can't just pass the value
+ # of epgstation.src directly because it'd be evaluated before we can run
+ # updateScript.
+ SRC="$(nix-build ../../../.. --no-out-link -A epgstation.src)"
+ if [[ "${version}" == "$(${jq}/bin/jq -r .version "$SRC/package.json")" ]]; then
+ echo "[INFO] Already using the latest version of ${pname}" >&2
+ exit
+ fi
+
+ # Regenerate package.json from the latest source.
+ ${jq}/bin/jq '. + {
+ dependencies: (.dependencies + .devDependencies),
+ } | del(.devDependencies, .main, .scripts)' \
+ "$SRC/package.json" \
+ > package.json
+
+ # Regenerate node packages to update the pre-overriden epgstation derivation.
+ # This must come *after* package.json has been regenerated.
+ pushd ../../../development/node-packages
+ ./generate.sh
+ popd
+
+ # Generate default streaming settings for the nixos module.
+ pushd ../../../../nixos/modules/services/video/epgstation
+ ${jq}/bin/jq '
+ { liveHLS
+ , liveMP4
+ , liveWebM
+ , mpegTsStreaming
+ , mpegTsViewer
+ , recordedDownloader
+ , recordedStreaming
+ , recordedHLS
+ , recordedViewer
+ }' \
+ "$SRC/config/config.sample.json" \
+ > streaming.json
+ popd
+''