apu local dhcp lease dns and invidious
This commit is contained in:
99
modules/services/invidious-companion.nix
Normal file
99
modules/services/invidious-companion.nix
Normal file
@@ -0,0 +1,99 @@
|
||||
{
|
||||
config,
|
||||
lib,
|
||||
pkgs,
|
||||
...
|
||||
}:
|
||||
let
|
||||
cfg = config.services.invidious-companion;
|
||||
companionRelease = "release-master";
|
||||
hostPlatform = pkgs.stdenv.hostPlatform.system;
|
||||
|
||||
# Invidious Companion package - fetches binary release and patches for NixOS
|
||||
unwrappedCompanion = pkgs.stdenv.mkDerivation {
|
||||
pname = "unwrapped-invidious-companion";
|
||||
version = companionRelease;
|
||||
|
||||
src =
|
||||
let
|
||||
archMap = {
|
||||
x86_64-linux = "x86_64-unknown-linux-gnu";
|
||||
aarch64-linux = "aarch64-unknown-linux-gnu";
|
||||
};
|
||||
platform = archMap.${hostPlatform} or (throw "Unsupported platform: ${hostPlatform}");
|
||||
in
|
||||
pkgs.fetchzip {
|
||||
url = "https://github.com/iv-org/invidious-companion/releases/download/${companionRelease}/invidious_companion-${platform}.tar.gz";
|
||||
sha256 = cfg.binaryHash;
|
||||
};
|
||||
|
||||
dontStrip = true;
|
||||
dontPatchELF = true;
|
||||
|
||||
installPhase = ''
|
||||
mkdir -p $out/bin
|
||||
cp invidious_companion $out/bin/invidious_companion
|
||||
chmod +x $out/bin/invidious_companion
|
||||
'';
|
||||
};
|
||||
|
||||
invidiousCompanion = pkgs.buildFHSEnv {
|
||||
name = "invidious-companion";
|
||||
targetPkgs = pkgs: [ unwrappedCompanion ];
|
||||
runScript = "invidious_companion";
|
||||
meta = {
|
||||
description = "Invidious companion for handling video streams";
|
||||
homepage = "https://github.com/iv-org/invidious-companion";
|
||||
license = lib.licenses.agpl3Only;
|
||||
};
|
||||
};
|
||||
in
|
||||
{
|
||||
options.services.invidious-companion = {
|
||||
enable = lib.mkEnableOption "Enable Invidious Companion service";
|
||||
host = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
default = "localhost";
|
||||
};
|
||||
port = lib.mkOption {
|
||||
type = lib.types.port;
|
||||
default = 8282;
|
||||
description = "Port for Invidious Companion to listen on";
|
||||
};
|
||||
secretKeyFile = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
description = "Path to file containing the companion secret key";
|
||||
};
|
||||
binaryHash = lib.mkOption {
|
||||
type = lib.types.nullOr lib.types.str;
|
||||
default = null;
|
||||
description = "SHA256 hash of the invidious companion binary release";
|
||||
};
|
||||
};
|
||||
|
||||
config = lib.mkIf cfg.enable {
|
||||
systemd.services.invidious-companion = {
|
||||
description = "Invidious Companion - video stream handler";
|
||||
wantedBy = [ "multi-user.target" ];
|
||||
after = [ "network.target" ];
|
||||
|
||||
serviceConfig = {
|
||||
Type = "simple";
|
||||
User = "invidious";
|
||||
Group = "invidious";
|
||||
DynamicUser = true;
|
||||
ExecStart = lib.getExe invidiousCompanion;
|
||||
Environment = [
|
||||
"HOST=${cfg.host}"
|
||||
"PORT=${toString cfg.port}"
|
||||
"TMPDIR=/var/cache/invidious-companion"
|
||||
];
|
||||
EnvironmentFile = [ cfg.secretKeyFile ];
|
||||
CacheDirectory = "invidious-companion";
|
||||
WorkingDirectory = "%C/invidious-companion";
|
||||
Restart = "always";
|
||||
RestartSec = 5;
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user