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
6 changes: 5 additions & 1 deletion nixos/modules/services/video/mirakurun.nix
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,9 @@ in
description = "Mirakurun user";
group = "video";
isSystemUser = true;

# NPM insists on creating ~/.npm
home = "/var/cache/mirakurun";
};

services.mirakurun.serverSettings = {
Expand All @@ -171,9 +174,10 @@ in
wantedBy = [ "multi-user.target" ];
after = [ "network.target" ];
serviceConfig = {
ExecStart = "${mirakurun}/bin/mirakurun-start";
ExecStart = "${mirakurun}/bin/mirakurun start";
User = username;
Group = groupname;
CacheDirectory = "mirakurun";
RuntimeDirectory="mirakurun";
StateDirectory="mirakurun";
Nice = -10;
Expand Down
98 changes: 38 additions & 60 deletions pkgs/applications/video/mirakurun/default.nix
Original file line number Diff line number Diff line change
@@ -1,96 +1,74 @@
# NOTE: Mirakurun is packaged outside of nodePackages because Node2nix can't
# handle one of its subdependencies. See below link for details.
#
# https://github.com/Chinachu/node-aribts/blob/af84dbbbd81ea80b946e538083b64b5b2dc7e8f2/package.json#L26

{ lib
, stdenvNoCC
, stdenv
, bash
, buildNpmPackage
, fetchFromGitHub
, gitUpdater
, jq
, installShellFiles
, makeWrapper
, mkYarnPackage
, which
, writers
, nodejs
, substituteAll
, v4l-utils
, yarn
, yarn2nix
, which
}:

stdenvNoCC.mkDerivation rec {
buildNpmPackage rec {
pname = "mirakurun";
version = "3.8.0";
version = "3.9.0-rc.4";

src = fetchFromGitHub {
owner = "Chinachu";
repo = "Mirakurun";
rev = version;
sha256 = "1fmzi3jc3havvpc1kz5z16k52lnrsmc3b5yqyxc7i911gqyjsxzr";
sha256 = "sha256-Qg+wET5H9t3Mv2Hv0iT/C85/SEaQ+BHSBL3JjMQW5+Q=";
};

nativeBuildInputs = [ makeWrapper ];
patches = [
# NOTE: fixes for hardcoded paths and assumptions about filesystem
# permissions
./nix-filesystem.patch
];

mirakurun = mkYarnPackage rec {
name = "${pname}-${version}";
inherit version src;
npmDepsHash = "sha256-e7m7xb7p1SBzLAyQ82TTR/qLXv4lRm37x0JJPWYYGvI=";

yarnNix = ./yarn.nix;
yarnLock = ./yarn.lock;
packageJSON = ./package.json;
nativeBuildInputs = [ installShellFiles makeWrapper ];

# workaround for https://github.com/webpack/webpack/issues/14532
NODE_OPTIONS = "--openssl-legacy-provider";

patches = [
# NOTE: fixes for hardcoded paths and assumptions about filesystem
# permissions
./nix-filesystem.patch
];

buildPhase = ''
yarn --offline build
'';
# workaround for https://github.com/webpack/webpack/issues/14532
NODE_OPTIONS = "--openssl-legacy-provider";

distPhase = "true";
};

installPhase =
postInstall =
let
runtimeDeps = [ bash which v4l-utils ];
runtimeDeps = [
bash
nodejs
which
] ++ lib.optionals stdenv.isLinux [ v4l-utils ];
crc32Patch = substituteAll {
src = ./fix-musl-detection.patch;
isMusl = if stdenv.hostPlatform.isMusl then "true" else "false";
};
in
''
mkdir -p $out/bin
sed 's/@DESCRIPTION@/${meta.description}/g' ${./mirakurun.1} > mirakurun.1
installManPage mirakurun.1

makeWrapper ${mirakurun}/bin/mirakurun-epgdump $out/bin/mirakurun-epgdump \
--chdir "${mirakurun}/libexec/mirakurun/node_modules/mirakurun" \
wrapProgram $out/bin/mirakurun-epgdump \
--prefix PATH : ${lib.makeBinPath runtimeDeps}

# XXX: The original mirakurun command uses PM2 to manage the Mirakurun
# server. However, we invoke the server directly and let systemd
# manage it to avoid complication. This is okay since no features
# unique to PM2 is currently being used.
makeWrapper ${yarn}/bin/yarn $out/bin/mirakurun-start \
--add-flags "start" \
--chdir "${mirakurun}/libexec/mirakurun/node_modules/mirakurun" \
makeWrapper ${nodejs}/bin/npm $out/bin/mirakurun \
--chdir "$out/lib/node_modules/mirakurun" \
--prefix PATH : ${lib.makeBinPath runtimeDeps}
'';

passthru.updateScript = import ./update.nix {
inherit lib;
inherit (src.meta) homepage;
inherit
pname
version
gitUpdater
writers
jq
yarn
yarn2nix;
};
pushd $out/lib/node_modules/mirakurun/node_modules/@node-rs/crc32
patch -p3 < ${crc32Patch}
popd
'';

meta = with lib; {
inherit (mirakurun.meta) description platforms;
description = "Resource manager for TV tuners.";
license = licenses.asl20;
maintainers = with maintainers; [ midchildan ];
};
Expand Down
29 changes: 29 additions & 0 deletions pkgs/applications/video/mirakurun/fix-musl-detection.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
diff --git a/packages/crc32/index.js b/packages/crc32/index.js
index cdc7519..7b05930 100644
--- a/packages/crc32/index.js
+++ b/packages/crc32/index.js
@@ -5,7 +5,7 @@ const { platform, arch } = process

let nativeBinding = null
let localFileExisted = false
-let isMusl = false
+let isMusl = @isMusl@
let loadError = null

switch (platform) {
@@ -114,7 +114,6 @@ switch (platform) {
case 'linux':
switch (arch) {
case 'x64':
- isMusl = readFileSync('/usr/bin/ldd', 'utf8').includes('musl')
if (isMusl) {
localFileExisted = existsSync(join(__dirname, 'crc32.linux-x64-musl.node'))
try {
@@ -140,7 +139,6 @@ switch (platform) {
}
break
case 'arm64':
- isMusl = readFileSync('/usr/bin/ldd', 'utf8').includes('musl')
if (isMusl) {
localFileExisted = existsSync(join(__dirname, 'crc32.linux-arm64-musl.node'))
try {
44 changes: 44 additions & 0 deletions pkgs/applications/video/mirakurun/mirakurun.1
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
.Dd $Mdocdate$
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We normally don't write man pages but use the nixos manual instead

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As noted in this document, the primary way of using Mirakurun is through the NixOS module. So the main document is in the options section of the NixOS manual, and this man page isn't something that I meant to prominently feature in the manual.

Additionally, this is mainly written for people who try to run the command directly and get confused. For that audience, it's not very clear at first that this is an Nix-provided command instead of something provided by upstream and I think it's natural to look in the man pages.

.Dt MIRAKURUN 1
.Os
.Sh NAME
.Nm mirakurun
.Nd @DESCRIPTION@
.Sh SYNOPSIS
.Nm
.Bk -words
.Op Ar command Op Ar args
.Ek
.Sh DESCRIPTION
.Nm
is a wrapper command for Mirakurun provided by Nix. It's actually a thin
wrapper around the
.Xr npm 1
command line tool which you can use to invoke npm commands from the Mirakurun
project directory. The command line arguments are simply passed as-is to
.Xr npm 1 .
.Pp
On NixOS, it is strongly recommended that you enable the mirakurun module
instead of invoking this command directly to launch Mirakurun. On other
platforms, run
.Pp
.Dl $ mirakurun start
.Pp
to start Mirakurun.
.Sh FILES
.Bl -tag -width Ds -compact
.It Pa /etc/mirakurun
.Nm
configuration directory.
.El
.Sh EXAMPLES
Start Mirakurun.
.Pp
.Dl $ mirakurun start
.Pp
Start Mirakurun in development mode.
.Pp
.Dl $ mirakurun run debug
.Pp
.Sh SEE ALSO
.Xr npm 1
129 changes: 0 additions & 129 deletions pkgs/applications/video/mirakurun/package.json

This file was deleted.

Loading