Configuration for my NixOS based systems and Home Manager
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Add Valheim game server

+145
+2
host-specific/odin/configuration.nix
··· 12 12 #./gui.nix 13 13 ./packages.nix 14 14 ./services.nix 15 + ./steam.nix 16 + ./valheim.nix 15 17 ]; 16 18 17 19 nixpkgs.config.allowUnfree = true;
+80
host-specific/odin/steam.nix
··· 1 + { 2 + pkgs, 3 + unstable, 4 + ... 5 + }: 6 + { 7 + users.users.steam = { 8 + isSystemUser = true; 9 + group = "steam"; 10 + home = "/var/lib/steam"; 11 + createHome = true; 12 + }; 13 + 14 + users.groups.steam = { }; 15 + 16 + systemd.services."steam@" = { 17 + unitConfig = { 18 + StopWhenUnneeded = true; 19 + }; 20 + serviceConfig = { 21 + Type = "oneshot"; 22 + ExecStart = "${ 23 + pkgs.resholve.writeScript "steam" 24 + { 25 + interpreter = "${pkgs.zsh}/bin/zsh"; 26 + inputs = with pkgs; [ 27 + patchelf 28 + unstable.steamcmd 29 + ]; 30 + execer = [ 31 + "cannot:${unstable.steamcmd}/bin/steamcmd" 32 + ]; 33 + } 34 + '' 35 + set -eux 36 + 37 + instance=''${1:?Instance Missing} 38 + eval 'args=(''${(@s:_:)instance})' 39 + app=''${args[1]:?App ID missing} 40 + beta=''${args[2]:-} 41 + betapass=''${args[3]:-} 42 + 43 + dir=/var/lib/steam-app-$instance 44 + 45 + cmds=( 46 + +force_install_dir $dir 47 + +login anonymous 48 + +app_update $app validate 49 + ) 50 + 51 + if [[ $beta ]]; then 52 + cmds+=(-beta $beta) 53 + if [[ $betapass ]]; then 54 + cmds+=(-betapassword $betapass) 55 + fi 56 + fi 57 + 58 + cmds+=(+quit) 59 + 60 + steamcmd $cmds 61 + 62 + for f in $dir/*; do 63 + if ! [[ -f $f && -x $f ]]; then 64 + continue 65 + fi 66 + 67 + # Update the interpreter to the path on NixOS. 68 + patchelf --set-interpreter ${pkgs.glibc}/lib/ld-linux-x86-64.so.2 $f || true 69 + done 70 + '' 71 + } %i"; 72 + PrivateTmp = true; 73 + Restart = "on-failure"; 74 + StateDirectory = "steam-app-%i"; 75 + TimeoutStartSec = 3600; # Allow time for updates. 76 + User = "steam"; 77 + WorkingDirectory = "~"; 78 + }; 79 + }; 80 + }
+63
host-specific/odin/valheim.nix
··· 1 + # See https://kevincox.ca/2022/12/09/valheim-server-nixos-v2/ 2 + { pkgs, utils, ... }: 3 + let 4 + # Set to {id}-{branch}-{password} for betas. 5 + steam-app = "896660"; 6 + in 7 + { 8 + imports = [ 9 + ./steam.nix 10 + ]; 11 + 12 + users.users.valheim = { 13 + isSystemUser = true; 14 + # Valheim puts save data in the home directory. 15 + home = "/var/lib/valheim"; 16 + createHome = true; 17 + homeMode = "750"; 18 + group = "valheim"; 19 + }; 20 + 21 + users.groups.valheim = { }; 22 + 23 + systemd.services.valheim = { 24 + wantedBy = [ "multi-user.target" ]; 25 + 26 + # Install the game before launching. 27 + wants = [ "steam@${steam-app}.service" ]; 28 + after = [ "steam@${steam-app}.service" ]; 29 + 30 + serviceConfig = { 31 + ExecStart = utils.escapeSystemdExecArgs [ 32 + "/var/lib/steam-app-${steam-app}/valheim_server.x86_64" 33 + "-nographics" 34 + "-batchmode" 35 + # "-crossplay" # This is broken because it looks for "party" shared library in the wrong path. 36 + "-savedir" 37 + "/var/lib/valheim/save" 38 + "-name" 39 + "rm -rf" 40 + "-port" 41 + "2456" 42 + "-world" 43 + "Dedicated" 44 + "-password" 45 + "Password123" 46 + "-public" 47 + "0" # Valheim now supports favourite servers in-game which I am using instead of listing in the public registry. 48 + "-backups" 49 + "3" # I take my own backups, if you don't you can remove this to use the built-in basic rotation system. 50 + ]; 51 + Nice = "-5"; 52 + PrivateTmp = true; 53 + Restart = "always"; 54 + User = "valheim"; 55 + WorkingDirectory = "~"; 56 + }; 57 + environment = { 58 + # linux64 directory is required by Valheim. 59 + LD_LIBRARY_PATH = "/var/lib/steam-app-${steam-app}/linux64:${pkgs.glibc}/lib"; 60 + SteamAppId = "892970"; 61 + }; 62 + }; 63 + }