added minecraft server. Backup solution is a bit ugly ATM.
This commit is contained in:
		
							parent
							
								
									39bee826c3
								
							
						
					
					
						commit
						a022854265
					
				
					 7 changed files with 89 additions and 5 deletions
				
			
		| 
						 | 
				
			
			@ -5,6 +5,9 @@
 | 
			
		|||
  lib,
 | 
			
		||||
  ...
 | 
			
		||||
}: {
 | 
			
		||||
  virtualisation.docker.enable = true;
 | 
			
		||||
  virtualisation.docker = {
 | 
			
		||||
    enable = true;
 | 
			
		||||
    autoPrune.enable = true;
 | 
			
		||||
  };
 | 
			
		||||
  users.users.${config.host.user}.extraGroups = ["docker"];
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -13,7 +13,6 @@
 | 
			
		|||
      hostname = "factorio";
 | 
			
		||||
      ports = [
 | 
			
		||||
        "34197:34197/udp"
 | 
			
		||||
        "27015:27015/tcp"
 | 
			
		||||
      ];
 | 
			
		||||
      environment = {UPDATE_MODS_ON_START = "true";};
 | 
			
		||||
    };
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										46
									
								
								configs/nixos/minecraft-docker.nix
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										46
									
								
								configs/nixos/minecraft-docker.nix
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,46 @@
 | 
			
		|||
{
 | 
			
		||||
  inputs,
 | 
			
		||||
  config,
 | 
			
		||||
  pkgs,
 | 
			
		||||
  lib,
 | 
			
		||||
  ...
 | 
			
		||||
}: {
 | 
			
		||||
  virtualisation.oci-containers = {
 | 
			
		||||
    backend = "docker";
 | 
			
		||||
    containers.minecraft = {
 | 
			
		||||
      image = "itzg/minecraft-server";
 | 
			
		||||
      volumes = ["/storage/minecraft:/data"];
 | 
			
		||||
      hostname = "minecraft";
 | 
			
		||||
      ports = [
 | 
			
		||||
        "25565:25565"
 | 
			
		||||
      ];
 | 
			
		||||
      environment = {
 | 
			
		||||
        EULA = "TRUE";
 | 
			
		||||
        TYPE="FORGE";
 | 
			
		||||
        VERSION = "1.20.1";
 | 
			
		||||
        PACKWIZ_URL = "https://static.venberg.xyz/minecraft/less-than-compact-2/pack.toml";
 | 
			
		||||
        MEMORY = "16G";
 | 
			
		||||
        USE_AIKAR_FLAGS = "true";
 | 
			
		||||
        UID = "1000";
 | 
			
		||||
        GID = "100";
 | 
			
		||||
        STOP_SERVER_ANNOUNCE_DELAY = "300";
 | 
			
		||||
        ENABLE_ROLLING_LOGS = "true";
 | 
			
		||||
        GUI = "FALSE";
 | 
			
		||||
        # SETUP_ONLY = "true";
 | 
			
		||||
        MOTD = "Welcome!";
 | 
			
		||||
        DIFFICULTY = "normal";
 | 
			
		||||
        OPS = ''
 | 
			
		||||
          TheToric
 | 
			
		||||
        '';
 | 
			
		||||
        ENFORCE_WHITELIST = "true";
 | 
			
		||||
        ENABLE_WHITELIST = "true";
 | 
			
		||||
        ANNOUNCE_PLAYER_ACHIEVEMENTS = "true";
 | 
			
		||||
        ALLOW_FLIGHT = "TRUE";
 | 
			
		||||
      };
 | 
			
		||||
      extraOptions = ["--stop-timeout=600"];
 | 
			
		||||
    };
 | 
			
		||||
  };
 | 
			
		||||
  imports = [
 | 
			
		||||
    ./docker.nix
 | 
			
		||||
  ];
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -25,7 +25,7 @@ in {
 | 
			
		|||
      ];
 | 
			
		||||
    };
 | 
			
		||||
  };
 | 
			
		||||
  services.nginx.virtualHosts."static.venberg.xyz" = {
 | 
			
		||||
  services.nginx.virtualHosts."directory.venberg.xyz" = {
 | 
			
		||||
    enableACME = true;
 | 
			
		||||
    forceSSL = true;
 | 
			
		||||
    locations."/" = {
 | 
			
		||||
							
								
								
									
										13
									
								
								configs/nixos/nginx-static.nix
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								configs/nixos/nginx-static.nix
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,13 @@
 | 
			
		|||
{
 | 
			
		||||
  inputs,
 | 
			
		||||
  config,
 | 
			
		||||
  pkgs,
 | 
			
		||||
  lib,
 | 
			
		||||
  ...
 | 
			
		||||
}: {
 | 
			
		||||
  services.nginx.virtualHosts."static.venberg.xyz" = {
 | 
			
		||||
    enableACME = true;
 | 
			
		||||
    forceSSL = true;
 | 
			
		||||
    root = "/storage/static";
 | 
			
		||||
  };
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -24,7 +24,9 @@ inputs.nixpkgs.lib.nixosSystem {
 | 
			
		|||
    ../../configs/nixos/grocy.nix
 | 
			
		||||
    ../../configs/nixos/factorio-docker.nix
 | 
			
		||||
    ../../configs/nixos/cyberchef.nix
 | 
			
		||||
    ../../configs/nixos/miniserve-static.nix
 | 
			
		||||
    ../../configs/nixos/miniserve-directory.nix
 | 
			
		||||
    ../../configs/nixos/minecraft-docker.nix
 | 
			
		||||
    ../../configs/nixos/nginx-static.nix
 | 
			
		||||
    ({
 | 
			
		||||
      config,
 | 
			
		||||
      pkgs,
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -6,6 +6,24 @@
 | 
			
		|||
  ...
 | 
			
		||||
}: let
 | 
			
		||||
  port = "8090";
 | 
			
		||||
  # TODO: I should really make restic a custom module at this point, with an enable option, a option for being the host,
 | 
			
		||||
  # and the ability to add paths and pre/post commands from multiple places.
 | 
			
		||||
  preBackup=pkgs.writeShellScriptBin "mc-docker-pre-backup" ''
 | 
			
		||||
        set -euxo pipefail
 | 
			
		||||
 | 
			
		||||
        docker exec minecraft rcon-cli "say server backing up, expect minor lag"
 | 
			
		||||
        sleep 10
 | 
			
		||||
        docker exec minecraft rcon-cli "save-all flush"
 | 
			
		||||
        docker exec minecraft rcon-cli "save-off"
 | 
			
		||||
        sleep 10
 | 
			
		||||
      '';
 | 
			
		||||
postBackup=pkgs.writeShellScriptBin "mc-docker-post-backup" ''
 | 
			
		||||
        set -euxo pipefail
 | 
			
		||||
 | 
			
		||||
        docker exec minecraft rcon-cli "save-on"
 | 
			
		||||
        docker exec minecraft rcon-cli "say server backup succsessful!"
 | 
			
		||||
      '';
 | 
			
		||||
 | 
			
		||||
in {
 | 
			
		||||
  services.restic.server = lib.mkIf (inputs ? nix-secrets) {
 | 
			
		||||
    enable = true;
 | 
			
		||||
| 
						 | 
				
			
			@ -46,9 +64,12 @@ in {
 | 
			
		|||
      repositoryFile = "/backup/restic/";
 | 
			
		||||
      passwordFile = config.sops.secrets.restic-password.path;
 | 
			
		||||
      initialize = true;
 | 
			
		||||
      backupPrepareCommand = "${preBackup}/bin/mc-docker-pre-backup";
 | 
			
		||||
      backupCleanupCommand = "${postBackup}/bin/mc-docker-post-backup";
 | 
			
		||||
      paths = [
 | 
			
		||||
        "/storage/syncthing"
 | 
			
		||||
        "/storage/factorio"
 | 
			
		||||
        "/storage/minecraft"
 | 
			
		||||
      ];
 | 
			
		||||
      pruneOpts = [
 | 
			
		||||
        "--keep-within 14d"
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue