Add Factorio (vultr) server

main
Chandler Swift 2024-08-05 20:04:32 -05:00
parent 6e16dd7162
commit b74fc406d5
Signed by: chandlerswift
GPG Key ID: A851D929D52FB93F
6 changed files with 104 additions and 0 deletions

View File

@ -0,0 +1,8 @@
.PHONY: deploy
deploy:
nixos-rebuild switch --fast -I nixos-config=./configuration.nix --build-host root@factorio.chandlerswift.com --target-host root@factorio.chandlerswift.com
.PHONY: create-server
create-server:
../create-server.py factorio.chandlerswift.com

View File

@ -0,0 +1 @@
# factorio.chandlerswift.com

View File

@ -0,0 +1,61 @@
{ config, lib, pkgs, ... }: {
nixpkgs.config.allowUnfreePredicate = pkg: builtins.elem (lib.getName pkg) [
"factorio-headless"
];
imports = [
./hardware-configuration.nix
];
networking.hostName = "factorio";
time.timeZone = "America/Chicago";
i18n.defaultLocale = "en_US.UTF-8";
environment.systemPackages = with pkgs; [ rsync ];
services.openssh.enable = true;
users.users.root.openssh.authorizedKeys.keys = [''ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIEhPyyqS3BGYor3zLbjc8hZuhem3mS8TNmvWogXcnz/b chandler@chandlerswift.com'' ];
services.factorio = {
enable = true;
openFirewall = true;
nonBlockingSaving = true;
game-name = "Chandler's Factorio Server";
game-password = "nixosftw";
description = "Hi Jeff!";
mods =
let
inherit (pkgs) lib;
modDir = ./mods;
modList = lib.pipe modDir [
builtins.readDir
(lib.filterAttrs (k: v: v == "regular"))
(lib.mapAttrsToList (k: v: k))
(builtins.filter (lib.hasSuffix ".zip"))
];
modToDrv = modFileName:
pkgs.runCommand "copy-factorio-mods" {} ''
mkdir $out
cp ${modDir + "/${modFileName}"} $out/${modFileName}
''
// { deps = []; };
in
builtins.map modToDrv modList;
};
# networking.firewall.allowedTCPPorts = [
# 80 # Caddy
# 443 # Caddy
# ];
# networking.firewall.allowedUDPPorts = [ ... ];
# 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.
system.stateVersion = "24.05";
}

View File

@ -0,0 +1,19 @@
{ modulesPath, ... }:
{
imports = [ (modulesPath + "/profiles/qemu-guest.nix") ];
boot.loader.grub = {
efiSupport = true;
efiInstallAsRemovable = true;
device = "nodev";
};
fileSystems."/boot" = { device = "/dev/disk/by-uuid/FDD2-F69B"; fsType = "vfat"; };
boot.initrd.availableKernelModules = [ "ata_piix" "uhci_hcd" "xen_blkfront" "vmw_pvscsi" ];
boot.initrd.kernelModules = [ "nvme" ];
fileSystems."/" = { device = "/dev/vda2"; fsType = "ext4"; };
swapDevices = [{
device = "/swapfile";
size = 4 * 1024; # 4GB
}];
boot.tmp.cleanOnBoot = true;
zramSwap.enable = true;
}

View File

@ -0,0 +1,13 @@
#!/usr/bin/env nix-shell
#! nix-shell -i bash -p bash curl jq
mods="Krastorio2 Krastorio2Assets flib Big_Brother AtomicArtillery AutoDeconstruct nixie-tubes"
download_dir=./mods
username=$(cat ../keys.toml | grep factorio-username | cut -d'"' -f2)
token=$(cat ../keys.toml | grep factorio-token | cut -d'"' -f2)
for mod in $mods; do
mod_data=$(curl -s https://mods.factorio.com/api/mods/$mod)
download_url=$(<<<$mod_data jq -r ".releases[-1].download_url")
file_name=$(<<<$mod_data jq -r ".releases[-1].file_name")
sha1=$(<<<$mod_data jq -r ".releases[-1].sha1") # TODO
[ -f $download_dir/$file_name ] || curl --location --no-clobber --output $download_dir/$file_name "https://mods.factorio.com/$download_url?username=$username&token=$token"
done

2
factorio/mods/.gitignore vendored 100644
View File

@ -0,0 +1,2 @@
*
!.gitignore