Skip to content

Commit

Permalink
feat(nix): start working on jellyfin
Browse files Browse the repository at this point in the history
  • Loading branch information
sbulav committed Nov 22, 2024
1 parent ef6188e commit d08927c
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 0 deletions.
87 changes: 87 additions & 0 deletions nix/modules/nixos/containers/jellyfin/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
{
config,
lib,
namespace,
...
}:
with lib;
with lib.custom; let
cfg = config.${namespace}.containers.jellyfin;
in {
options.${namespace}.containers.jellyfin = with types; {
enable = mkBoolOpt false "Enable jellyfin nixos-container;";
host = mkOpt str "jellyfin.sbulav.ru" "The host to serve jellyfin on";
dataPath = mkOpt str "/tank/jellyfin" "Jellyfin data path on host machine";
hostAddress = mkOpt str "172.16.64.10" "With private network, which address to use on Host";
localAddress = mkOpt str "172.16.64.107" "With privateNetwork, which address to use in container";
};
imports = [
(import ../shared/shared-traefik-route.nix
{
app = "jellyfin";
host = "${cfg.host}";
url = "http://${cfg.localAddress}:8096";
route_enabled = cfg.enable;
})
(import ../shared/shared-adguard-dns-rewrite.nix
{
host = "${cfg.host}";
rewrite_enabled = cfg.enable;
})
];

config = mkIf cfg.enable {
networking.nat = {
enable = true;
internalInterfaces = ["ve-jellyfin"];
externalInterface = "ens3";
};
containers.jellyfin = {
ephemeral = true;
autoStart = true;

privateNetwork = true;
# Need to add 172.16.64.0/18 on router
hostAddress = "${cfg.hostAddress}";
localAddress = "${cfg.localAddress}";

bindMounts = {
"/var/lib/jellyfin/config/" = {
hostPath = "${cfg.dataPath}/config/";
isReadOnly = false;
};
"/var/lib/jellyfin/" = {
hostPath = "${cfg.dataPath}/";
isReadOnly = false;
};
"/var/lib/jellyfin/log/" = {
"hostPath" = "${cfg.dataPath}/log/";
isReadOnly = false;
};

config = {...}: {
systemd.tmpfiles.rules = [
"d /var/lib/jellyfin 700 jellyfin jellyfin -"
];
services.jellyfin = {
enable = true;
};

networking = {
firewall = {
enable = true;
# https://jellyfin.org/docs/general/networking/index.html#port-bindings
allowedTCPPorts = [8096 8920];
allowedUDPPorts = [1900 7359];
};
# Use systemd-resolved inside the container
# Workaround for bug https://github.com/NixOS/nixpkgs/issues/162686
useHostResolvConf = lib.mkForce false;
};
services.resolved.enable = true;
system.stateVersion = "24.11";
};
};
};
};
}
6 changes: 6 additions & 0 deletions nix/systems/x86_64-linux/serverz/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ in {
hostAddress = "172.16.64.10";
localAddress = "172.16.64.106";
};
jellyfin = {
enable = true;
host = "jellyfin2.sbulav.ru";
hostAddress = "172.16.64.10";
localAddress = "172.16.64.107";
};
};

environment.systemPackages = with pkgs; [
Expand Down

0 comments on commit d08927c

Please sign in to comment.