Skip to content
This repository was archived by the owner on Feb 2, 2025. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 41 additions & 1 deletion nixos-modules/valheim.nix
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,43 @@ in {
description = lib.mdDoc "Whether to open ports in the firewall.";
};

public = lib.mkOption {
type = lib.types.bool;
default = true;
description = lib.mdDoc ''
Toggles visibility on the Steam server & community lists.

When not set, defaults to true (visible).
Set to false to make the server private.
'';
};

logFile = lib.mkOption {
type = with lib.types; nullOr str;
default = null;
example = "/var/lib/valheim/log/valheim-server.log";
description = lib.mdDoc ''
The path where the server log file will be saved.

When set, this will redirect all logs from stdout to the specified path.
This means that the logs will not be captured by systemd's journal.
Leave this option unset to keep console logging enabled.

Make sure the valheim user has write access to the specified directory, otherwise
the valheim service fail to start and exit.
'';
};
Comment on lines +75 to +89
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think -logFile is there because upstream expects you to run it using their wrapper script, from the commandline, where the log output will just go to your terminal scrollback buffer. The NixOS module provided by this flake instead runs it using systemd. Telling the underlying program to log to a file instead of standard out/error somewhat goes against the purpose of running as a systemd service, so I would rather not expose that function.


preset = lib.mkOption {
type = with lib.types; nullOr str;
default = null;
example = "hardcore";
description = lib.mdDoc ''
The preset world modifier, valid options are
"easy", "hard", "hardcore", "casual", "hammer" and "immersive".
'';
};
Comment on lines +91 to +99
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regarding your comment about using an enum type, you would change the type from nullOr str to nullOr (enum ["easy" "hard" ...]) (replacing ... with the rest of the enum values), and then remove the list of values from the description.

Reference: NixOS Manual


password = lib.mkOption {
type = lib.types.str;
default = "";
Expand Down Expand Up @@ -277,8 +314,11 @@ in {
++ [
"-port \"${builtins.toString cfg.port}\""
"-password \"${cfg.password}\""
"-public ${if cfg.public then "1" else "0"}"
]
++ (lib.lists.optional cfg.crossplay "-crossplay"));
++ (lib.lists.optional cfg.crossplay "-crossplay")
++ (lib.lists.optional (cfg.logFile != null) "-logFile \"${cfg.logFile}\"")
++ (lib.lists.optional (cfg.preset != null) "-preset \"${cfg.preset}\""));
};
};
};
Expand Down