Compare commits

..

2 commits

Author SHA1 Message Date
223fb72217
Apparently sunshine is in nixpkgs now. 2024-01-14 20:45:03 +01:00
a3db857a48
flake.lock: Update
Flake lock file updates:

• Updated input 'flake-utils':
    'github:numtide/flake-utils/c0e246b9b83f637f4681389ecabcb2681b4f3af0' (2022-08-07)
  → 'github:numtide/flake-utils/4022d587cbbfd70fe950c1e2083a02621806a725' (2023-12-04)
• Added input 'flake-utils/systems':
    'github:nix-systems/default/da67096a3b9bf56a91d16901293e51ba5b49a27e' (2023-04-09)
• Updated input 'nixpkgs':
    'path:/nix/store/if56vv9237zafkzgzcdkqxf2lmp86myq-source?lastModified=1663850217&narHash=sha256-tp9nXo1/IdN/xN9m06ryy0QUAEfoN6K56ObM/1QTAjc%3D&rev=ae1dc133ea5f1538d035af41e5ddbc2ebcb67b90' (2022-09-22)
  → 'path:/nix/store/0g53xyh39z3y90p4d8r341wbqyjy1zhl-source?lastModified=1704722960&narHash=sha256-mKGJ3sPsT6//s%2BKnglai5YflJUF2DGj7Ai6Ynopz0kI%3D&rev=317484b1ead87b9c1b8ac5261a8d2dd748a0492d' (2024-01-08)
2024-01-14 20:24:13 +01:00
2 changed files with 105 additions and 145 deletions

View file

@ -1,35 +1,60 @@
{
"nodes": {
"flake-utils": {
"flake-parts": {
"inputs": {
"nixpkgs-lib": "nixpkgs-lib"
},
"locked": {
"lastModified": 1659877975,
"narHash": "sha256-zllb8aq3YO3h8B/U0/J1WBgAL8EX5yWf5pMj3G0NAmc=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "c0e246b9b83f637f4681389ecabcb2681b4f3af0",
"lastModified": 1704982712,
"narHash": "sha256-2Ptt+9h8dczgle2Oo6z5ni5rt/uLMG47UFTR1ry/wgg=",
"owner": "hercules-ci",
"repo": "flake-parts",
"rev": "07f6395285469419cf9d078f59b5b49993198c00",
"type": "github"
},
"original": {
"id": "flake-utils",
"type": "indirect"
"owner": "hercules-ci",
"repo": "flake-parts",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1663850217,
"narHash": "sha256-tp9nXo1/IdN/xN9m06ryy0QUAEfoN6K56ObM/1QTAjc=",
"path": "/nix/store/if56vv9237zafkzgzcdkqxf2lmp86myq-source",
"rev": "ae1dc133ea5f1538d035af41e5ddbc2ebcb67b90",
"type": "path"
"lastModified": 1705133751,
"narHash": "sha256-rCIsyE80jgiOU78gCWN3A0wE0tR2GI5nH6MlS+HaaSQ=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "9b19f5e77dd906cb52dade0b7bd280339d2a1f3d",
"type": "github"
},
"original": {
"id": "nixpkgs",
"type": "indirect"
"owner": "NixOS",
"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": {
"inputs": {
"flake-utils": "flake-utils",
"flake-parts": "flake-parts",
"nixpkgs": "nixpkgs"
}
}

193
flake.nix
View file

@ -1,147 +1,82 @@
{
description = "A very basic flake";
description = "NixOS module for Shunshine";
inputs = {
nixpkgs = { };
flake-utils = { };
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-parts = {
url = "github:hercules-ci/flake-parts";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs = { self, nixpkgs, flake-utils }:
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";
outputs = { self, nixpkgs, flake-parts, ... }@inputs:
flake-parts.lib.mkFlake { inherit inputs; } {
systems = [ "x86_64-linux" ];
perSystem = { self', pkgs, lib, ... }: {
formatter = pkgs.nixpkgs-fmt;
src = pkgs.fetchFromGitHub {
owner = "LizardByte";
repo = "Sunshine";
rev = "6000b85b1a4ec574d93fbc7545f5bf48f3d5aaa7";
sha256 = "SB2DAOYf2izIwwRWEw2wt5L5oCDbb6YOqXw/z/PD1pQ=";
fetchSubmodules = true;
devShells.default = with pkgs; mkShell { };
};
flake = {
nixosModules.sunshine = { pkgs, config, lib, ... }:
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; [
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
];
openFirewall = mkOption {
description = "Open the necessary ports for sunshine";
type = types.bool;
default = false;
};
};
hardeningDisable = [ "format" ];
config = mkIf cfg.enable {
environment.systemPackages = [ sunshine ];
nativeBuildInputs = with pkgs; [
cmake
pkgconf
makeWrapper
];
hardware.uinput.enable = true;
cmakeFlags = [
"-DCMAKE_INSTALL_PREFIX=${placeholder "out"}"
"-DSUNSHINE_ASSETS_DIR=share/sunshine"
"-DSUNSHINE_CONFIG_DIR=share/sunshine"
];
users.extraUsers.${cfg.user}.extraGroups = [ "uinput" "video" ];
security.wrappers.sunshine = {
owner = "root";
group = "root";
capabilities = "cap_sys_admin+p";
source = "${sunshine}/bin/sunshine";
};
# patches = [ ./001-cmake-find-evdev.patch ];
patches = [ ./sunshine.patch ];
systemd.user.services.sunshine = {
description = "Sunshine is a Gamestream host for Moonlight";
preConfigure = ''
substituteInPlace CMakeLists.txt \
--replace "/usr/include/libevdev-1.0" "${pkgs.libevdev}/include/libevdev-1.0" \
'';
serviceConfig.ExecStart = "${config.security.wrapperDir}/sunshine";
postInstall = ''
rm -r $out/lib/systemd
wrapProgram $out/bin/sunshine --prefix LD_LIBRARY_PATH : "${lib.makeLibraryPath (with pkgs; [ avahi mesa libGL ])}"
'';
wantedBy = [ "graphical-session.target" ];
};
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; }
];
};
};
};
};
};
}