-
Notifications
You must be signed in to change notification settings - Fork 0
/
steamcmd.nix
109 lines (95 loc) · 2.74 KB
/
steamcmd.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/*
* Taken and modified from https://kevincox.ca/2022/12/09/valheim-server-nixos-v2/
*/
{ config, pkgs, lib, ... }:
{
users.users.steamcmd = {
isSystemUser = true;
group = config.users.groups.steamcmd.name;
home = "/var/lib/steamcmd";
homeMode = "777";
createHome = true;
};
users.groups.steamcmd = {};
systemd.services."steamcmd@" = {
after = [ "network-online.target" ];
wants = [ "network-online.target" ];
unitConfig = {
StopWhenUnneeded = true;
};
serviceConfig = {
Type = "oneshot";
ExecStart = "${pkgs.resholve.writeScript "steam" {
interpreter = "${pkgs.zsh}/bin/zsh";
inputs = with pkgs; [
patchelf
steamcmd
coreutils
];
execer = [
"cannot:${pkgs.steamcmd}/bin/steamcmd"
];
} ''
set -eux
instance=''${1:?Instance Missing}
eval 'args=(''${(@s:_:)instance})'
app=''${args[1]:?App ID missing}
beta=''${args[2]:-}
betapass=''${args[3]:-}
dir=/var/lib/steamcmd/apps/$instance
cmds=(
+force_install_dir $dir
+login anonymous
+app_update $app validate
)
if [[ $beta ]]; then
cmds+=(-beta $beta)
if [[ $betapass ]]; then
cmds+=(-betapassword $betapass)
fi
fi
cmds+=(+quit)
steamcmd $cmds
for f in $dir/*; do
chmod -R ugo+rwx $f
if ! [[ -f $f && -x $f ]]; then
continue
fi
# Update the interpreter to the path on NixOS.
patchelf --set-interpreter ${pkgs.glibc}/lib/ld-linux-x86-64.so.2 $f || true
done
''} %i";
PrivateTmp = true;
Restart = "on-failure";
StateDirectory = "steamcmd/apps/%i";
TimeoutStartSec = 3600; # Allow time for updates.
User = config.users.users.steamcmd.name;
WorkingDirectory = "~";
};
};
# Some games might depend on the Steamworks SDK redistributable, so download it.
systemd.services.steamworks-sdk = {
wantedBy = [ "multi-user.target" ];
wants = [ "[email protected]" "steamworks-sdk.timer" ];
after = [ "[email protected]" ];
serviceConfig = {
Type="oneshot";
ExecStart = lib.escapeShellArgs [
"${pkgs.coreutils}/bin/echo"
"Done! Steamworks SDK should be downloaded now."
];
Restart = "no";
User = config.users.users.steamcmd.name;
WorkingDirectory = "~";
};
};
systemd.timers.steamworks-sdk = {
description = "Updates Steamworks SDK daily.";
wantedBy = [ "timers.target" ];
timerConfig = {
Unit = "steamworks-sdk.service";
OnCalendar = "*-*-* 04:00:00";
Persistent = true;
};
};
}