Running a Valheim Dedicated Server on NixOS v2
Tags: valheim, nixos
Published: 2022-12-15 13:53:40

---
title: Running a Valheim Dedicated Server on NixOS v2
published: true
date: 2022-12-09 22:10:00 UTC
tags: Valheim,NixOS
canonical_url: https://kevincox.ca/2022/12/09/valheim-server-nixos-v2/
---

<main style="--width:min(36em,100%);display:grid;grid-template-columns:1fr var(--width) 1fr;overflow:auto;padding:0;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><p style="box-sizing:border-box;grid-column:2;margin:0 1rem .8em">This is an update to <a href="https://kevincox.ca/2021/02/16/valheim-dedicated-server-nixos" style="box-sizing:border-box;margin:0;text-decoration:underline;-webkit-text-decoration-color:gray;text-decoration-color:gray">a previous post</a> with some improvements and some fixes for more recent versions of Valheim.</p>
<p style="box-sizing:border-box;grid-column:2;margin:0 1rem .8em">Improvements:</p>
<ol style="box-sizing:border-box;grid-column:2;margin:0 1rem .8em">
<li style="box-sizing:border-box;margin:0">Game download is separated from the game running.<ul style='box-sizing:border-box;list-style:disc;list-style:"- ";margin:0'>
<li style="box-sizing:border-box;margin:0">This allows running multiple isolated instances on the same server sharing the game code.</li>
<li style="box-sizing:border-box;margin:0">If the download fails (for example Steam is down) the old version continues running.</li>
</ul>
</li>
<li style="box-sizing:border-box;margin:0">Updates to game execution. The old method of calling the linker stopped working due to the way that Valheim tries to find it’s data files (it was looking relative to the linker instead of it’s own executable).</li>
<li style="box-sizing:border-box;margin:0">Updates to take advantage of new flags.<ul style='box-sizing:border-box;list-style:disc;list-style:"- ";margin:0'>
<li style="box-sizing:border-box;margin:0">Save resources by disabling graphics.</li>
<li style="box-sizing:border-box;margin:0">Disable backups since we have our own.</li>
</ul>
</li>
</ol>
<p style="box-sizing:border-box;grid-column:2;margin:0 1rem .8em">So without further ado here is the new code:</p>
<h1 id="valheim-service" style="box-sizing:border-box;grid-column:2;margin:.4em 1rem .8em"><a href="https://kevincox.ca/2022/12/09/valheim-server-nixos-v2/#valheim-service" style="box-sizing:border-box;color:inherit!important;margin:0;text-decoration:inherit;text-decoration:underline;-webkit-text-decoration-color:gray;text-decoration-color:gray;text-shadow:inherit!important">Valheim Service</a></h1>
<div style="background:#222;border-bottom:1px solid #444;border-top:1px solid #444;box-sizing:border-box;display:grid;grid-column:2;grid-column:1/4;grid-template-columns:1fr var(--width) 1fr;margin:0 0 .8em;overflow-x:auto;padding:0"><pre style="box-sizing:border-box;grid-column:2;margin:.4em 1rem;-moz-tab-size:2;-o-tab-size:2;tab-size:2"><code style="background:none!important;box-sizing:border-box;color:#fff;margin:0;white-space:pre-wrap;white-space:pre"><span style="box-sizing:border-box;color:#ccc;font-style:italic;margin:0;padding:0;white-space:pre-wrap"># valheim.nix</span>
<span style="box-sizing:border-box;color:#999;margin:0;padding:0">{</span><span style="box-sizing:border-box;color:#759ef0;margin:0;padding:0">config</span><span style="box-sizing:border-box;color:#999;margin:0;padding:0">,</span> <span style="box-sizing:border-box;color:#759ef0;margin:0;padding:0">pkgs</span><span style="box-sizing:border-box;color:#999;margin:0;padding:0">,</span> <span style="box-sizing:border-box;color:#759ef0;margin:0;padding:0">lib</span><span style="box-sizing:border-box;color:#999;margin:0;padding:0">,</span> <span style="box-sizing:border-box;color:#f5a3a3;font-weight:700;margin:0;padding:0">...</span><span style="box-sizing:border-box;color:#999;margin:0;padding:0">}:</span> <span style="box-sizing:border-box;color:#8585e0;font-weight:700;margin:0;padding:0">let</span>
	<span style="box-sizing:border-box;color:#ccc;font-style:italic;margin:0;padding:0;white-space:pre-wrap"># Set to {id}-{branch}-{password} for betas.</span>
	<span style="box-sizing:border-box;color:#759ef0;margin:0;padding:0">steam-app</span> <span style="box-sizing:border-box;color:#f5a3a3;font-weight:700;margin:0;padding:0">=</span> <span style="box-sizing:border-box;color:#b3d733;margin:0;padding:0">"896660"</span><span style="box-sizing:border-box;color:#999;margin:0;padding:0">;</span>
