diff --git a/machines/nixos/x86_64-linux/jeeves/configuration.nix b/machines/nixos/x86_64-linux/jeeves/configuration.nix index 759a277..4e83fe7 100644 --- a/machines/nixos/x86_64-linux/jeeves/configuration.nix +++ b/machines/nixos/x86_64-linux/jeeves/configuration.nix @@ -8,6 +8,7 @@ ./network.nix ./wireguard.nix ./jellyfin.nix + ./mindustry.nix ]; nixpkgs = { diff --git a/machines/nixos/x86_64-linux/jeeves/mindustry.nix b/machines/nixos/x86_64-linux/jeeves/mindustry.nix new file mode 100644 index 0000000..575aa13 --- /dev/null +++ b/machines/nixos/x86_64-linux/jeeves/mindustry.nix @@ -0,0 +1,6 @@ +{ lib, pkgs, config, ... }: +{ + reo101.mindustry = { + enable = true; + }; +} diff --git a/modules/nixos/mindustry/default.nix b/modules/nixos/mindustry/default.nix new file mode 100644 index 0000000..8d565c6 --- /dev/null +++ b/modules/nixos/mindustry/default.nix @@ -0,0 +1,124 @@ +{ lib, pkgs, config, ... }: + +with lib; +let + cfg = config.reo101.mindustry; +in +{ + imports = [ + ]; + + options = { + reo101.mindustry = { + enable = mkEnableOption "reo101 Mindustry config"; + version = mkOption { + type = types.str; + default = "146"; + description = '' + Game version to run + ''; + }; + # jarUrl = mkOption { + # type = types.str; + # default = "https://github.com/Anuken/Mindustry/releases/download/v${cfg.version}/Mindustry.jar"; + # description = '' + # URL of the game server jar + # ''; + # }; + # jarSha256 = mkOption { + # type = types.str; + # default = "sha256-OrDkbDy9yGNSm6BegEhH7wDj29tFZ7XCfF5tzgcbk/k="; + # description = '' + # sha256 of the game server jar + # ''; + # }; + # java = mkOption { + # type = types.package; + # default = pkgs.zulu17; + # defaultText = "pkgs.zulu17"; + # description = '' + # Java package used to run the game server jar + # ''; + # }; + mindustry-server = mkOption { + type = types.package; + default = pkgs.mindustry-server; + defaultText = "pkgs.mindustry-server"; + description = '' + Package providing the `/bin/mindustry-server` binary + ''; + }; + port = mkOption { + type = types.port; + default = 6567; + description ='' + Port to run the game server on + ''; + }; + openFirewall = mkOption { + type = types.bool; + default = false; + description = '' + Whether to open the game port to the firewall + ''; + }; + }; + }; + + config = mkIf cfg.enable ( let + # mindustryJar = builtins.fetchurl { + # url = cfg.jarUrl; + # sha256 = cfg.jarSha256; + # }; + # mindustryCmd = "${cfg.java}/bin/java -jar ${mindustryJar}"; + mindustryConfig = lib.concatStringsSep "," [ + ("startCommands " + lib.concatStringsSep "," [ + "config port ${builtins.toString cfg.port}" + "config logging false" + ]) + ]; + mindustryCmd = "${cfg.mindustry-server}/bin/mindustry-server ${mindustryConfig}"; + in + { + # FIXME: set log path + + # systemd.services.mindustry = + # wantedBy = [ "multi-user.target" ]; + # after = [ "network.target" ]; + # description = "Start a Mindustry server instance"; + # serviceConfig = { + # User = "jeeves"; + # # ExecStart = ''${pkgs.screen}/bin/screen -dmS mindustry ${mindustryCmd}''; + # # ExecStop = ''${pkgs.screen}/bin/screen -S mindustry -X quit''; + # # Restart = "on-failure"; + # # RestartSec = "5s"; + # Type = "forking"; + # ExecStart = ''${mindustryCmd}''; + # }; + # }; + + environment.systemPackages = with pkgs; [ + mindustry-server + ]; + + networking.firewall = + lib.pipe + ["TCP" "UDP"] + [ + (builtins.map + (protocol: + lib.nameValuePair + "allowed${protocol}Ports" + [cfg.port])) + builtins.listToAttrs + ]; + + # networking.firewall.allowedTCPPorts = [cfg.port]; + # networking.firewall.allowedUDPPorts = [cfg.port]; + } + ); + + meta = { + maintainers = with lib.maintainers; [ reo101 ]; + }; +}