Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nixos/archisteamfarm: init; ASF-ui: init; ArchiSteamFarm: 5.1.5.3 -> 5.2.0.10 & fix build on aarch-64 #148541

Merged
merged 8 commits into from
Jan 10, 2022
8 changes: 8 additions & 0 deletions nixos/doc/manual/from_md/release-notes/rl-2205.section.xml
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,14 @@
<link linkend="opt-services.tetrd.enable">services.tetrd</link>.
</para>
</listitem>
<listitem>
<para>
<link xlink:href="https://github.com/JustArchiNET/ArchiSteamFarm">ArchiSteamFarm</link>,
a C# application with primary purpose of idling Steam cards
from multiple accounts simultaneously. Available as
<link xlink:href="options.html#opt-services.archisteamfarm.enable">services.archisteamfarm</link>.
</para>
</listitem>
</itemizedlist>
</section>
<section xml:id="sec-release-22.05-incompatibilities">
Expand Down
2 changes: 2 additions & 0 deletions nixos/doc/manual/release-notes/rl-2205.section.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ In addition to numerous new and upgraded packages, this release has the followin

- [tetrd](https://tetrd.app), share your internet connection from your device to your PC and vice versa through a USB cable. Available at [services.tetrd](#opt-services.tetrd.enable).

- [ArchiSteamFarm](https://github.com/JustArchiNET/ArchiSteamFarm), a C# application with primary purpose of idling Steam cards from multiple accounts simultaneously. Available as [services.archisteamfarm](options.html#opt-services.archisteamfarm.enable).

## Backward Incompatibilities {#sec-release-22.05-incompatibilities}

- `pkgs.ghc` now refers to `pkgs.targetPackages.haskellPackages.ghc`.
Expand Down
1 change: 1 addition & 0 deletions nixos/modules/module-list.nix
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,7 @@
./services/editors/emacs.nix
./services/editors/infinoted.nix
./services/finance/odoo.nix
./services/games/asf.nix
./services/games/crossfire-server.nix
./services/games/deliantra-server.nix
./services/games/factorio.nix
Expand Down
236 changes: 236 additions & 0 deletions nixos/modules/services/games/asf.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,236 @@
{ config, lib, pkgs, ... }:

with lib;

let
cfg = config.services.archisteamfarm;

format = pkgs.formats.json { };

asf-config = format.generate "ASF.json" (cfg.settings // {
# we disable it because ASF cannot update itself anyways
# and nixos takes care of restarting the service
# is in theory not needed as this is already the default for default builds
UpdateChannel = 0;
Headless = true;
});

ipc-config = format.generate "IPC.config" cfg.ipcSettings;

mkBot = n: c:
format.generate "${n}.json" (c.settings // {
SteamLogin = if c.username == "" then n else c.username;
SteamPassword = c.passwordFile;
# sets the password format to file (https://github.com/JustArchiNET/ArchiSteamFarm/wiki/Security#file)
legendofmiracles marked this conversation as resolved.
Show resolved Hide resolved
PasswordFormat = 4;
Enabled = c.enabled;
});
in
{
options.services.archisteamfarm = {
enable = mkOption {
type = types.bool;
description = ''
If enabled, starts the ArchisSteamFarm service.
For configuring the SteamGuard token you will need to use the web-ui, which is enabled by default over on 127.0.0.1:1242.
You cannot configure ASF in any way outside of nix, since all the config files get wiped on restart and replaced with the programatically set ones by nix.
'';
default = false;
};

web-ui = mkOption {
type = types.submodule {
options = {
enable = mkEnableOption
"Wheter to start the web-ui. This is the preferred way of configuring things such as the steam guard token";

package = mkOption {
type = types.package;
default = pkgs.ArchiSteamFarm.ui;
description =
"Web-UI package to use. Contents must be in lib/dist.";
};
};
};
default = {
enable = true;
package = pkgs.ArchiSteamFarm.ui;
legendofmiracles marked this conversation as resolved.
Show resolved Hide resolved
};
example = {
enable = false;
};
description = "The Web-UI hosted on 127.0.0.1:1242.";
};

package = mkOption {
type = types.package;
default = pkgs.ArchiSteamFarm;
description =
"Package to use. Should always be the latest version, for security reasons, since this module uses very new features and to not get out of sync with the Steam API.";
};

dataDir = mkOption {
type = types.path;
default = "/var/lib/asf";
description = ''
The ASF home directory used to store all data.
If left as the default value this directory will automatically be created before the ASF server starts, otherwise the sysadmin is responsible for ensuring the directory exists with appropriate ownership and permissions.'';
};

settings = mkOption {
type = format.type;
description = ''
The ASF.json file, all the options are documented <link xlink:href="https://github.com/JustArchiNET/ArchiSteamFarm/wiki/Configuration#global-config">here</link>.
Do note that `AutoRestart` and `UpdateChannel` is always to `false`
respectively `0` because NixOS takes care of updating everything.
`Headless` is also always set to `true` because there is no way to provide inputs via a systemd service.
You should try to keep ASF up to date since upstream does not provide support for anything but the latest version and you're exposing yourself to all kinds of issues - as is outlined <link xlink:href="https://github.com/JustArchiNET/ArchiSteamFarm/wiki/Configuration#updateperiod">here</link>.
'';
example = {
Statistics = false;
};
default = { };
};

ipcSettings = mkOption {
type = format.type;
description = ''
Settings to write to IPC.config.
All options can be found <link xlink:href="https://github.com/JustArchiNET/ArchiSteamFarm/wiki/IPC#custom-configuration">here</link>.
'';
example = {
Kestrel = {
Endpoints = {
HTTP = {
Url = "http://*:1242";
};
};
};
};
default = { };
};

bots = mkOption {
type = types.attrsOf (types.submodule {
options = {
username = mkOption {
type = types.str;
description =
"Name of the user to log in. Default is attribute name.";
default = "";
};
passwordFile = mkOption {
type = types.path;
description =
"Path to a file containig the password. The file must be readable by the <literal>asf</literal> user/group.";
};
enabled = mkOption {
type = types.bool;
default = true;
description = "Whether to enable the bot on startup.";
};
settings = mkOption {
type = types.attrs;
description =
"Additional settings that are documented <link xlink:href=\"https://github.com/JustArchiNET/ArchiSteamFarm/wiki/Configuration#bot-config\">here</link>.";
default = { };
};
};
});
description = ''
Bots name and configuration.
'';
example = {
exampleBot = {
username = "alice";
passwordFile = "/var/lib/asf/secrets/password";
settings = { SteamParentalCode = "1234"; };
};
};
default = { };
};
};

config = mkIf cfg.enable {

users = {
users.asf = {
home = cfg.dataDir;
isSystemUser = true;
group = "asf";
description = "Archis-Steam-Farm service user";
};
groups.asf = { };
};

systemd.services = {
asf = {
aanderse marked this conversation as resolved.
Show resolved Hide resolved
description = "Archis-Steam-Farm Service";
after = [ "network.target" ];
legendofmiracles marked this conversation as resolved.
Show resolved Hide resolved
wantedBy = [ "multi-user.target" ];

serviceConfig = mkMerge [
(mkIf (cfg.dataDir == "/var/lib/asf") { StateDirectory = "asf"; })
{
User = "asf";
Group = "asf";
WorkingDirectory = cfg.dataDir;
Type = "simple";
ExecStart =
"${cfg.package}/bin/ArchiSteamFarm --path ${cfg.dataDir} --process-required --no-restart --service --no-config-migrate";

# mostly copied from the default systemd service
PrivateTmp = true;
LockPersonality = true;
PrivateDevices = true;
PrivateIPC = true;
PrivateMounts = true;
PrivateUsers = true;
ProtectClock = true;
ProtectControlGroups = true;
ProtectHostname = true;
ProtectKernelLogs = true;
ProtectKernelModules = true;
ProtectKernelTunables = true;
ProtectProc = "invisible";
ProtectSystem = "full";
RemoveIPC = true;
RestrictAddressFamilies = "AF_INET AF_INET6";
RestrictNamespaces = true;
RestrictRealtime = true;
RestrictSUIDSGID = true;
}
];

preStart = ''
mkdir -p config
rm -f www
rm -f config/{*.json,*.config}

ln -s ${asf-config} config/ASF.json

${strings.optionalString (cfg.ipcSettings != {}) ''
ln -s ${ipc-config} config/IPC.config
''}

ln -s ${pkgs.runCommandLocal "ASF-bots" {} ''
mkdir -p $out/lib/asf/bots
for i in ${strings.concatStringsSep " " (lists.map (x: "${getName x},${x}") (attrsets.mapAttrsToList mkBot cfg.bots))}; do IFS=",";
set -- $i
ln -s $2 $out/lib/asf/bots/$1
done
''}/lib/asf/bots/* config/

${strings.optionalString cfg.web-ui.enable ''
ln -s ${cfg.web-ui.package}/lib/dist www
''}
'';
};
};
};

meta = {
buildDocsInSandbox = false;
maintainers = with maintainers; [ lom ];
};
}
27 changes: 15 additions & 12 deletions pkgs/applications/misc/ArchiSteamFarm/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,48 +5,51 @@
, libkrb5
, zlib
, openssl
, callPackage
, stdenvNoCC
}:

buildDotnetModule rec {
pname = "archisteamfarm";
version = "5.1.5.3";
version = "5.2.1.5";

src = fetchFromGitHub {
owner = "justarchinet";
repo = pname;
rev = version;
sha256 = "sha256-H038maKHZujmbKhbi8fxsKR/tcSPrcl9L5xnr77yyXg=";
sha256 = "sha256-fjRf+9m1VGRq2ylqp5CP+FCPepUPyHjknSmJaei2yyE=";
};

dotnet-runtime = dotnetCorePackages.aspnetcore_5_0;
nugetDeps = ./deps.nix;
dotnet-runtime = dotnetCorePackages.aspnetcore_6_0;
dotnet-sdk = dotnetCorePackages.sdk_6_0;

nugetDeps = if stdenvNoCC.isAarch64 then ./deps-aarch64-linux.nix else ./deps-x86_64-linux.nix;

projectFile = "ArchiSteamFarm.sln";
executables = [ "ArchiSteamFarm" ];

runtimeDeps = [ libkrb5 zlib openssl ];

# Without this, it attempts to write to the store even though the `--path` flag is supplied.
patches = [ ./mutable-customdir.patch ];

doCheck = true;

preInstall = ''
# A mutable path, with this directory tree must be set. By default, this would point at the nix store causing errors.
makeWrapperArgs+=(
--add-flags "--path ~/.config/archisteamfarm"
--run "mkdir -p ~/.config/archisteamfarm/{config,logs,plugins}"
--run "cd ~/.config/archisteamfarm"
--run 'mkdir -p ~/.config/archisteamfarm/{config,logs,plugins}'
--set "ASF_PATH" "~/.config/archisteamfarm"
)
'';

passthru.updateScript = ./updater.sh;
passthru = {
updateScript = ./updater.sh;
ui = callPackage ./web-ui { };
};

meta = with lib; {
description = "Application with primary purpose of idling Steam cards from multiple accounts simultaneously";
homepage = "https://github.com/JustArchiNET/ArchiSteamFarm";
license = licenses.asl20;
platforms = dotnetCorePackages.aspnetcore_5_0.meta.platforms;
platforms = [ "x86_64-linux" "aarch64-linux" ];
maintainers = with maintainers; [ SuperSandro2000 lom ];
};
}
Loading