Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions nixos/modules/services/video/epgstation/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,11 @@ in
options.services.epgstation = {
enable = lib.mkEnableOption (lib.mdDoc description);

package = lib.mkOption {
default = pkgs.epgstation;
type = lib.types.package;
defaultText = lib.literalExpression "pkgs.epgstation";
description = lib.mdDoc "epgstation package to use";
package = lib.mkPackageOptionMD pkgs "epgstation" { };

ffmpeg = lib.mkPackageOptionMD pkgs "ffmpeg" {
default = [ "ffmpeg-headless" ];
example = "pkgs.ffmpeg-full";
};

usePreconfiguredStreaming = lib.mkOption {
Expand Down Expand Up @@ -278,6 +278,8 @@ in
package = lib.mkDefault pkgs.mariadb;
ensureDatabases = [ cfg.database.name ];
# FIXME: enable once mysqljs supports auth_socket
# https://github.com/mysqljs/mysql/issues/1507
#
# ensureUsers = [ {
# name = username;
# ensurePermissions = { "${cfg.database.name}.*" = "ALL PRIVILEGES"; };
Expand All @@ -295,8 +297,8 @@ in
database = cfg.database.name;
};

ffmpeg = lib.mkDefault "${pkgs.ffmpeg-full}/bin/ffmpeg";
ffprobe = lib.mkDefault "${pkgs.ffmpeg-full}/bin/ffprobe";
ffmpeg = lib.mkDefault "${cfg.ffmpeg}/bin/ffmpeg";
ffprobe = lib.mkDefault "${cfg.ffmpeg}/bin/ffprobe";

# for disambiguation with TypeScript files
recordedFileExtension = lib.mkDefault ".m2ts";
Expand All @@ -308,9 +310,15 @@ in
];

systemd.tmpfiles.rules = [
"d '/var/lib/epgstation/key' - ${username} ${groupname} - -"
"d '/var/lib/epgstation/streamfiles' - ${username} ${groupname} - -"
"d '/var/lib/epgstation/drop' - ${username} ${groupname} - -"
"d '/var/lib/epgstation/recorded' - ${username} ${groupname} - -"
"d '/var/lib/epgstation/thumbnail' - ${username} ${groupname} - -"
"d '/var/lib/epgstation/db/subscribers' - ${username} ${groupname} - -"
"d '/var/lib/epgstation/db/migrations/mysql' - ${username} ${groupname} - -"
"d '/var/lib/epgstation/db/migrations/postgres' - ${username} ${groupname} - -"
"d '/var/lib/epgstation/db/migrations/sqlite' - ${username} ${groupname} - -"
];

systemd.services.epgstation = {
Expand Down
57 changes: 0 additions & 57 deletions pkgs/applications/video/epgstation/client/package.json

This file was deleted.

140 changes: 66 additions & 74 deletions pkgs/applications/video/epgstation/default.nix
Original file line number Diff line number Diff line change
@@ -1,86 +1,93 @@
{ lib
, stdenv
, fetchpatch
, fetchFromGitHub
, buildNpmPackage
, installShellFiles
, makeWrapper
, bash
, nodejs
, gzip
, callPackage
, python3
}:

let
# NOTE: use updateScript to bump the package version
pname = "EPGStation";
buildNpmPackage rec {
pname = "epgstation";
version = "2.6.20";

src = fetchFromGitHub {
owner = "l3tnun";
repo = "EPGStation";
rev = "v${version}";
sha256 = "K1cAvmqWEfS6EY4MKAtjXb388XLYHtouxNM70PWgFig=";
};

client = nodejs.pkgs.epgstation-client.override (drv: {
# This is set to false to keep devDependencies at build time. Build time
# dependencies are pruned afterwards.
production = false;
patches = [
./use-mysql-over-domain-socket.patch

meta = drv.meta // {
inherit (nodejs.meta) platforms;
};
});
# upgrade dependencies to make it compatible with node 18
(fetchpatch {
url = "https://github.com/midchildan/EPGStation/commit/5d6cad746b7d9b6d246adcdecf9c991b77c9d89e.patch";
sha256 = "sha256-9a8VUjczlyQHVO7w9MYorPIZunAuBuif1HNmtp1yMk8=";
})
(fetchpatch {
url = "https://github.com/midchildan/EPGStation/commit/c948e833e485c2b7cb7fb33b953cca1e20de3a70.patch";
sha256 = "sha256-nM6KkVRURuQFZLXZ2etLU1a1+BoaJnfjngo07TFbe58=";
})
];

server = nodejs.pkgs.epgstation.override (drv: {
# NOTE: updateScript relies on version matching the src.
inherit version src;
npmDepsHash = "sha256-dohencRGuvc+vSoclLVn5iles4GOuTq26BrEVeJ4GC4=";
npmBuildScript = "build-server";
npmRootPath = "/lib/node_modules/epgstation";

# This is set to false to keep devDependencies at build time. Build time
# dependencies are pruned afterwards.
production = false;
buildInputs = [ bash ];
nativeBuildInputs = [ installShellFiles makeWrapper python3 ];

buildInputs = (drv.buildInputs or [ ]) ++ [ bash ];
nativeBuildInputs = (drv.nativeBuildInputs or [ ]) ++ [
makeWrapper
];
clientDir = buildNpmPackage {
pname = "${pname}-client";
inherit version src installPhase meta;

preRebuild = ''
# Fix for OpenSSL compat with newer Node.js
export NODE_OPTIONS=--openssl-legacy-provider
npmDepsHash = "sha256-a/cDPABWI4lPxvSOI4D90O71A9lm8icPMak/g6DPYQY=";
npmRootPath = "";

# Fix for not being able to connect to mysql using domain sockets.
patch -p1 < ${./use-mysql-over-domain-socket.patch}
sourceRoot = "source/client";
NODE_OPTIONS = "--openssl-legacy-provider";
};

# Workaround for https://github.com/svanderburg/node2nix/issues/275
sed -i -e "s|#!/usr/bin/env node|#! ${nodejs}/bin/node|" node_modules/node-gyp-build/bin.js
postBuild = ''
rm -rf client
cp -r ${clientDir} client
'';

# Optional typeorm dependency that does not build on aarch64-linux
rm -r node_modules/oracledb
# installPhase is shared with clientDir
installPhase = ''
runHook preInstall

find . -name package-lock.json -delete
'';
npm prune --omit dev --no-save \
$npmInstallFlags \
"''${npmInstallFlagsArray[@]}" \
$npmFlags \
"''${npmFlagsArray[@]}"

mkdir -p $out$npmRootPath
cp -r . $out$npmRootPath

runHook postInstall
'';

postInstall = let
postInstall =
let
runtimeDeps = [ nodejs bash ];
in
''
mkdir -p $out/{bin,libexec,share/doc/epgstation,share/man/man1}
mkdir -p $out/{bin,libexec,share/doc/epgstation}

pushd $out/lib/node_modules/epgstation

cp -r ${client}/lib/node_modules/epgstation-client/{package-lock.json,node_modules} client/
chmod -R u+w client/{package-lock.json,node_modules}

npm run build

npm prune --production
pushd client
npm prune --production
popd
pushd $out$npmRootPath

mv config/enc.js.template $out/libexec/enc.js
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
sed 's/@DESCRIPTION@/${meta.description}/g' ${./epgstation.1} > doc/epgstation.1
installManPage doc/epgstation.1
rm -rf doc

# just log to stdout and let journald do its job
Expand All @@ -90,42 +97,27 @@ let
# 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
rm -r config data drop recorded thumbnail src/db/subscribers src/db/migrations
ln -sfT /etc/epgstation config
ln -sfT /var/lib/epgstation data
ln -sfT /var/lib/epgstation/drop drop
ln -sfT /var/lib/epgstation/recorded recorded
ln -sfT /var/lib/epgstation/thumbnail thumbnail
ln -sfT /var/lib/epgstation/db/subscribers src/db/subscribers
ln -sfT /var/lib/epgstation/db/migrations src/db/migrations

makeWrapper ${nodejs}/bin/npm $out/bin/epgstation \
--chdir "$out/lib/node_modules/epgstation" \
--chdir $out$npmRootPath \
--prefix PATH : ${lib.makeBinPath runtimeDeps} \
--set APP_ROOT_PATH "$out/lib/node_modules/epgstation"
--set APP_ROOT_PATH $out$npmRootPath

popd
'';

# NOTE: this may take a while since it has to update all packages in
# nixpkgs.nodePackages
passthru.updateScript = callPackage ./update.nix { };

# nodePackages.epgstation is a stub package to fetch npm dependencies and
# its meta.platforms is made empty to prevent users from installing it
# directly. This technique ensures epgstation can share npm packages with
# the rest of 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.
meta = drv.meta // {
inherit (nodejs.meta) platforms;
};
});
in
server // {
name = "${pname}-${version}";

meta = with lib; server.meta // {
meta = with lib; {
description = "DVR software compatible with Mirakurun.";
homepage = "https://github.com/l3tnun/EPGStation";
license = licenses.mit;
maintainers = with maintainers; [ midchildan ];

# NOTE: updateScript relies on this being correct
position = toString ./default.nix + ":1";
};
}
72 changes: 0 additions & 72 deletions pkgs/applications/video/epgstation/package.json

This file was deleted.

Loading