<span style="box-sizing:border-box;color:#8585e0;font-weight:700;margin:0;padding:0">in</span> <span style="box-sizing:border-box;color:#999;margin:0;padding:0">{</span>
	<span style="box-sizing:border-box;color:#759ef0;margin:0;padding:0">imports</span> <span style="box-sizing:border-box;color:#f5a3a3;font-weight:700;margin:0;padding:0">=</span> <span style="box-sizing:border-box;color:#999;margin:0;padding:0">[</span>
		<span style="box-sizing:border-box;color:#b3d733;margin:0;padding:0">./steam.nix</span>
	<span style="box-sizing:border-box;color:#999;margin:0;padding:0">];</span>

	<span style="box-sizing:border-box;color:#759ef0;margin:0;padding:0">users</span><span style="box-sizing:border-box;color:#f5a3a3;font-weight:700;margin:0;padding:0">.</span><span style="box-sizing:border-box;color:#759ef0;margin:0;padding:0">users</span><span style="box-sizing:border-box;color:#f5a3a3;font-weight:700;margin:0;padding:0">.</span><span style="box-sizing:border-box;color:#759ef0;margin:0;padding:0">valheim</span> <span style="box-sizing:border-box;color:#f5a3a3;font-weight:700;margin:0;padding:0">=</span> <span style="box-sizing:border-box;color:#999;margin:0;padding:0">{</span>
		<span style="box-sizing:border-box;color:#759ef0;margin:0;padding:0">isSystemUser</span> <span style="box-sizing:border-box;color:#f5a3a3;font-weight:700;margin:0;padding:0">=</span> <span style="box-sizing:border-box;color:#8585e0;color:#ffb433;font-weight:700;margin:0;padding:0">true</span><span style="box-sizing:border-box;color:#999;margin:0;padding:0">;</span>
		<span style="box-sizing:border-box;color:#ccc;font-style:italic;margin:0;padding:0;white-space:pre-wrap"># Valheim puts save data in the home directory.</span>
		<span style="box-sizing:border-box;color:#759ef0;margin:0;padding:0">home</span> <span style="box-sizing:border-box;color:#f5a3a3;font-weight:700;margin:0;padding:0">=</span> <span style="box-sizing:border-box;color:#b3d733;margin:0;padding:0">"/var/lib/valheim"</span><span style="box-sizing:border-box;color:#999;margin:0;padding:0">;</span>
		<span style="box-sizing:border-box;color:#759ef0;margin:0;padding:0">createHome</span> <span style="box-sizing:border-box;color:#f5a3a3;font-weight:700;margin:0;padding:0">=</span> <span style="box-sizing:border-box;color:#8585e0;color:#ffb433;font-weight:700;margin:0;padding:0">true</span><span style="box-sizing:border-box;color:#999;margin:0;padding:0">;</span>
		<span style="box-sizing:border-box;color:#759ef0;margin:0;padding:0">homeMode</span> <span style="box-sizing:border-box;color:#f5a3a3;font-weight:700;margin:0;padding:0">=</span> <span style="box-sizing:border-box;color:#b3d733;margin:0;padding:0">"750"</span><span style="box-sizing:border-box;color:#999;margin:0;padding:0">;</span>
		<span style="box-sizing:border-box;color:#759ef0;margin:0;padding:0">group</span> <span style="box-sizing:border-box;color:#f5a3a3;font-weight:700;margin:0;padding:0">=</span> <span style="box-sizing:border-box;color:#b3d733;margin:0;padding:0">"valheim"</span><span style="box-sizing:border-box;color:#999;margin:0;padding:0">;</span>
	<span style="box-sizing:border-box;color:#999;margin:0;padding:0">};</span>

	<span style="box-sizing:border-box;color:#759ef0;margin:0;padding:0">users</span><span style="box-sizing:border-box;color:#f5a3a3;font-weight:700;margin:0;padding:0">.</span><span style="box-sizing:border-box;color:#759ef0;margin:0;padding:0">groups</span><span style="box-sizing:border-box;color:#f5a3a3;font-weight:700;margin:0;padding:0">.</span><span style="box-sizing:border-box;color:#759ef0;margin:0;padding:0">valheim</span> <span style="box-sizing:border-box;color:#f5a3a3;font-weight:700;margin:0;padding:0">=</span> <span style="box-sizing:border-box;color:#999;margin:0;padding:0">{};</span>

	<span style="box-sizing:border-box;color:#759ef0;margin:0;padding:0">systemd</span><span style="box-sizing:border-box;color:#f5a3a3;font-weight:700;margin:0;padding:0">.</span><span style="box-sizing:border-box;color:#759ef0;margin:0;padding:0">services</span><span style="box-sizing:border-box;color:#f5a3a3;font-weight:700;margin:0;padding:0">.</span><span style="box-sizing:border-box;color:#759ef0;margin:0;padding:0">valheim</span> <span style="box-sizing:border-box;color:#f5a3a3;font-weight:700;margin:0;padding:0">=</span> <span style="box-sizing:border-box;color:#999;margin:0;padding:0">{</span>
		<span style="box-sizing:border-box;color:#759ef0;margin:0;padding:0">wantedBy</span> <span style="box-sizing:border-box;color:#f5a3a3;font-weight:700;margin:0;padding:0">=</span> <span style="box-sizing:border-box;color:#999;margin:0;padding:0">[</span> <span style="box-sizing:border-box;color:#b3d733;margin:0;padding:0">"multi-user.target"</span> <span style="box-sizing:border-box;color:#999;margin:0;padding:0">];</span>

		<span style="box-sizing:border-box;color:#ccc;font-style:italic;margin:0;padding:0;white-space:pre-wrap"># Install the game before launching.</span>
		<span style="box-sizing:border-box;color:#759ef0;margin:0;padding:0">wants</span> <span style="box-sizing:border-box;color:#f5a3a3;font-weight:700;margin:0;padding:0">=</span> <span style="box-sizing:border-box;color:#999;margin:0;padding:0">[</span> <span style="box-sizing:border-box;color:#b3d733;margin:0;padding:0">"steam@</span><span style="box-sizing:border-box;color:#b3d733;margin:0;padding:0">${</span><span style="box-sizing:border-box;color:#759ef0;margin:0;padding:0">steam-app</span><span style="box-sizing:border-box;color:#b3d733;margin:0;padding:0">}</span><span style="box-sizing:border-box;color:#b3d733;margin:0;padding:0">.service"</span> <span style="box-sizing:border-box;color:#999;margin:0;padding:0">];</span>
		<span style="box-sizing:border-box;color:#759ef0;margin:0;padding:0">after</span> <span style="box-sizing:border-box;color:#f5a3a3;font-weight:700;margin:0;padding:0">=</span> <span style="box-sizing:border-box;color:#999;margin:0;padding:0">[</span> <span style="box-sizing:border-box;color:#b3d733;margin:0;padding:0">"steam@</span><span style="box-sizing:border-box;color:#b3d733;margin:0;padding:0">${</span><span style="box-sizing:border-box;color:#759ef0;margin:0;padding:0">steam-app</span><span style="box-sizing:border-box;color:#b3d733;margin:0;padding:0">}</span><span style="box-sizing:border-box;color:#b3d733;margin:0;padding:0">.service"</span> <span style="box-sizing:border-box;color:#999;margin:0;padding:0">];</span>

		<span style="box-sizing:border-box;color:#759ef0;margin:0;padding:0">serviceConfig</span> <span style="box-sizing:border-box;color:#f5a3a3;font-weight:700;margin:0;padding:0">=</span> <span style="box-sizing:border-box;color:#999;margin:0;padding:0">{</span>
			<span style="box-sizing:border-box;color:#759ef0;margin:0;padding:0">ExecStart</span> <span style="box-sizing:border-box;color:#f5a3a3;font-weight:700;margin:0;padding:0">=</span> <span style="box-sizing:border-box;color:#759ef0;margin:0;padding:0">lib</span><span style="box-sizing:border-box;color:#f5a3a3;font-weight:700;margin:0;padding:0">.</span><span style="box-sizing:border-box;color:#759ef0;margin:0;padding:0">escapeShellArgs</span> <span style="box-sizing:border-box;color:#999;margin:0;padding:0">[</span>
				<span style="box-sizing:border-box;color:#b3d733;margin:0;padding:0">"/var/lib/steam-app-</span><span style="box-sizing:border-box;color:#b3d733;margin:0;padding:0">${</span><span style="box-sizing:border-box;color:#759ef0;margin:0;padding:0">steam-app</span><span style="box-sizing:border-box;color:#b3d733;margin:0;padding:0">}</span><span style="box-sizing:border-box;color:#b3d733;margin:0;padding:0">/valheim_server.x86_64"</span>
				<span style="box-sizing:border-box;color:#b3d733;margin:0;padding:0">"-nographics"</span>
				<span style="box-sizing:border-box;color:#b3d733;margin:0;padding:0">"-batchmode"</span>
				<span style="box-sizing:border-box;color:#ccc;font-style:italic;margin:0;padding:0;white-space:pre-wrap"># "-crossplay" # This is broken because it looks for "party" shared library in the wrong path.</span>
				<span style="box-sizing:border-box;color:#b3d733;margin:0;padding:0">"-savedir"</span> <span style="box-sizing:border-box;color:#b3d733;margin:0;padding:0">"/var/lib/valheim/save"</span>
				<span style="box-sizing:border-box;color:#b3d733;margin:0;padding:0">"-name"</span> <span style="box-sizing:border-box;color:#b3d733;margin:0;padding:0">"YOUR SERVER NAME"</span>
				<span style="box-sizing:border-box;color:#b3d733;margin:0;padding:0">"-port"</span> <span style="box-sizing:border-box;color:#b3d733;margin:0;padding:0">"2456"</span>
				<span style="box-sizing:border-box;color:#b3d733;margin:0;padding:0">"-world"</span> <span style="box-sizing:border-box;color:#b3d733;margin:0;padding:0">"Dedicated"</span>
				<span style="box-sizing:border-box;color:#b3d733;margin:0;padding:0">"-password"</span> <span style="box-sizing:border-box;color:#b3d733;margin:0;padding:0">"YOUR PASSWORD HERE!!!"</span>
				<span style="box-sizing:border-box;color:#b3d733;margin:0;padding:0">"-public"</span> <span style="box-sizing:border-box;color:#b3d733;margin:0;padding:0">"0"</span> <span style="box-sizing:border-box;color:#ccc;font-style:italic;margin:0;padding:0;white-space:pre-wrap"># Valheim now supports favourite servers in-game which I am using instead of listing in the public registry.</span>
				<span style="box-sizing:border-box;color:#b3d733;margin:0;padding:0">"-backups"</span> <span style="box-sizing:border-box;color:#b3d733;margin:0;padding:0">"0"</span> <span style="box-sizing:border-box;color:#ccc;font-style:italic;margin:0;padding:0;white-space:pre-wrap"># I take my own backups, if you don't you can remove this to use the built-in basic rotation system.</span>
			<span style="box-sizing:border-box;color:#999;margin:0;padding:0">];</span>
			<span style="box-sizing:border-box;color:#759ef0;margin:0;padding:0">Nice</span> <span style="box-sizing:border-box;color:#f5a3a3;font-weight:700;margin:0;padding:0">=</span> <span style="box-sizing:border-box;color:#b3d733;margin:0;padding:0">"-5"</span><span style="box-sizing:border-box;color:#999;margin:0;padding:0">;</span>
			<span style="box-sizing:border-box;color:#759ef0;margin:0;padding:0">PrivateTmp</span> <span style="box-sizing:border-box;color:#f5a3a3;font-weight:700;margin:0;padding:0">=</span> <span style="box-sizing:border-box;color:#8585e0;color:#ffb433;font-weight:700;margin:0;padding:0">true</span><span style="box-sizing:border-box;color:#999;margin:0;padding:0">;</span>
			<span style="box-sizing:border-box;color:#759ef0;margin:0;padding:0">Restart</span> <span style="box-sizing:border-box;color:#f5a3a3;font-weight:700;margin:0;padding:0">=</span> <span style="box-sizing:border-box;color:#b3d733;margin:0;padding:0">"always"</span><span style="box-sizing:border-box;color:#999;margin:0;padding:0">;</span>
			<span style="box-sizing:border-box;color:#759ef0;margin:0;padding:0">User</span> <span style="box-sizing:border-box;color:#f5a3a3;font-weight:700;margin:0;padding:0">=</span> <span style="box-sizing:border-box;color:#b3d733;margin:0;padding:0">"valheim"</span><span style="box-sizing:border-box;color:#999;margin:0;padding:0">;</span>
			<span style="box-sizing:border-box;color:#759ef0;margin:0;padding:0">WorkingDirectory</span> <span style="box-sizing:border-box;color:#f5a3a3;font-weight:700;margin:0;padding:0">=</span> <span style="box-sizing:border-box;color:#b3d733;margin:0;padding:0">"~"</span><span style="box-sizing:border-box;color:#999;margin:0;padding:0">;</span>
		<span style="box-sizing:border-box;color:#999;margin:0;padding:0">};</span>
		<span style="box-sizing:border-box;color:#759ef0;margin:0;padding:0">environment</span> <span style="box-sizing:border-box;color:#f5a3a3;font-weight:700;margin:0;padding:0">=</span> <span style="box-sizing:border-box;color:#999;margin:0;padding:0">{</span>
			<span style="box-sizing:border-box;color:#ccc;font-style:italic;margin:0;padding:0;white-space:pre-wrap"># linux64 directory is required by Valheim.</span>
			<span style="box-sizing:border-box;color:#759ef0;margin:0;padding:0">LD_LIBRARY_PATH</span> <span style="box-sizing:border-box;color:#f5a3a3;font-weight:700;margin:0;padding:0">=</span> <span style="box-sizing:border-box;color:#b3d733;margin:0;padding:0">"/var/lib/steam-app-</span><span style="box-sizing:border-box;color:#b3d733;margin:0;padding:0">${</span><span style="box-sizing:border-box;color:#759ef0;margin:0;padding:0">steam-app</span><span style="box-sizing:border-box;color:#b3d733;margin:0;padding:0">}</span><span style="box-sizing:border-box;color:#b3d733;margin:0;padding:0">/linux64:</span><span style="box-sizing:border-box;color:#b3d733;margin:0;padding:0">${</span><span style="box-sizing:border-box;color:#759ef0;margin:0;padding:0">pkgs</span><span style="box-sizing:border-box;color:#f5a3a3;font-weight:700;margin:0;padding:0">.</span><span style="box-sizing:border-box;color:#759ef0;margin:0;padding:0">glibc</span><span style="box-sizing:border-box;color:#b3d733;margin:0;padding:0">}</span><span style="box-sizing:border-box;color:#b3d733;margin:0;padding:0">/lib"</span><span style="box-sizing:border-box;color:#999;margin:0;padding:0">;</span>
			<span style="box-sizing:border-box;color:#759ef0;margin:0;padding:0">SteamAppId</span> <span style="box-sizing:border-box;color:#f5a3a3;font-weight:700;margin:0;padding:0">=</span> <span style="box-sizing:border-box;color:#b3d733;margin:0;padding:0">"892970"</span><span style="box-sizing:border-box;color:#999;margin:0;padding:0">;</span>
		<span style="box-sizing:border-box;color:#999;margin:0;padding:0">};</span>
	<span style="box-sizing:border-box;color:#999;margin:0;padding:0">};</span>

	<span style="box-sizing:border-box;color:#ccc;font-style:italic;margin:0;padding:0;white-space:pre-wrap"># This is my custom backup machinery. Substitute your own 🙂</span>
	<span style="box-sizing:border-box;color:#759ef0;margin:0;padding:0">kevincox</span><span style="box-sizing:border-box;color:#f5a3a3;font-weight:700;margin:0;padding:0">.</span><span style="box-sizing:border-box;color:#759ef0;margin:0;padding:0">backup</span><span style="box-sizing:border-box;color:#f5a3a3;font-weight:700;margin:0;padding:0">.</span><span style="box-sizing:border-box;color:#759ef0;margin:0;padding:0">valheim</span> <span style="box-sizing:border-box;color:#f5a3a3;font-weight:700;margin:0;padding:0">=</span> <span style="box-sizing:border-box;color:#999;margin:0;padding:0">{</span>
		<span style="box-sizing:border-box;color:#759ef0;margin:0;padding:0">paths</span> <span style="box-sizing:border-box;color:#f5a3a3;font-weight:700;margin:0;padding:0">=</span> <span style="box-sizing:border-box;color:#999;margin:0;padding:0">[</span>
			<span style="box-sizing:border-box;color:#b3d733;margin:0;padding:0">"/var/lib/valheim/save/"</span>
		<span style="box-sizing:border-box;color:#999;margin:0;padding:0">];</span>
	<span style="box-sizing:border-box;color:#999;margin:0;padding:0">};</span>
</code></pre></div>
<h1 id="steam-downloader" style="box-sizing:border-box;grid-column:2;margin:.4em 1rem .8em"><a href="https://kevincox.ca/2022/12/09/valheim-server-nixos-v2/#steam-downloader" style="box-sizing:border-box;color:inherit!important;margin:0;text-decoration:inherit;text-decoration:underline;-webkit-text-decoration-color:gray;text-decoration-color:gray;text-shadow:inherit!important">Steam Downloader</a></h1>
<div style="background:#222;border-bottom:1px solid #444;border-top:1px solid #444;box-sizing:border-box;display:grid;grid-column:2;grid-column:1/4;grid-template-columns:1fr var(--width) 1fr;margin:0 0 .8em;overflow-x:auto;padding:0"><pre style="box-sizing:border-box;grid-column:2;margin:.4em 1rem;-moz-tab-size:2;-o-tab-size:2;tab-size:2"><code style="background:none!important;box-sizing:border-box;color:#fff;margin:0;white-space:pre-wrap;white-space:pre"><span style="box-sizing:border-box;color:#ccc;font-style:italic;margin:0;padding:0;white-space:pre-wrap"># steam.nix</span>
<span style="box-sizing:border-box;color:#999;margin:0;padding:0">{</span><span style="box-sizing:border-box;color:#759ef0;margin:0;padding:0">config</span><span style="box-sizing:border-box;color:#999;margin:0;padding:0">,</span> <span style="box-sizing:border-box;color:#759ef0;margin:0;padding:0">pkgs</span><span style="box-sizing:border-box;color:#999;margin:0;padding:0">,</span> <span style="box-sizing:border-box;color:#759ef0;margin:0;padding:0">lib</span><span style="box-sizing:border-box;color:#999;margin:0;padding:0">,</span> <span style="box-sizing:border-box;color:#f5a3a3;font-weight:700;margin:0;padding:0">...</span><span style="box-sizing:border-box;color:#999;margin:0;padding:0">}:</span> <span style="box-sizing:border-box;color:#999;margin:0;padding:0">{</span>
	<span style="box-sizing:border-box;color:#759ef0;margin:0;padding:0">users</span><span style="box-sizing:border-box;color:#f5a3a3;font-weight:700;margin:0;padding:0">.</span><span style="box-sizing:border-box;color:#759ef0;margin:0;padding:0">users</span><span style="box-sizing:border-box;color:#f5a3a3;font-weight:700;margin:0;padding:0">.</span><span style="box-sizing:border-box;color:#759ef0;margin:0;padding:0">steam</span> <span style="box-sizing:border-box;color:#f5a3a3;font-weight:700;margin:0;padding:0">=</span> <span style="box-sizing:border-box;color:#999;margin:0;padding:0">{</span>
		<span style="box-sizing:border-box;color:#759ef0;margin:0;padding:0">isSystemUser</span> <span style="box-sizing:border-box;color:#f5a3a3;font-weight:700;margin:0;padding:0">=</span> <span style="box-sizing:border-box;color:#8585e0;color:#ffb433;font-weight:700;margin:0;padding:0">true</span><span style="box-sizing:border-box;color:#999;margin:0;padding:0">;</span>
		<span style="box-sizing:border-box;color:#759ef0;margin:0;padding:0">group</span> <span style="box-sizing:border-box;color:#f5a3a3;font-weight:700;margin:0;padding:0">=</span> <span style="box-sizing:border-box;color:#b3d733;margin:0;padding:0">"steam"</span><span style="box-sizing:border-box;color:#999;margin:0;padding:0">;</span>
		<span style="box-sizing:border-box;color:#759ef0;margin:0;padding:0">home</span> <span style="box-sizing:border-box;color:#f5a3a3;font-weight:700;margin:0;padding:0">=</span> <span style="box-sizing:border-box;color:#b3d733;margin:0;padding:0">"/var/lib/steam"</span><span style="box-sizing:border-box;color:#999;margin:0;padding:0">;</span>
		<span style="box-sizing:border-box;color:#759ef0;margin:0;padding:0">createHome</span> <span style="box-sizing:border-box;color:#f5a3a3;font-weight:700;margin:0;padding:0">=</span> <span style="box-sizing:border-box;color:#8585e0;color:#ffb433;font-weight:700;margin:0;padding:0">true</span><span style="box-sizing:border-box;color:#999;margin:0;padding:0">;</span>
	<span style="box-sizing:border-box;color:#999;margin:0;padding:0">};</span>

	<span style="box-sizing:border-box;color:#759ef0;margin:0;padding:0">users</span><span style="box-sizing:border-box;color:#f5a3a3;font-weight:700;margin:0;padding:0">.</span><span style="box-sizing:border-box;color:#759ef0;margin:0;padding:0">groups</span><span style="box-sizing:border-box;color:#f5a3a3;font-weight:700;margin:0;padding:0">.</span><span style="box-sizing:border-box;color:#759ef0;margin:0;padding:0">steam</span> <span style="box-sizing:border-box;color:#f5a3a3;font-weight:700;margin:0;padding:0">=</span> <span style="box-sizing:border-box;color:#999;margin:0;padding:0">{};</span>

	<span style="box-sizing:border-box;color:#759ef0;margin:0;padding:0">systemd</span><span style="box-sizing:border-box;color:#f5a3a3;font-weight:700;margin:0;padding:0">.</span><span style="box-sizing:border-box;color:#759ef0;margin:0;padding:0">services</span><span style="box-sizing:border-box;color:#f5a3a3;font-weight:700;margin:0;padding:0">.</span><span style="box-sizing:border-box;color:#b3d733;margin:0;padding:0">"steam@"</span> <span style="box-sizing:border-box;color:#f5a3a3;font-weight:700;margin:0;padding:0">=</span> <span style="box-sizing:border-box;color:#999;margin:0;padding:0">{</span>
		<span style="box-sizing:border-box;color:#759ef0;margin:0;padding:0">unitConfig</span> <span style="box-sizing:border-box;color:#f5a3a3;font-weight:700;margin:0;padding:0">=</span> <span style="box-sizing:border-box;color:#999;margin:0;padding:0">{</span>
			<span style="box-sizing:border-box;color:#759ef0;margin:0;padding:0">StopWhenUnneeded</span> <span style="box-sizing:border-box;color:#f5a3a3;font-weight:700;margin:0;padding:0">=</span> <span style="box-sizing:border-box;color:#8585e0;color:#ffb433;font-weight:700;margin:0;padding:0">true</span><span style="box-sizing:border-box;color:#999;margin:0;padding:0">;</span>
		<span style="box-sizing:border-box;color:#999;margin:0;padding:0">};</span>
		<span style="box-sizing:border-box;color:#759ef0;margin:0;padding:0">serviceConfig</span> <span style="box-sizing:border-box;color:#f5a3a3;font-weight:700;margin:0;padding:0">=</span> <span style="box-sizing:border-box;color:#999;margin:0;padding:0">{</span>
			<span style="box-sizing:border-box;color:#759ef0;margin:0;padding:0">Type</span> <span style="box-sizing:border-box;color:#f5a3a3;font-weight:700;margin:0;padding:0">=</span> <span style="box-sizing:border-box;color:#b3d733;margin:0;padding:0">"oneshot"</span><span style="box-sizing:border-box;color:#999;margin:0;padding:0">;</span>
			<span style="box-sizing:border-box;color:#759ef0;margin:0;padding:0">ExecStart</span> <span style="box-sizing:border-box;color:#f5a3a3;font-weight:700;margin:0;padding:0">=</span> <span style="box-sizing:border-box;color:#b3d733;margin:0;padding:0">"</span><span style="box-sizing:border-box;color:#b3d733;margin:0;padding:0">${</span><span style="box-sizing:border-box;color:#759ef0;margin:0;padding:0">pkgs</span><span style="box-sizing:border-box;color:#f5a3a3;font-weight:700;margin:0;padding:0">.</span><span style="box-sizing:border-box;color:#759ef0;margin:0;padding:0">resholve</span><span style="box-sizing:border-box;color:#f5a3a3;font-weight:700;margin:0;padding:0">.</span><span style="box-sizing:border-box;color:#759ef0;margin:0;padding:0">writeScript</span> <span style="box-sizing:border-box;color:#b3d733;margin:0;padding:0">"steam"</span> <span style="box-sizing:border-box;color:#999;margin:0;padding:0">{</span>
				<span style="box-sizing:border-box;color:#759ef0;margin:0;padding:0">interpreter</span> <span style="box-sizing:border-box;color:#f5a3a3;font-weight:700;margin:0;padding:0">=</span> <span style="box-sizing:border-box;color:#b3d733;margin:0;padding:0">"</span><span style="box-sizing:border-box;color:#b3d733;margin:0;padding:0">${</span><span style="box-sizing:border-box;color:#759ef0;margin:0;padding:0">pkgs</span><span style="box-sizing:border-box;color:#f5a3a3;font-weight:700;margin:0;padding:0">.</span><span style="box-sizing:border-box;color:#759ef0;margin:0;padding:0">zsh</span><span style="box-sizing:border-box;color:#b3d733;margin:0;padding:0">}</span><span style="box-sizing:border-box;color:#b3d733;margin:0;padding:0">/bin/zsh"</span><span style="box-sizing:border-box;color:#999;margin:0;padding:0">;</span>
				<span style="box-sizing:border-box;color:#759ef0;margin:0;padding:0">inputs</span> <span style="box-sizing:border-box;color:#f5a3a3;font-weight:700;margin:0;padding:0">=</span> <span style="box-sizing:border-box;color:#8585e0;font-weight:700;margin:0;padding:0">with</span> <span style="box-sizing:border-box;color:#759ef0;margin:0;padding:0">pkgs</span><span style="box-sizing:border-box;color:#999;margin:0;padding:0">;</span> <span style="box-sizing:border-box;color:#999;margin:0;padding:0">[</span>
					<span style="box-sizing:border-box;color:#759ef0;margin:0;padding:0">patchelf</span>
					<span style="box-sizing:border-box;color:#759ef0;margin:0;padding:0">steamcmd</span>
				<span style="box-sizing:border-box;color:#999;margin:0;padding:0">];</span>
				<span style="box-sizing:border-box;color:#759ef0;margin:0;padding:0">execer</span> <span style="box-sizing:border-box;color:#f5a3a3;font-weight:700;margin:0;padding:0">=</span> <span style="box-sizing:border-box;color:#8585e0;font-weight:700;margin:0;padding:0">with</span> <span style="box-sizing:border-box;color:#759ef0;margin:0;padding:0">pkgs</span><span style="box-sizing:border-box;color:#999;margin:0;padding:0">;</span> <span style="box-sizing:border-box;color:#999;margin:0;padding:0">[</span>
					<span style="box-sizing:border-box;color:#b3d733;margin:0;padding:0">"cannot:</span><span style="box-sizing:border-box;color:#b3d733;margin:0;padding:0">${</span><span style="box-sizing:border-box;color:#759ef0;margin:0;padding:0">steamcmd</span><span style="box-sizing:border-box;color:#b3d733;margin:0;padding:0">}</span><span style="box-sizing:border-box;color:#b3d733;margin:0;padding:0">/bin/steamcmd"</span>
				<span style="box-sizing:border-box;color:#999;margin:0;padding:0">];</span>
			<span style="box-sizing:border-box;color:#999;margin:0;padding:0">}</span> <span style="box-sizing:border-box;color:#b3d733;margin:0;padding:0">''</span><span style="background-color:#1e0010;box-sizing:border-box;color:#960050;margin:0;padding:0">
</span><span style="box-sizing:border-box;color:#b3d733;margin:0;padding:0"> set -eux</span><span style="background-color:#1e0010;box-sizing:border-box;color:#960050;margin:0;padding:0">

</span><span style="box-sizing:border-box;color:#b3d733;margin:0;padding:0"> instance=</span><span style="box-sizing:border-box;color:#b3d733;margin:0;padding:0">''$</span><span style="box-sizing:border-box;color:#b3d733;margin:0;padding:0">{1:?Instance Missing}</span><span style="background-color:#1e0010;box-sizing:border-box;color:#960050;margin:0;padding:0">
</span><span style="box-sizing:border-box;color:#b3d733;margin:0;padding:0"> eval 'args=(</span><span style="box-sizing:border-box;color:#b3d733;margin:0;padding:0">''$</span><span style="box-sizing:border-box;color:#b3d733;margin:0;padding:0">{(@s:_:)instance})'</span><span style="background-color:#1e0010;box-sizing:border-box;color:#960050;margin:0;padding:0">
</span><span style="box-sizing:border-box;color:#b3d733;margin:0;padding:0"> app=</span><span style="box-sizing:border-box;color:#b3d733;margin:0;padding:0">''$</span><span style="box-sizing:border-box;color:#b3d733;margin:0;padding:0">{args[1]:?App ID missing}</span><span style="background-color:#1e0010;box-sizing:border-box;color:#960050;margin:0;padding:0">
</span><span style="box-sizing:border-box;color:#b3d733;margin:0;padding:0"> beta=</span><span style="box-sizing:border-box;color:#b3d733;margin:0;padding:0">''$</span><span style="box-sizing:border-box;color:#b3d733;margin:0;padding:0">{args[2]:-}</span><span style="background-color:#1e0010;box-sizing:border-box;color:#960050;margin:0;padding:0">
</span><span style="box-sizing:border-box;color:#b3d733;margin:0;padding:0"> betapass=</span><span style="box-sizing:border-box;color:#b3d733;margin:0;padding:0">''$</span><span style="box-sizing:border-box;color:#b3d733;margin:0;padding:0">{args[3]:-}</span><span style="background-color:#1e0010;box-sizing:border-box;color:#960050;margin:0;padding:0">

</span><span style="box-sizing:border-box;color:#b3d733;margin:0;padding:0"> dir=/var/lib/steam-app-$instance</span><span style="background-color:#1e0010;box-sizing:border-box;color:#960050;margin:0;padding:0">

</span><span style="box-sizing:border-box;color:#b3d733;margin:0;padding:0"> cmds=(</span><span style="background-color:#1e0010;box-sizing:border-box;color:#960050;margin:0;padding:0">
</span><span style="box-sizing:border-box;color:#b3d733;margin:0;padding:0"> +force_install_dir $dir</span><span style="background-color:#1e0010;box-sizing:border-box;color:#960050;margin:0;padding:0">
</span><span style="box-sizing:border-box;color:#b3d733;margin:0;padding:0"> +login anonymous</span><span style="background-color:#1e0010;box-sizing:border-box;color:#960050;margin:0;padding:0">
</span><span style="box-sizing:border-box;color:#b3d733;margin:0;padding:0"> +app_update $app validate</span><span style="background-color:#1e0010;box-sizing:border-box;color:#960050;margin:0;padding:0">
</span><span style="box-sizing:border-box;color:#b3d733;margin:0;padding:0"> )</span><span style="background-color:#1e0010;box-sizing:border-box;color:#960050;margin:0;padding:0">

</span><span style="box-sizing:border-box;color:#b3d733;margin:0;padding:0"> if [[$beta]]; then</span><span style="background-color:#1e0010;box-sizing:border-box;color:#960050;margin:0;padding:0">
</span><span style="box-sizing:border-box;color:#b3d733;margin:0;padding:0"> cmds+=(-beta $beta)</span><span style="background-color:#1e0010;box-sizing:border-box;color:#960050;margin:0;padding:0">
</span><span style="box-sizing:border-box;color:#b3d733;margin:0;padding:0"> if [[$betapass]]; then</span><span style="background-color:#1e0010;box-sizing:border-box;color:#960050;margin:0;padding:0">
</span><span style="box-sizing:border-box;color:#b3d733;margin:0;padding:0"> cmds+=(-betapassword $betapass)</span><span style="background-color:#1e0010;box-sizing:border-box;color:#960050;margin:0;padding:0">
</span><span style="box-sizing:border-box;color:#b3d733;margin:0;padding:0"> fi</span><span style="background-color:#1e0010;box-sizing:border-box;color:#960050;margin:0;padding:0">
</span><span style="box-sizing:border-box;color:#b3d733;margin:0;padding:0"> fi</span><span style="background-color:#1e0010;box-sizing:border-box;color:#960050;margin:0;padding:0">

</span><span style="box-sizing:border-box;color:#b3d733;margin:0;padding:0"> cmds+=(+quit)</span><span style="background-color:#1e0010;box-sizing:border-box;color:#960050;margin:0;padding:0">

</span><span style="box-sizing:border-box;color:#b3d733;margin:0;padding:0"> steamcmd $cmds</span><span style="background-color:#1e0010;box-sizing:border-box;color:#960050;margin:0;padding:0">

</span><span style="box-sizing:border-box;color:#b3d733;margin:0;padding:0"> for f in $dir/*; do</span><span style="background-color:#1e0010;box-sizing:border-box;color:#960050;margin:0;padding:0">
</span><span style="box-sizing:border-box;color:#b3d733;margin:0;padding:0"> if ! [[-f $f &amp;&amp; -x $f]]; then</span><span style="background-color:#1e0010;box-sizing:border-box;color:#960050;margin:0;padding:0">
</span><span style="box-sizing:border-box;color:#b3d733;margin:0;padding:0"> continue</span><span style="background-color:#1e0010;box-sizing:border-box;color:#960050;margin:0;padding:0">
</span><span style="box-sizing:border-box;color:#b3d733;margin:0;padding:0"> fi</span><span style="background-color:#1e0010;box-sizing:border-box;color:#960050;margin:0;padding:0">

</span><span style="box-sizing:border-box;color:#b3d733;margin:0;padding:0"> # Update the interpreter to the path on NixOS.</span><span style="background-color:#1e0010;box-sizing:border-box;color:#960050;margin:0;padding:0">
</span><span style="box-sizing:border-box;color:#b3d733;margin:0;padding:0"> patchelf --set-interpreter </span><span style="box-sizing:border-box;color:#b3d733;margin:0;padding:0">${</span><span style="box-sizing:border-box;color:#759ef0;margin:0;padding:0">pkgs</span><span style="box-sizing:border-box;color:#f5a3a3;font-weight:700;margin:0;padding:0">.</span><span style="box-sizing:border-box;color:#759ef0;margin:0;padding:0">glibc</span><span style="box-sizing:border-box;color:#b3d733;margin:0;padding:0">}</span><span style="box-sizing:border-box;color:#b3d733;margin:0;padding:0">/lib/ld-linux-x86-64.so.2 $f || true</span><span style="background-color:#1e0010;box-sizing:border-box;color:#960050;margin:0;padding:0">
</span><span style="box-sizing:border-box;color:#b3d733;margin:0;padding:0"> done</span><span style="background-color:#1e0010;box-sizing:border-box;color:#960050;margin:0;padding:0">
</span><span style="box-sizing:border-box;color:#b3d733;margin:0;padding:0"> ''</span><span style="box-sizing:border-box;color:#b3d733;margin:0;padding:0">}</span><span style="box-sizing:border-box;color:#b3d733;margin:0;padding:0"> %i"</span><span style="box-sizing:border-box;color:#999;margin:0;padding:0">;</span>
			<span style="box-sizing:border-box;color:#759ef0;margin:0;padding:0">PrivateTmp</span> <span style="box-sizing:border-box;color:#f5a3a3;font-weight:700;margin:0;padding:0">=</span> <span style="box-sizing:border-box;color:#8585e0;color:#ffb433;font-weight:700;margin:0;padding:0">true</span><span style="box-sizing:border-box;color:#999;margin:0;padding:0">;</span>
			<span style="box-sizing:border-box;color:#759ef0;margin:0;padding:0">Restart</span> <span style="box-sizing:border-box;color:#f5a3a3;font-weight:700;margin:0;padding:0">=</span> <span style="box-sizing:border-box;color:#b3d733;margin:0;padding:0">"on-failure"</span><span style="box-sizing:border-box;color:#999;margin:0;padding:0">;</span>
			<span style="box-sizing:border-box;color:#759ef0;margin:0;padding:0">StateDirectory</span> <span style="box-sizing:border-box;color:#f5a3a3;font-weight:700;margin:0;padding:0">=</span> <span style="box-sizing:border-box;color:#b3d733;margin:0;padding:0">"steam-app-%i"</span><span style="box-sizing:border-box;color:#999;margin:0;padding:0">;</span>
			<span style="box-sizing:border-box;color:#759ef0;margin:0;padding:0">TimeoutStartSec</span> <span style="box-sizing:border-box;color:#f5a3a3;font-weight:700;margin:0;padding:0">=</span> <span style="box-sizing:border-box;color:#ffb433;margin:0;padding:0">3600</span><span style="box-sizing:border-box;color:#999;margin:0;padding:0">;</span> <span style="box-sizing:border-box;color:#ccc;font-style:italic;margin:0;padding:0;white-space:pre-wrap"># Allow time for updates.</span>
			<span style="box-sizing:border-box;color:#759ef0;margin:0;padding:0">User</span> <span style="box-sizing:border-box;color:#f5a3a3;font-weight:700;margin:0;padding:0">=</span> <span style="box-sizing:border-box;color:#b3d733;margin:0;padding:0">"steam"</span><span style="box-sizing:border-box;color:#999;margin:0;padding:0">;</span>
			<span style="box-sizing:border-box;color:#759ef0;margin:0;padding:0">WorkingDirectory</span> <span style="box-sizing:border-box;color:#f5a3a3;font-weight:700;margin:0;padding:0">=</span> <span style="box-sizing:border-box;color:#b3d733;margin:0;padding:0">"~"</span><span style="box-sizing:border-box;color:#999;margin:0;padding:0">;</span>
		<span style="box-sizing:border-box;color:#999;margin:0;padding:0">};</span>
	<span style="box-sizing:border-box;color:#999;margin:0;padding:0">};</span>
<span style="box-sizing:border-box;color:#999;margin:0;padding:0">}</span>
</code></pre></div>
<h1 id="connecting" style="box-sizing:border-box;grid-column:2;margin:.4em 1rem .8em"><a href="https://kevincox.ca/2022/12/09/valheim-server-nixos-v2/#connecting" style="box-sizing:border-box;color:inherit!important;margin:0;text-decoration:inherit;text-decoration:underline;-webkit-text-decoration-color:gray;text-decoration-color:gray;text-shadow:inherit!important">Connecting</a></h1>
<ol style="box-sizing:border-box;grid-column:2;margin:0 1rem .8em">
<li style="box-sizing:border-box;margin:0">Start the game and get to the “Join Game” dialog.</li>
<li style="box-sizing:border-box;margin:0">Click “Add Server”</li>
<li style="box-sizing:border-box;margin:0">Enter the IP or hostname. (If you changed the port include it)</li>
<li style="box-sizing:border-box;margin:0">Click “Add Server”</li>
<li style="box-sizing:border-box;margin:0">Select the entry from the favourites list and click “Connect”.</li>
</ol></main>