Initial commit
This commit is contained in:
commit
d6c38fb9bd
6 changed files with 231 additions and 0 deletions
1
.envrc
Normal file
1
.envrc
Normal file
|
@ -0,0 +1 @@
|
|||
use flake
|
9
default.nix
Normal file
9
default.nix
Normal file
|
@ -0,0 +1,9 @@
|
|||
(import (
|
||||
let
|
||||
lock = builtins.fromJSON (builtins.readFile ./flake.lock);
|
||||
in fetchTarball {
|
||||
url = "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz";
|
||||
sha256 = lock.nodes.flake-compat.locked.narHash;
|
||||
}) {
|
||||
src = ./.;
|
||||
}).defaultNix
|
39
flake.lock
Normal file
39
flake.lock
Normal file
|
@ -0,0 +1,39 @@
|
|||
{
|
||||
"nodes": {
|
||||
"flake-utils": {
|
||||
"locked": {
|
||||
"lastModified": 1659877975,
|
||||
"narHash": "sha256-zllb8aq3YO3h8B/U0/J1WBgAL8EX5yWf5pMj3G0NAmc=",
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"rev": "c0e246b9b83f637f4681389ecabcb2681b4f3af0",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"id": "flake-utils",
|
||||
"type": "indirect"
|
||||
}
|
||||
},
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1663850217,
|
||||
"narHash": "sha256-tp9nXo1/IdN/xN9m06ryy0QUAEfoN6K56ObM/1QTAjc=",
|
||||
"path": "/nix/store/if56vv9237zafkzgzcdkqxf2lmp86myq-source",
|
||||
"rev": "ae1dc133ea5f1538d035af41e5ddbc2ebcb67b90",
|
||||
"type": "path"
|
||||
},
|
||||
"original": {
|
||||
"id": "nixpkgs",
|
||||
"type": "indirect"
|
||||
}
|
||||
},
|
||||
"root": {
|
||||
"inputs": {
|
||||
"flake-utils": "flake-utils",
|
||||
"nixpkgs": "nixpkgs"
|
||||
}
|
||||
}
|
||||
},
|
||||
"root": "root",
|
||||
"version": 7
|
||||
}
|
125
flake.nix
Normal file
125
flake.nix
Normal file
|
@ -0,0 +1,125 @@
|
|||
{
|
||||
description = "A very basic flake";
|
||||
|
||||
inputs = {
|
||||
nixpkgs = { };
|
||||
flake-utils = { };
|
||||
};
|
||||
|
||||
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";
|
||||
|
||||
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 = [
|
||||
"-DSUNSHINE_ASSETS_DIR=${placeholder "out"}/etc/sunshine"
|
||||
"-DSUNSHINE_CONFIG_DIR=${placeholder "out"}/etc/sunshine"
|
||||
];
|
||||
|
||||
# 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" \
|
||||
--replace "/etc/udev/rules.d" "$out/etc/udev/rules.d" \
|
||||
--replace "/usr/bin" "$out/bin" \
|
||||
--replace "/usr/lib/systemd/user" "$out/lib/systemd/user"
|
||||
'';
|
||||
|
||||
postInstall = ''
|
||||
wrapProgram $out/bin/sunshine --prefix LD_LIBRARY_PATH : "${lib.makeLibraryPath (with pkgs; [ avahi mesa libGL ])}"
|
||||
'';
|
||||
};
|
||||
};
|
||||
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 ];
|
||||
};
|
||||
|
||||
}) // {
|
||||
nixosModule.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 = true;
|
||||
|
||||
users.extraUsers.${cfg.user}.extraGroups = [ "uinput" "video" ];
|
||||
security.wrappers.sunshine = {
|
||||
owner = "root";
|
||||
group = "root";
|
||||
capabilities = "cap_sys_admin+p";
|
||||
source = "${sunshine}/bin/sunshine";
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
9
shell.nix
Normal file
9
shell.nix
Normal file
|
@ -0,0 +1,9 @@
|
|||
(import (
|
||||
let
|
||||
lock = builtins.fromJSON (builtins.readFile ./flake.lock);
|
||||
in fetchTarball {
|
||||
url = "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz";
|
||||
sha256 = lock.nodes.flake-compat.locked.narHash;
|
||||
}) {
|
||||
src = ./.;
|
||||
}).shellNix
|
48
sunshine.patch
Normal file
48
sunshine.patch
Normal file
|
@ -0,0 +1,48 @@
|
|||
diff --git a/src/config.cpp b/src/config.cpp
|
||||
index fd88760..04f2489 100644
|
||||
--- a/src/config.cpp
|
||||
+++ b/src/config.cpp
|
||||
@@ -20,7 +20,7 @@ using namespace std::literals;
|
||||
#define PRIVATE_KEY_FILE CA_DIR "/cakey.pem"
|
||||
#define CERTIFICATE_FILE CA_DIR "/cacert.pem"
|
||||
|
||||
-#define APPS_JSON_PATH platf::appdata().string() + "/apps.json"
|
||||
+#define APPS_JSON_PATH "apps.json"
|
||||
namespace config {
|
||||
|
||||
namespace nv {
|
||||
@@ -292,7 +292,7 @@ sunshine_t sunshine {
|
||||
{}, // Username
|
||||
{}, // Password
|
||||
{}, // Password Salt
|
||||
- platf::appdata().string() + "/sunshine.conf", // config file
|
||||
+ "sunshine.conf", // config file
|
||||
{}, // cmd args
|
||||
47989,
|
||||
};
|
||||
@@ -703,6 +703,7 @@ int apply_flags(const char *line) {
|
||||
void apply_config(std::unordered_map<std::string, std::string> &&vars) {
|
||||
if(!fs::exists(stream.file_apps.c_str())) {
|
||||
fs::copy_file(SUNSHINE_CONFIG_DIR "/apps.json", stream.file_apps);
|
||||
+ fs::permissions(stream.file_apps, fs::perms::owner_write, fs::perm_options::add);
|
||||
}
|
||||
|
||||
for(auto &[name, val] : vars) {
|
||||
@@ -910,11 +911,16 @@ int parse(int argc, char *argv[]) {
|
||||
}
|
||||
}
|
||||
|
||||
+ std::unordered_map<std::string, std::string> vars;
|
||||
+ path_f(vars, "config_file", sunshine.config_file);
|
||||
+ path_f(vars, "file_apps", stream.file_apps);
|
||||
+
|
||||
if(!fs::exists(sunshine.config_file)) {
|
||||
fs::copy_file(SUNSHINE_CONFIG_DIR "/sunshine.conf", sunshine.config_file);
|
||||
+ fs::permissions(sunshine.config_file, fs::perms::owner_write, fs::perm_options::add);
|
||||
}
|
||||
|
||||
- auto vars = parse_config(read_file(sunshine.config_file.c_str()));
|
||||
+ vars = parse_config(read_file(sunshine.config_file.c_str()));
|
||||
|
||||
for(auto &[name, value] : cmd_vars) {
|
||||
vars.insert_or_assign(std::move(name), std::move(value));
|
Loading…
Reference in a new issue