From 1b165364de5ee4471731a5ee35ae4435d1fa9274 Mon Sep 17 00:00:00 2001 From: teidesu Date: Sun, 17 Mar 2024 05:59:15 +0300 Subject: [PATCH] feat(koi): uxplay server --- hosts/koi/configuration.nix | 1 + hosts/koi/containers/puffer.nix | 7 ++++- hosts/koi/containers/uxplay.nix | 47 ++++++++++++++++++++++++++++ hosts/koi/hardware-configuration.nix | 1 + services/uxplay.nix | 37 ++++++++++++++++++++++ users/teidesu/server.nix | 2 +- 6 files changed, 93 insertions(+), 2 deletions(-) create mode 100644 hosts/koi/containers/uxplay.nix create mode 100755 services/uxplay.nix diff --git a/hosts/koi/configuration.nix b/hosts/koi/configuration.nix index 5191bbb..2dd5646 100755 --- a/hosts/koi/configuration.nix +++ b/hosts/koi/configuration.nix @@ -16,6 +16,7 @@ ./services/coredns.nix ./services/nginx.nix + ./containers/uxplay.nix ./containers/torrent.nix ./containers/puffer.nix ./containers/sharkey diff --git a/hosts/koi/containers/puffer.nix b/hosts/koi/containers/puffer.nix index 0370504..511c72d 100644 --- a/hosts/koi/containers/puffer.nix +++ b/hosts/koi/containers/puffer.nix @@ -143,6 +143,10 @@ let sftpgoConfig ]; + environment.systemPackages = with pkgs; [ + uxplay + ]; + users.groups.puffer = { }; users.users.smb-guest = { isNormalUser = true; @@ -157,7 +161,8 @@ let "d /mnt/puffer/Backups 0755 smb-guest puffer - -" ]; - networking.firewall.allowedTCPPorts = [ 22 ]; + networking.firewall.allowedTCPPorts = [ 22 7000 7001 7002 ]; + networking.firewall.allowedUDPPorts = [ 22 7000 7001 7002 ]; }; mounts = { diff --git a/hosts/koi/containers/uxplay.nix b/hosts/koi/containers/uxplay.nix new file mode 100644 index 0000000..097d2ff --- /dev/null +++ b/hosts/koi/containers/uxplay.nix @@ -0,0 +1,47 @@ +{ abs, lib, pkgs, config, ... }@inputs: +let + containers = import (abs "lib/containers.nix") inputs; + uxplay = import (abs "services/uxplay.nix") inputs; +in +{ + imports = [ + (containers.mkNixosContainer { + name = "uxplay"; + ip = "10.42.0.6"; + private = false; + + config = { ... }: { + imports = [ + (uxplay { + params = [ + "-p 7000" + "-vs 0" + "-async" + "-n koi -nh" + ]; + withAvahi = true; + }) + ]; + + networking.firewall.allowedTCPPorts = [ 7000 7001 7002 ]; + networking.firewall.allowedUDPPorts = [ 7000 7001 7002 ]; + services.avahi.openFirewall = true; + }; + + containerConfig.extraFlags = [ + "--bind=/run/pipewire" + "--bind=/dev/snd" + "--bind=/dev/shm" + ]; + }) + ]; + + security.rtkit.enable = true; + services.pipewire = { + enable = true; + alsa.enable = true; + alsa.support32Bit = true; + pulse.enable = true; + systemWide = true; + }; +} diff --git a/hosts/koi/hardware-configuration.nix b/hosts/koi/hardware-configuration.nix index cf3c098..a5641de 100755 --- a/hosts/koi/hardware-configuration.nix +++ b/hosts/koi/hardware-configuration.nix @@ -55,4 +55,5 @@ in nixpkgs.hostPlatform = lib.mkDefault "x86_64-linux"; hardware.cpu.amd.updateMicrocode = lib.mkDefault config.hardware.enableRedistributableFirmware; + hardware.firmware = [ pkgs.alsa-firmware ]; } diff --git a/services/uxplay.nix b/services/uxplay.nix new file mode 100755 index 0000000..8d1380e --- /dev/null +++ b/services/uxplay.nix @@ -0,0 +1,37 @@ +{ lib, pkgs, ... }: + +{ + # UXPlay parameters + params ? [ ] + # Whether to also set up avahi daemon +, withAvahi ? false +, # Name of the systemd service + serviceName ? "uxplay" +, # UXPlay package + package ? pkgs.uxplay +, serviceConfig ? { } +}: +let + paramsJoined = builtins.concatStringsSep " " params; +in +{ + systemd.services.${serviceName} = { + description = "${serviceName} Daemon"; + after = [ "network.target" ] ++ lib.optionals withAvahi [ "avahi-daemon.service" ]; + wantedBy = [ "multi-user.target" ]; + serviceConfig.PrivateTmp = true; + script = '' + sleep 5 # idk needed for some reason + exec ${package}/bin/uxplay ${paramsJoined} + ''; + } // serviceConfig; +} // lib.optionalAttrs withAvahi { + services.avahi = { + enable = true; + nssmdns4 = true; + publish = { + enable = true; + userServices = true; + }; + }; +} \ No newline at end of file diff --git a/users/teidesu/server.nix b/users/teidesu/server.nix index bb68d24..d52eafa 100644 --- a/users/teidesu/server.nix +++ b/users/teidesu/server.nix @@ -3,7 +3,7 @@ { users.users.teidesu = { isNormalUser = true; - extraGroups = [ "wheel" "kvm" "docker" ]; + extraGroups = [ "wheel" "kvm" "docker" "pipewire" ]; shell = pkgs.zsh; openssh.authorizedKeys.keyFiles = [