diff --git a/flake.nix b/flake.nix index 0fd430f..e1e8690 100644 --- a/flake.nix +++ b/flake.nix @@ -21,6 +21,14 @@ ]; }; + nixserver = lib.nixosSystem { + system = "x86_64-linux"; + specialArgs = inputs; + modules = [ + ./hosts/nixserver/configuration.nix + ]; + }; + }; }; } diff --git a/hosts/nixserver/configuration.nix b/hosts/nixserver/configuration.nix new file mode 100755 index 0000000..87c6a8e --- /dev/null +++ b/hosts/nixserver/configuration.nix @@ -0,0 +1,120 @@ +# Edit this configuration file to define what should be installed on +# your system. Help is available in the configuration.nix(5) man page, on +# https://search.nixos.org/options and in the NixOS manual (`nixos-help`). + +{ config, lib, pkgs, ... }: + +let common_dir = ../../common; +in { + imports = + [ # Include the results of the hardware scan. + ./hardware-configuration.nix + + (common_dir + /options.nix) + + (common_dir + /bootloader/grub.nix) + (common_dir + /users/users.nix) + + ./minecraft.nix + ./frp.nix + ]; + + nix.settings.experimental-features = [ "nix-command" "flakes" ]; + + + # Use the GRUB 2 boot loader with legacy boot + grub.device = "/dev/disk/by-uuid/dfdccedd-4336-4449-bdc9-5cc4533cfbdd"; + + + # USB WiFi driver kernel module + boot.extraModulePackages = [ config.boot.kernelPackages.rtl8821au ]; + boot.kernelModules = ["8821au"]; + + + networking.hostName = "nixserver"; + networking.networkmanager.enable = true; + + + # Set your time zone. + time.timeZone = "America/Denver"; + + # Select internationalisation properties. + # i18n.defaultLocale = "en_US.UTF-8"; + # console = { + # font = "Lat2-Terminus16"; + # keyMap = "us"; + # useXkbConfig = true; # use xkb.options in tty. + # }; + + # Enable sound. + # sound.enable = true; + # hardware.pulseaudio.enable = true; + + # Define a user account. Don't forget to set a password with ‘passwd’. + user.cameron.enable = true; + + programs = { + zsh.enable = true; + neovim = { + defaultEditor = true; + viAlias = true; + vimAlias = true; + }; + }; + + # List packages installed in system profile. To search, run: + # $ nix search wget + environment.systemPackages = with pkgs; [ + git + curl + wget + ranger + lf + tmux + ]; + + environment.shells = with pkgs; [ bash zsh ]; + + # List services that you want to enable: + + # Enable the OpenSSH daemon. + services.openssh = { + enable = true; + + settings = { + PasswordAuthentication = false; + PermitRootLogin = "no"; + }; + }; + + # Open ports in the firewall. + # networking.firewall.allowedTCPPorts = [ ... ]; + # networking.firewall.allowedUDPPorts = [ ... ]; + # Or disable the firewall altogether. + # networking.firewall.enable = false; + + # Copy the NixOS configuration file and link it from the resulting system + # (/run/current-system/configuration.nix). This is useful in case you + # accidentally delete configuration.nix. + system.copySystemConfiguration = true; + + # This option defines the first version of NixOS you have installed on this particular machine, + # and is used to maintain compatibility with application data (e.g. databases) created on older NixOS versions. + # + # Most users should NEVER change this value after the initial install, for any reason, + # even if you've upgraded your system to a new NixOS release. + # + # This value does NOT affect the Nixpkgs version your packages and OS are pulled from, + # so changing it will NOT upgrade your system. + # + # This value being lower than the current NixOS release does NOT mean your system is + # out of date, out of support, or vulnerable. + # + # Do NOT change this value unless you have manually inspected all the changes it would make to your configuration, + # and migrated your data accordingly. + # + # For more information, see `man configuration.nix` or https://nixos.org/manual/nixos/stable/options#opt-system.stateVersion . + system.stateVersion = "23.11"; # Did you read the comment? + +} + diff --git a/hosts/nixserver/custom-packages/forge-installer/default.nix b/hosts/nixserver/custom-packages/forge-installer/default.nix new file mode 100755 index 0000000..2fda3fc --- /dev/null +++ b/hosts/nixserver/custom-packages/forge-installer/default.nix @@ -0,0 +1,60 @@ +{ + lib, + stdenvNoCC, + fetchurl, + jre, + makeBinaryWrapper, +}: + +stdenvNoCC.mkDerivation (finalAttrs: { + pname = "forge-installer"; + version = "1.18.2-40.2.9"; + + src = + fetchurl { + url = "https://maven.minecraftforge.net/net/minecraftforge/forge/${finalAttrs.version}/forge-${finalAttrs.version}-installer.jar"; + hash = "sha256-N/GpCeXZUH3//IIhUgCTCoI+nCcttlQghIXO7sk3rFk="; + }; + + installPhase = '' + runHook preInstall + + install -D $src $out/bin/installer.jar + + echo "#!/usr/bin/env bash + +if [[ ! -d libraries ]]; then + ${lib.getExe jre} -jar $out/bin/installer.jar --installServer + sed -e \"s|libraries|\$(pwd)/libraries|g\" libraries/net/minecraftforge/forge/${finalAttrs.version}/unix_args.txt > forge_args.txt + rm run.sh run.bat user_jvm_args.txt installer.jar.log +fi + +exec $out/bin/run \$@" > $out/bin/minecraft-server + chmod +x $out/bin/minecraft-server + + makeWrapper ${lib.getExe jre} "$out/bin/run" \ + --append-flags "@forge_args.txt nogui" + + runHook postInstall + ''; + + nativeBuildInputs = [ + jre + makeBinaryWrapper + ]; + + buildInputs = [ + jre + ]; + + dontUnpack = true; + preferLocalBuild = true; + allowSubstitutes = false; + + meta = { + description = "Annoying Minecraft Server"; + homepage = "https://minecraftforge.net/"; + platforms = lib.platforms.unix; + mainProgram = "minecraft-server"; + }; +}) diff --git a/hosts/nixserver/frp.nix b/hosts/nixserver/frp.nix new file mode 100755 index 0000000..d9d6762 --- /dev/null +++ b/hosts/nixserver/frp.nix @@ -0,0 +1,24 @@ +{ services, ... }: + +{ + services.frp = { + enable = true; + role = "client"; + settings = { + common = { + server_addr = "45.79.110.117"; + server_port = 7486; + + authentication_method = "token"; + token = "6%i&MOc@!RPE6xGkRuABnp*3S"; + }; + + mc_vh = { + type = "tcp"; + local_ip = "127.0.0.1"; + local_port = 25565; + remote_port = 35000; + }; + }; + }; +} diff --git a/hosts/nixserver/hardware-configuration.nix b/hosts/nixserver/hardware-configuration.nix new file mode 100755 index 0000000..7f001d2 --- /dev/null +++ b/hosts/nixserver/hardware-configuration.nix @@ -0,0 +1,35 @@ +# Do not modify this file! It was generated by ‘nixos-generate-config’ +# and may be overwritten by future invocations. Please make changes +# to /etc/nixos/configuration.nix instead. +{ config, lib, pkgs, modulesPath, ... }: + +{ + imports = + [ (modulesPath + "/installer/scan/not-detected.nix") + ]; + + boot.initrd.availableKernelModules = [ "uhci_hcd" "ehci_pci" "ahci" "usb_storage" "usbhid" "sd_mod" "sr_mod" ]; + boot.initrd.kernelModules = [ ]; + boot.kernelModules = [ "kvm-intel" ]; + boot.extraModulePackages = [ ]; + + fileSystems."/" = + { device = "/dev/disk/by-uuid/dfdccedd-4336-4449-bdc9-5cc4533cfbdd"; + fsType = "ext4"; + }; + + swapDevices = + [ { device = "/dev/disk/by-uuid/2b82487e-40c5-40dd-b39d-e9d90e23424e"; } + ]; + + # Enables DHCP on each ethernet and wireless interface. In case of scripted networking + # (the default) this is the recommended approach. When using systemd-networkd it's + # still possible to use this option, but it's recommended to use it in conjunction + # with explicit per-interface declarations with `networking.interfaces..useDHCP`. + networking.useDHCP = lib.mkDefault true; + # networking.interfaces.enp0s29f7u6.useDHCP = lib.mkDefault true; + # networking.interfaces.enp6s0.useDHCP = lib.mkDefault true; + + nixpkgs.hostPlatform = lib.mkDefault "x86_64-linux"; + hardware.cpu.intel.updateMicrocode = lib.mkDefault config.hardware.enableRedistributableFirmware; +} diff --git a/hosts/nixserver/minecraft.nix b/hosts/nixserver/minecraft.nix new file mode 100755 index 0000000..feca7c5 --- /dev/null +++ b/hosts/nixserver/minecraft.nix @@ -0,0 +1,27 @@ +{ pkgs, services, ... }: + +let forge = pkgs.callPackage ./custom-packages/forge-installer/default.nix {}; + +in { + services.minecraft-server = { + enable = true; + eula = true; + + package = forge; + + jvmOpts = "-Xms8G -Xmx24G"; + declarative = true; + serverProperties = { + difficulty = "hard"; + gamemode = "survival"; + level-name = "vh"; + motd = "Let's vault!"; + view-distance = 12; + enable-rcon = true; + "rcon.password" = "d3u@@bdvVuVq9fgL#r10iFbJA"; + spawn-protection = 0; + }; + + openFirewall = true; + }; +}