sunshine/flake.nix

148 lines
4.3 KiB
Nix
Raw Normal View History

2022-09-26 11:59:48 +02:00
{
description = "A very basic flake";
inputs = {
nixpkgs = { };
flake-utils = { };
};
outputs = { self, nixpkgs, flake-utils }:
2022-09-26 12:05:41 +02:00
flake-utils.lib.eachSystem [ "x86_64-linux" ]
(system:
let
pkgs = nixpkgs.legacyPackages.${system};
lib = nixpkgs.lib;
in
{
formatter = pkgs.nixpkgs-fmt;
packages = {
sunshine = pkgs.stdenv.mkDerivation {
pname = "sunshine";
version = "0.14.1";
src = pkgs.fetchFromGitHub {
owner = "LizardByte";
repo = "Sunshine";
rev = "6000b85b1a4ec574d93fbc7545f5bf48f3d5aaa7";
sha256 = "SB2DAOYf2izIwwRWEw2wt5L5oCDbb6YOqXw/z/PD1pQ=";
fetchSubmodules = true;
};
buildInputs = with pkgs; [
avahi
(boost.override { enableStatic = true; })
ffmpeg
libevdev
libpulseaudio
xorg.libX11
xorg.libxcb
xorg.libXfixes
xorg.libXrandr
xorg.libXtst
openssl
libopus
udev
libdrm
valgrind.dev
wayland
libffi
icu
];
hardeningDisable = [ "format" ];
nativeBuildInputs = with pkgs; [
cmake
pkgconf
makeWrapper
];
cmakeFlags = [
2022-09-26 18:35:28 +02:00
"-DCMAKE_INSTALL_PREFIX=${placeholder "out"}"
"-DSUNSHINE_ASSETS_DIR=share/sunshine"
"-DSUNSHINE_CONFIG_DIR=share/sunshine"
2022-09-26 12:05:41 +02:00
];
# patches = [ ./001-cmake-find-evdev.patch ];
patches = [ ./sunshine.patch ];
preConfigure = ''
substituteInPlace CMakeLists.txt \
--replace "/usr/include/libevdev-1.0" "${pkgs.libevdev}/include/libevdev-1.0" \
'';
postInstall = ''
2022-09-26 12:52:40 +02:00
rm -r $out/lib/systemd
2022-09-26 12:05:41 +02:00
wrapProgram $out/bin/sunshine --prefix LD_LIBRARY_PATH : "${lib.makeLibraryPath (with pkgs; [ avahi mesa libGL ])}"
'';
2022-09-26 11:59:48 +02:00
};
2022-09-26 12:05:41 +02:00
};
packages.default = self.packages.${system}.sunshine;
2022-09-26 11:59:48 +02:00
2022-09-26 12:05:41 +02:00
devShells.default = with pkgs; mkShell {
nativeBuildInputs = [ nix-prefetch-scripts nix-prefetch-github cmake-language-server ];
inputsFrom = [ self.packages.${system}.sunshine ];
2022-09-26 11:59:48 +02:00
};
2022-09-26 12:05:41 +02:00
}) // {
2022-09-26 12:09:14 +02:00
nixosModules.sunshine = { pkgs, config, lib, ... }:
2022-09-26 12:05:41 +02:00
with lib;
let
cfg = config.services.sunshine;
sunshine = self.packages.${pkgs.system}.sunshine;
in
{
options.services.sunshine = {
enable = mkEnableOption "sunshine";
user = mkOption {
description = "The user using sunshine";
type = types.str;
};
2022-09-26 11:59:48 +02:00
2022-09-26 12:05:41 +02:00
openFirewall = mkOption {
description = "Open the necessary ports for sunshine";
type = types.bool;
default = false;
};
};
2022-09-26 11:59:48 +02:00
2022-09-26 12:05:41 +02:00
config = mkIf cfg.enable {
environment.systemPackages = [ sunshine ];
2022-09-26 12:15:07 +02:00
hardware.uinput.enable = true;
2022-09-26 12:05:41 +02:00
users.extraUsers.${cfg.user}.extraGroups = [ "uinput" "video" ];
security.wrappers.sunshine = {
owner = "root";
group = "root";
capabilities = "cap_sys_admin+p";
2022-09-26 13:20:44 +02:00
source = "${sunshine}/bin/sunshine";
2022-09-26 11:59:48 +02:00
};
2022-09-26 12:52:40 +02:00
systemd.user.services.sunshine = {
description = "Sunshine is a Gamestream host for Moonlight";
2022-09-26 13:18:27 +02:00
serviceConfig.ExecStart = "${config.security.wrapperDir}/sunshine";
2022-09-26 12:52:40 +02:00
wantedBy = [ "graphical-session.target" ];
};
2022-09-26 12:05:41 +02:00
networking.firewall = mkIf cfg.openFirewall {
allowedTCPPorts = [
48010
];
2022-09-26 11:59:48 +02:00
2022-09-26 12:05:41 +02:00
allowedTCPPortRanges = [
{ from = 47984; to = 47990; }
];
2022-09-26 11:59:48 +02:00
2022-09-26 12:05:41 +02:00
allowedUDPPortRanges = [
{ from = 47998; to = 48000; }
];
2022-09-26 11:59:48 +02:00
};
};
2022-09-26 12:05:41 +02:00
};
};
2022-09-26 11:59:48 +02:00
}