Personal Nix setup

Move palworld helpers and package to local overlay

+17 -3
flake.nix
···
};
};
-
outputs = inputs: let
+
outputs = inputs @ { self, ... }: let
inherit (inputs.nixpkgs) lib;
inherit (import ./lib/system.nix inputs) mkSystem;
eachSystem = lib.genAttrs ["aarch64-darwin" "aarch64-linux" "x86_64-darwin" "x86_64-linux"];
···
inputs.nvim-plugins.overlays.default
inputs.android-sdk.overlays.default
inputs.language-servers.overlays.default
+
self.overlays.default
];
in {
darwinConfigurations."sprite" = mkSystem {
···
hostname = "ramune";
};
-
packages = eachSystem (system: {
+
overlays = {
+
default = import ./lib/pkgs;
+
};
+
+
packages = eachSystem (system: let
+
pkgs = import inputs.nixpkgs {
+
inherit system;
+
overlays = [ self.overlays.default ];
+
};
+
in {
inherit (inputs.agenix.packages.${system}) agenix;
inherit (inputs.darwin.packages.${system}) darwin-rebuild;
-
} // (import ./lib/pkgs inputs.nixpkgs.legacyPackages.${system}));
+
} // {
+
inherit (pkgs)
+
steamworks-sdk-redist
+
systemd-transparent-udp-forwarderd;
+
});
apps = eachSystem (system: import ./lib/apps {
inherit lib;
+7 -2
lib/pkgs/default.nix
···
-
pkgs: {
-
yeetmouse = import ./yeetmouse.nix pkgs;
+
self: super: {
+
fetchSteam = import ./fetch-steam.nix self super;
+
mkSteamPackage = import ./mk-steam-package.nix self super;
+
mkSteamWrapper = import ./mk-steam-wrapper.nix self super;
+
systemd-transparent-udp-forwarderd = import ./systemd-transparent-udp-forwarderd.nix self super;
+
steamworks-sdk-redist = import ./steamworks-sdk-redist.nix self super;
+
palworld-server = import ./palworld-server.nix self super;
}
+56
lib/pkgs/mk-steam-package.nix
···
+
self: pkgs @ {
+
lib,
+
stdenv,
+
autoPatchelfHook,
+
...
+
}:
+
+
with lib;
+
let
+
inherit (stdenv.hostPlatform) isAarch64;
+
in
+
{
+
name,
+
hash ? "",
+
version,
+
appId,
+
depotId,
+
manifestId,
+
...
+
} @ args: let
+
derivationArgs = builtins.removeAttrs args [ "name" "appId" "depotId" "manifestId" "hash" ];
+
in
+
stdenv.mkDerivation (rec {
+
pname = name;
+
src = self.fetchSteam {
+
inherit name appId depotId manifestId hash;
+
};
+
+
dontBuild = true;
+
dontConfigure = true;
+
dontFixup = isAarch64;
+
+
nativeBuildInputs = optionals (!isAarch64) [ autoPatchelfHook ];
+
appendRunpaths = with self; makeLibraryPath [
+
steamworks-sdk-redist
+
glibc
+
libxcrypt
+
libGL
+
libdrm
+
mesa # for libgbm
+
udev
+
libudev0-shim
+
libva
+
vulkan-loader
+
];
+
+
installPhase = ''
+
runHook preInstall
+
+
mkdir -p $out
+
mv ./* $out
+
chmod 755 -R $out
+
+
runHook postInstall
+
'';
+
} // derivationArgs)
+74
lib/pkgs/mk-steam-wrapper.nix
···
+
self: pkgs @ {
+
lib,
+
box64,
+
makeWrapper,
+
pkgsCross,
+
stdenv,
+
...
+
}:
+
+
with lib;
+
let
+
useBox64 = stdenv.hostPlatform.isAarch64;
+
+
defaultLibs = with self; [
+
steamworks-sdk-redist
+
glibc
+
libxcrypt
+
libGL
+
libdrm
+
mesa # for libgbm
+
udev
+
libudev0-shim
+
libva
+
vulkan-loader
+
];
+
+
defaultNativeLibs = optionals useBox64 [ pkgsCross.gnu64.libgcc ];
+
+
mkSteamWrapper = makeOverridable (
+
{
+
logLevel ? 0,
+
env ? {},
+
libs ? defaultLibs,
+
nativeLibs ? defaultNativeLibs,
+
extraWrapperArgs ? [],
+
}: let
+
runpaths = libs ++ optionals useBox64 nativeLibs;
+
combinedEnv = optionalAttrs useBox64 {
+
BOX64_LOG = logLevel;
+
BOX64_DYNAREC_STRONGMEM = 1;
+
BOX64_DYNAREC_BIGBLOCK = 1;
+
BOX64_DYNAREC_SAFEFLAGS = 1;
+
BOX64_DYNAREC_FASTROUND = 1;
+
BOX64_DYNAREC_FASTNAN = 1;
+
BOX64_DYNAREC_X87DOUBLE = 0;
+
} // env;
+
in bin:
+
stdenv.mkDerivation rec {
+
name = "box64-wrapper";
+
meta.mainProgram = name;
+
+
dontUnpack = true;
+
dontConfigure = true;
+
dontBuild = true;
+
+
nativeBuildInputs = [ makeWrapper ];
+
buildInputs = runpaths;
+
+
installPhase = let
+
outBin = if useBox64 then "${box64}/bin/box64" else bin;
+
targetBinFlag = if useBox64 then "--add-flags ${escapeShellArg bin}" else "";
+
in ''
+
runHook preInstall
+
makeWrapper "${outBin}" "$out/bin/${name}" \
+
${concatStrings (mapAttrsToList (name: value: "--set ${name} '${toString value}' ") combinedEnv)} \
+
--prefix LD_LIBRARY_PATH : ${makeLibraryPath runpaths} \
+
${targetBinFlag} \
+
${lib.strings.concatStringsSep " " extraWrapperArgs}
+
runHook postInstall
+
'';
+
}
+
);
+
in
+
mkSteamWrapper { }
+20
lib/pkgs/palworld-server.nix
···
+
self: {
+
lib,
+
...
+
}:
+
+
with lib;
+
self.mkSteamPackage {
+
name = "palworld-server";
+
version = "17082920";
+
appId = "2394010";
+
depotId = "2394012";
+
manifestId = "2423583208459052375";
+
hash = "sha256-gAFEDf/rKPQ5zTH8EJ93e4KKHUGi8uiYlPS7G2lWGWk=";
+
meta = {
+
description = "Palworld Dedicated Server";
+
homepage = "https://steamdb.info/app/2394010/";
+
changelog = "https://store.steampowered.com/news/app/1623730?updates=true";
+
sourceProvenance = with sourceTypes; [ sourceTypes.binaryNativeCode ];
+
};
+
}
+42
lib/pkgs/steamworks-sdk-redist.nix
···
+
self: pkgs @ {
+
lib,
+
stdenv,
+
...
+
}:
+
+
with lib;
+
stdenv.mkDerivation {
+
pname = "steamworks-sdk-redist";
+
version = "unstable-2024-05-30";
+
+
# Steamworks SDK Redist with steamclient.so.
+
# https://steamdb.info/app/1007/depots
+
src = self.fetchSteam {
+
appId = "1007";
+
depotId = "1006";
+
manifestId = "7138471031118904166";
+
hash = "sha256-OtPI1kAx6+9G09IEr2kYchyvxlPl3rzx/ai/xEVG4oM=";
+
};
+
+
dontConfigure = true;
+
dontBuild = true;
+
+
installPhase = ''
+
runHook preInstall
+
+
mkdir -p $out/lib
+
cp linux64/steamclient.so $out/lib
+
chmod +x $out/lib/steamclient.so
+
+
runHook postInstall
+
'';
+
+
meta = {
+
description = "Steamworks SDK Redist";
+
sourceProvenance = [ sourceTypes.binaryNativeCode ];
+
license = licenses.unfree;
+
badPlatforms = [
+
{ hasSharedLibraries = false; }
+
];
+
};
+
}
+27
lib/pkgs/systemd-transparent-udp-forwarderd.nix
···
+
pkgs @ {
+
stdenv,
+
cmake,
+
pkg-config,
+
fetchFromGitHub,
+
systemdLibs,
+
...
+
}:
+
+
stdenv.mkDerivation {
+
pname = "systemd-transparent-udp-forwarderd";
+
version = "0.0.1-add-activity-timeout-shutdown";
+
nativeBuildInputs = [ cmake pkg-config ];
+
buildInputs = [ systemdLibs ];
+
src = fetchFromGitHub {
+
owner = "cecton";
+
repo = "systemd-transparent-udp-forwarderd";
+
rev = "69072ef1271f013cefa91c239455d197f68d3f8e";
+
sha256 = "sha256-c4pui1aHw35Jw1pjCBgLQTHrjt5nYI2IUD4FqkyEd/M=";
+
};
+
+
installPhase = ''
+
runHook preInstall
+
install -Dm755 systemd-transparent-udp-forwarderd "$out/bin/$pname"
+
runHook postInstall
+
'';
+
}
-65
lib/pkgs/yeetmouse.nix
···
-
pkgs @ {
-
lib,
-
bash,
-
stdenv,
-
coreutils,
-
fetchFromGitHub,
-
kernel ? pkgs.linuxPackages_latest.kernel,
-
...
-
}:
-
-
stdenv.mkDerivation rec {
-
pname = "yeetmouse";
-
version = "ed39ee0457d330c751b689fe6e410acae8c40d4f";
-
-
src = fetchFromGitHub {
-
owner = "andyfilter";
-
repo = "yeetmouse";
-
rev = version;
-
sha256 = "sha256-8cr4WYX09ej81tRJOfEytnPGj51voDQA9tEH91ukC+s=";
-
};
-
-
setSourceRoot = "export sourceRoot=$(pwd)/source";
-
nativeBuildInputs = kernel.moduleBuildDependencies ++ [ pkgs.makeWrapper ];
-
buildInputs = [ pkgs.glfw3 ];
-
-
makeFlags = kernel.makeFlags ++ [
-
"-C"
-
"${kernel.dev}/lib/modules/${kernel.modDirVersion}/build"
-
"M=$(sourceRoot)/driver"
-
];
-
-
postUnpack = ''
-
cp -r $src/gui $sourceRoot/gui
-
chmod 755 -R $sourceRoot/gui
-
substituteInPlace $sourceRoot/driver/util.c \
-
--replace "#define NUM_USAGES 32" "#define NUM_USAGES 90"
-
'';
-
-
preBuild = ''
-
cp $sourceRoot/driver/config.sample.h $sourceRoot/driver/config.h
-
'';
-
-
LD_LIBRARY_PATH = "/run/opengl-driver/lib:${lib.makeLibraryPath buildInputs}";
-
-
postBuild = ''
-
make "-j$NIX_BUILD_CORES" -C $sourceRoot/gui "M=$sourceRoot/gui" "LIBS=-lglfw -lGL"
-
'';
-
-
postInstall = ''
-
install -Dm755 $sourceRoot/gui/YeetMouseGui $out/bin/yeetmouse
-
install -D $src/install_files/udev/99-leetmouse.rules $out/lib/udev/rules.d/98-leetmouse.rules
-
install -Dm755 $src/install_files/udev/leetmouse_bind $out/lib/udev/rules.d/leetmouse_bind
-
substituteInPlace $out/lib/udev/rules.d/98-leetmouse.rules \
-
--replace "PATH='/sbin:/bin:/usr/sbin:/usr/bin'" ""
-
patchShebangs $out/lib/udev/rules.d/leetmouse_bind
-
wrapProgram $out/lib/udev/rules.d/leetmouse_bind \
-
--prefix PATH : ${lib.makeBinPath [ bash coreutils ]}
-
substituteInPlace $out/lib/udev/rules.d/98-leetmouse.rules \
-
--replace "leetmouse_bind" "$out/lib/udev/rules.d/leetmouse_bind"
-
'';
-
-
buildFlags = [ "modules" ];
-
installFlags = [ "INSTALL_MOD_PATH=${placeholder "out"}" ];
-
installTargets = [ "modules_install" ];
-
}
+12 -5
modules/games/lib/fetchSteam.nix lib/pkgs/fetch-steam.nix
···
-
{ lib, pkgs, ... }:
+
self: pkgs @ {
+
lib,
+
runCommand,
+
depotdownloader,
+
cacert,
+
...
+
}:
-
with lib; makeOverridable (
+
with lib;
+
makeOverridable (
{
name ? "steamapp-${appId}-${depotId}-${manifestId}",
appId,
···
++ optionals debug [ "-debug" ];
drvArgs = {
-
depsBuildBuild = [ pkgs.depotdownloader ];
+
depsBuildBuild = [ depotdownloader ];
strictDeps = true;
···
outputHashMode = "recursive";
outputHash = if hash != "" then hash else fakeHash;
-
env.SSL_CERT_FILE = "${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt";
+
env.SSL_CERT_FILE = "${cacert}/etc/ssl/certs/ca-bundle.crt";
pos = builtins.unsafeGetAttrPos "manifestId" args;
inherit passthru;
} // optionalAttrs (args ? meta) { inherit meta; };
in
-
pkgs.runCommand name drvArgs ''
+
runCommand name drvArgs ''
HOME=$PWD DepotDownloader -dir "$out" ${escapeShellArgs downloadArgs}
rm -r "$out"/.DepotDownloader
''
-54
modules/games/lib/mkSteamPackage.nix
···
-
{ lib, helpers, pkgs, ... } @ inputs:
-
-
with lib;
-
let
-
fetchSteam = (import ./fetchSteam.nix) inputs;
-
inherit ((import ./steamworks.nix) inputs) steamworks-sdk-redist;
-
in
-
{
-
name,
-
hash ? "",
-
version,
-
appId,
-
depotId,
-
manifestId,
-
...
-
} @ args: let
-
mkDerivationArgs = builtins.removeAttrs args [ "name" "appId" "depotId" "manifestId" "hash" ];
-
in pkgs.stdenv.mkDerivation (rec {
-
pname = name;
-
src = fetchSteam {
-
inherit name appId depotId manifestId hash;
-
};
-
-
dontBuild = true;
-
dontConfigure = true;
-
dontFixup = helpers.system == "aarch64-linux";
-
-
appendRunpaths = with pkgs; makeLibraryPath [
-
steamworks-sdk-redist
-
glibc
-
libxcrypt
-
libGL
-
libdrm
-
mesa # for libgbm
-
udev
-
libudev0-shim
-
libva
-
vulkan-loader
-
];
-
-
nativeBuildInputs = optionals (helpers.system == "aarch64-linux") [
-
pkgs.autoPatchelfHook
-
];
-
-
installPhase = ''
-
runHook preInstall
-
-
mkdir -p $out
-
mv ./* $out
-
chmod 755 -R $out
-
-
runHook postInstall
-
'';
-
} // mkDerivationArgs)
-65
modules/games/lib/mkWrappedBox64.nix
···
-
{ lib, helpers, pkgs, ... } @ inputs:
-
-
with lib;
-
let
-
inherit ((import ./steamworks.nix) inputs) steamworks-sdk-redist;
-
-
defaultLibs = with pkgs; [
-
steamworks-sdk-redist
-
glibc
-
libxcrypt
-
libGL
-
libdrm
-
mesa # for libgbm
-
udev
-
libudev0-shim
-
libva
-
vulkan-loader
-
];
-
-
defaultNativeLibs = [ pkgs.pkgsCross.gnu64.libgcc ];
-
-
makeWrappedBox64 = {
-
logLevel ? 0,
-
env ? {},
-
libs ? defaultLibs,
-
nativeLibs ? defaultNativeLibs,
-
extraWrapperArgs ? [],
-
}: let
-
box64Bin = "${pkgs.box64}/bin/box64";
-
runpaths = libs ++ nativeLibs;
-
combinedEnv = {
-
BOX64_DYNAREC_STRONGMEM = 1;
-
BOX64_DYNAREC_BIGBLOCK = 1;
-
BOX64_DYNAREC_SAFEFLAGS = 1;
-
BOX64_DYNAREC_FASTROUND = 1;
-
BOX64_DYNAREC_FASTNAN = 1;
-
BOX64_DYNAREC_X87DOUBLE = 0;
-
} // env;
-
in bin:
-
pkgs.stdenv.mkDerivation rec {
-
name = "box64-wrapped";
-
-
dontUnpack = true;
-
dontConfigure = true;
-
dontBuild = true;
-
-
nativeBuildInputs = [ pkgs.makeWrapper ];
-
buildInputs = runpaths ++ libs;
-
-
installPhase = ''
-
runHook preInstall
-
makeWrapper "${box64Bin}" "$out/bin/box64" \
-
${concatStrings (mapAttrsToList (name: value: "--set ${name} '${toString value}' ") env)} \
-
--set BOX64_LOG "${toString logLevel}" \
-
--prefix LD_LIBRARY_PATH : ${lib.makeLibraryPath buildInputs} \
-
${lib.strings.concatStringsSep " " extraWrapperArgs} \
-
--add-flags "$bin"
-
runHook postInstall
-
'';
-
};
-
-
box64 = makeWrappedBox64 { };
-
identity = bin: bin;
-
in
-
if helpers.system == "aarch64-linux" then box64 else identity
modules/games/lib/serverScripts.nix modules/games/lib/scripts.nix
-42
modules/games/lib/steamworks.nix
···
-
{ lib, pkgs, ... } @ inputs:
-
-
with lib;
-
let
-
fetchSteam = (import ./fetchSteam.nix) inputs;
-
in {
-
steamworks-sdk-redist = pkgs.stdenv.mkDerivation {
-
pname = "steamworks-sdk-redist";
-
version = "unstable-2024-05-30";
-
-
# Steamworks SDK Redist with steamclient.so.
-
# https://steamdb.info/app/1007/depots
-
src = fetchSteam {
-
appId = "1007";
-
depotId = "1006";
-
manifestId = "7138471031118904166";
-
hash = "sha256-OtPI1kAx6+9G09IEr2kYchyvxlPl3rzx/ai/xEVG4oM=";
-
};
-
-
dontConfigure = true;
-
dontBuild = true;
-
-
installPhase = ''
-
runHook preInstall
-
-
mkdir -p $out/lib
-
cp linux64/steamclient.so $out/lib
-
chmod +x $out/lib/steamclient.so
-
-
runHook postInstall
-
'';
-
-
meta = {
-
description = "Steamworks SDK Redist";
-
sourceProvenance = [ sourceTypes.binaryNativeCode ];
-
license = licenses.unfree;
-
badPlatforms = [
-
{ hasSharedLibraries = false; }
-
];
-
};
-
};
-
}
+6 -24
modules/games/palworld.nix
···
cfg = config.modules.games.palworld;
name = "palworld-server";
-
serverScripts = (import ./lib/serverScripts.nix) args;
-
mkWrappedBox64 = (import ./lib/mkWrappedBox64.nix) args;
-
mkSteamPackage = (import ./lib/mkSteamPackage.nix) args;
-
inherit ((import ./lib/steamworks.nix) args) steamworks-sdk-redist;
+
scripts = (import ./lib/scripts.nix) args;
generateSettings = name: value: let
optionSettings =
···
OptionSettings=(${concatStringsSep "," optionSettings})
'';
-
palworld-server = mkSteamPackage {
-
name = "palworld-server";
-
version = "17082920";
-
appId = "2394010";
-
depotId = "2394012";
-
manifestId = "2423583208459052375";
-
hash = "sha256-gAFEDf/rKPQ5zTH8EJ93e4KKHUGi8uiYlPS7G2lWGWk=";
-
meta = {
-
description = "Palworld Dedicated Server";
-
homepage = "https://steamdb.info/app/2394010/";
-
changelog = "https://store.steampowered.com/news/app/1623730?updates=true";
-
sourceProvenance = with sourceTypes; [ sourceTypes.binaryNativeCode ];
-
};
-
};
-
baseSettings = {
ServerName = "Unnamed Server";
AllowConnectPlatform = "Steam";
···
package = mkOption {
type = types.package;
-
default = palworld-server;
+
default = pkgs.palworld-server;
};
public = mkOption {
···
files = let
settings = baseSettings // cfg.settings;
in {
-
"Pal/Binaries/Linux/steamclient.so" = "${steamworks-sdk-redist}/lib/steamclient.so";
+
"Pal/Binaries/Linux/steamclient.so" = "${pkgs.steamworks-sdk-redist}/lib/steamclient.so";
"Pal/Saved/Config/LinuxServer/PalWorldSettings.ini" = generateSettings "PalWorldSettings.ini" settings;
"Pal/Saved/Config/LinuxServer/Engine.ini" = builtins.toFile "Engine.ini" engineSettings;
};
···
]
++ optionals (cfg.ip != null) [ "-publicip=${cfg.ip}" ]
++ optionals cfg.public [ "-publiclobby" ];
-
bin = getBin (mkWrappedBox64 "${cfg.datadir}/Pal/Binaries/Linux/PalServer-Linux-Shipping");
+
bin = getExe (pkgs.mkSteamWrapper "${cfg.datadir}/Pal/Binaries/Linux/PalServer-Linux-Shipping");
in "${bin} ${concatStringsSep " " args}";
in {
wantedBy = mkIf cfg.autostart [ "multi-user.target" ];
···
inherit script;
preStart = ''
-
${serverScripts.mkDirs name dirs}
-
${serverScripts.mkFiles name files}
+
${scripts.mkDirs name dirs}
+
${scripts.mkFiles name files}
'';
serviceConfig = {