Apparently sunshine is in nixpkgs now.

This commit is contained in:
Erwin Boskma 2024-01-14 20:45:03 +01:00
parent a3db857a48
commit 223fb72217
Signed by: erwin
SSH key fingerprint: SHA256:/Wk1WZdLg+vQHs3in9qq7PsIp8SMzwGSk/RLZ5zPuZk
2 changed files with 103 additions and 161 deletions

View file

@ -1,55 +1,62 @@
{ {
"nodes": { "nodes": {
"flake-utils": { "flake-parts": {
"inputs": { "inputs": {
"systems": "systems" "nixpkgs-lib": "nixpkgs-lib"
}, },
"locked": { "locked": {
"lastModified": 1701680307, "lastModified": 1704982712,
"narHash": "sha256-kAuep2h5ajznlPMD9rnQyffWG8EM/C73lejGofXvdM8=", "narHash": "sha256-2Ptt+9h8dczgle2Oo6z5ni5rt/uLMG47UFTR1ry/wgg=",
"owner": "numtide", "owner": "hercules-ci",
"repo": "flake-utils", "repo": "flake-parts",
"rev": "4022d587cbbfd70fe950c1e2083a02621806a725", "rev": "07f6395285469419cf9d078f59b5b49993198c00",
"type": "github" "type": "github"
}, },
"original": { "original": {
"id": "flake-utils", "owner": "hercules-ci",
"type": "indirect" "repo": "flake-parts",
"type": "github"
} }
}, },
"nixpkgs": { "nixpkgs": {
"locked": { "locked": {
"lastModified": 1704722960, "lastModified": 1705133751,
"narHash": "sha256-mKGJ3sPsT6//s+Knglai5YflJUF2DGj7Ai6Ynopz0kI=", "narHash": "sha256-rCIsyE80jgiOU78gCWN3A0wE0tR2GI5nH6MlS+HaaSQ=",
"path": "/nix/store/0g53xyh39z3y90p4d8r341wbqyjy1zhl-source", "owner": "NixOS",
"rev": "317484b1ead87b9c1b8ac5261a8d2dd748a0492d", "repo": "nixpkgs",
"type": "path" "rev": "9b19f5e77dd906cb52dade0b7bd280339d2a1f3d",
"type": "github"
}, },
"original": { "original": {
"id": "nixpkgs", "owner": "NixOS",
"type": "indirect" "ref": "nixos-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"nixpkgs-lib": {
"locked": {
"dir": "lib",
"lastModified": 1703961334,
"narHash": "sha256-M1mV/Cq+pgjk0rt6VxoyyD+O8cOUiai8t9Q6Yyq4noY=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "b0d36bd0a420ecee3bc916c91886caca87c894e9",
"type": "github"
},
"original": {
"dir": "lib",
"owner": "NixOS",
"ref": "nixos-unstable",
"repo": "nixpkgs",
"type": "github"
} }
}, },
"root": { "root": {
"inputs": { "inputs": {
"flake-utils": "flake-utils", "flake-parts": "flake-parts",
"nixpkgs": "nixpkgs" "nixpkgs": "nixpkgs"
} }
},
"systems": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
} }
}, },
"root": "root", "root": "root",

193
flake.nix
View file

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