Skip to content

Instantly share code, notes, and snippets.

@ibizaman
Created August 5, 2026 08:07
Show Gist options
  • Select an option

  • Save ibizaman/b294e6a7fe5cb8aeb2dec8d6c4cbb2e1 to your computer and use it in GitHub Desktop.

Select an option

Save ibizaman/b294e6a7fe5cb8aeb2dec8d6c4cbb2e1 to your computer and use it in GitHub Desktop.
Minecraft server with SHB
{ config, pkgs, ... }:
let
hostname = "myhost";
backupCfg =
{
enable ? true,
shbOpt ? null,
timerConfig ? {
OnBootSec = "15min";
OnUnitActiveSec = "1h";
RandomizedDelaySec = "7min";
},
s3TimerConfig ? {
OnCalendar = "*-*-* 03:00:00";
RandomizedDelaySec = "1h";
},
}:
name:
let
bck = (if shbOpt != null then shbOpt else config.shb.${name}).backup.request;
in
{
shb.restic.instances."${name}-local" = {
request = bck;
settings = {
enable = if enable then true else shbOpt.enable;
passphrase.result = config.shb.sops.secret."restic/passphrases/${name}".result;
repository = {
path = "/srv/backup/restic/${hostname}/${name}";
timerConfig = timerConfig // {
FixedRandomDelay = true;
};
};
retention = {
keep_within = "1d";
keep_hourly = 24;
keep_daily = 7;
keep_weekly = 4;
keep_monthly = 6;
};
limitUploadKiBs = 8000;
limitDownloadKiBs = 8000;
};
};
shb.restic.instances."${name}-s3" = {
request = bck;
settings = {
enable = if enable then true else shbOpt.enable;
passphrase.result = config.shb.sops.secret."restic/passphrases/${name}".result;
repository = {
path = "s3:s3.us-west-000.backblazeb2.com/${hostname}-backup/${name}";
timerConfig = s3TimerConfig // {
FixedRandomDelay = true;
};
secrets = {
AWS_ACCESS_KEY_ID.source = config.sops.secrets."backup/b2/access_key_id/${name}".path;
AWS_SECRET_ACCESS_KEY.source = config.sops.secrets."backup/b2/secret_access_key/${name}".path;
};
};
retention = {
keep_within = "1d";
keep_hourly = 24;
keep_daily = 7;
keep_weekly = 4;
keep_monthly = 6;
};
limitUploadKiBs = 3000;
limitDownloadKiBs = 3000;
};
};
shb.sops.secret."restic/passphrases/${name}" = {
request = config.shb.restic.instances."${name}-local".settings.passphrase.request;
};
shb.sops.secret."backup/b2/access_key_id/${name}" = {
request = config.shb.restic.instances."${name}-local".settings.passphrase.request;
settings.key = "backup/b2/access_key_id";
};
shb.sops.secret."backup/b2/secret_access_key/${name}" = {
request = config.shb.restic.instances."${name}-local".settings.passphrase.request;
settings.key = "backup/b2/secret_access_key";
};
shb.sops.secret."backup/skaraboxJean/access_key_id/${name}" = {
request = config.shb.restic.instances."${name}-local".settings.passphrase.request;
settings.key = "backup/skaraboxJean/access_key_id";
};
shb.sops.secret."backup/skaraboxJean/secret_access_key/${name}" = {
request = config.shb.restic.instances."${name}-local".settings.passphrase.request;
settings.key = "backup/skaraboxJean/secret_access_key";
};
};
in
{
lib.mkMerge = [
{
shb.zfs.pools.root.datasets."safe/minecraft" = {
path = config.services.minecraft-servers.dataDir;
owner = "minecraft";
group = "minecraft";
};
shb.sanoid.backup."root/safe/minecraft" = {
request = config.shb.zfs.pools.root.datasets."safe/minecraft".datasetBackup.request;
settings.useTemplate = [ "main" ];
};
services.minecraft-servers = {
enable = true;
eula = true;
openFirewall = true;
servers.main = {
enable = true;
package = pkgs.neoforgeServers.neoforge-1_21_1;
serverProperties = {
server-port = 43000;
difficulty = "hard";
gamemode = "survival";
max-players = 5;
motd = "My Minecraft server!";
enforce-secure-profile = false;
online-mode = false;
white-list = false;
allow-cheats = true;
};
jvmOpts = "-Xms4092M -Xmx4092M -XX:+UseG1GC -XX:ParallelGCThreads=2 -XX:MinHeapFreeRatio=5 -XX:MaxHeapFreeRatio=10";
symlinks = {
# nix shell github:Infinidoge/nix-minecraft#nix-modrinth-prefetch
# nix-modrinth-prefetch KSgki4uc
mods = pkgs.linkFarmFromDrvs "mods" (
builtins.attrValues {
# https://modrinth.com/mod/journeymap
JourneyMap = pkgs.fetchurl {
url = "https://cdn.modrinth.com/data/lfHFW1mp/versions/E44vwUJO/journeymap-neoforge-1.21.1-6.0.0-beta.66.jar";
sha512 = "a6e6fc436020c4d4d3625147c271b04535765e0ae9c59703aa66cd1d3c986e077ddafe2daf9c00b45fd9f4dfbf82ab0f1ca1ea730253ea9e0b4d954729b2c632";
# url = "https://cdn.modrinth.com/data/lfHFW1mp/versions/HSajmA5j/journeymap-neoforge-1.21.5-6.0.0-beta.52.jar";
# sha512 = "sha512-EBX4pZkqYNM2zIs2RRXR0W6bW5wrTlJIqGJ3ScXsI7msAylAdpfjHkgxjINVDspePTGoOnBrlq4gnDPpuLPZww==";
};
# https://modrinth.com/mod/sophisticated-backpacks
SophisticatedBackpacks = pkgs.fetchurl {
url = "https://cdn.modrinth.com/data/TyCTlI4b/versions/ZMuJ1TI7/sophisticatedbackpacks-1.21.1-3.25.44.1736.jar";
sha512 = "0704060b2d0e2e88bc771da1b26fe262563ac6a814f129a1207782d7edbac8bdc1b4057669c5bc94976e6eb74c6386c0735f93628b2d1f23e7eac4ae6562e185";
# url = "https://cdn.modrinth.com/data/TyCTlI4b/versions/TbHJGS23/sophisticatedbackpacks-1.21.5-3.25.45.1737.jar";
# sha512 = "sha512-y+zMncOEF2squyfjOZ4PdWWHSOK2Lx0vF20U1krkC0fPoxc5g2Fw+f5M/uPXURVvxBWxEsXTZb/OtBYsJ95z3w==";
};
# https://modrinth.com/mod/sophisticated-core
SophisticatedCore = pkgs.fetchurl {
url = "https://cdn.modrinth.com/data/nmoqTijg/versions/ErcuCe4o/sophisticatedcore-1.21.1-1.4.35.1823.jar";
sha512 = "c2c9c4e9e99a43292297f92b1f4dcfa1c9000d9aa684fed07153a4896ae9791d90f29cf0d8365c61d1915c5a6ee4c5cb881eee6c2385b562770281c3b700c0f0";
};
# https://modrinth.com/mod/jei
JustEnoughItems = pkgs.fetchurl {
url = "https://cdn.modrinth.com/data/u6dRKJwZ/versions/YAcQ6elZ/jei-1.21.1-neoforge-19.27.0.340.jar";
sha512 = "8bad8eb3c8e974f867e23e4d74598f603c5fbf03eb5356a386dd37cb9fa23e08ad1f58be6b7be50d2fbf9d3fbfaeac8584c70ced736df4b8f82c7c75be242998";
# url = "https://cdn.modrinth.com/data/u6dRKJwZ/versions/Up8I2nu2/jei-1.21.5-neoforge-21.4.0.27.jar";
# sha512 = "sha512-qVyHvI7XUqD2s1pyFeY2IpOuerSWaL0c0hdrCNoMLXfjQFG7HW+utFB1Ggnssuc1cYKz/857n9M6JmeBOowk3A==";
};
# https://modrinth.com/mod/citadel
Citadel = pkgs.fetchurl {
url = "https://cdn.modrinth.com/data/jJfV67b1/versions/uzrkhBpn/citadel-2.7.0-1.21.1.jar";
sha512 = "d77d8d25279d877ef94f1e48e770547ba2fbee2f01ed151aa932c6e36ed5dd7f846db096f7b1f9c13f49a3e2fd5de434d20a0924a3232e06d20c7ca5f46e47f6";
};
# https://modrinth.com/mod/alexs-mobs(1.21.1)
AlexsMobs = pkgs.fetchurl {
url = "https://cdn.modrinth.com/data/EmNhnNnt/versions/KSgki4uc/alexsmobs-1.22.17.jar";
sha512 = "9f57f20693bb187c54f6d68dc34592b87d0e55a5a4628ad097b0aa39afe165f4a834b83b6590d803e64bac0b1230a8f46369bfe45851a3cc964cf3d88f235277";
};
# https://modrinth.com/mod/farmers-delight
FarmersDelight = pkgs.fetchurl {
url = "https://cdn.modrinth.com/data/R2OftAxM/versions/9gp7w8NC/FarmersDelight-1.21.1-1.3.1.jar";
sha512 = "596340db019049e8da066df13cedb76eb06a8e877c86fd10b38332317b5fd5001cad485a6de87e3a8bf0423d87a1ffbdd51a86f6c06560f40995d68fe05edf95";
};
}
);
};
};
};
allowedUnfreePackagesRegexs = [
"neoforge"
];
}
(
backupCfg {
shbOpt.backup.request = {
user = "minecraft";
sourceDirectories = [
config.services.minecraft-server.dataDir
];
};
} "minecraft"
)
];
}
// This is pseudo code
{
inputs = {
nix-minecraft.url = "github:Infinidoge/nix-minecraft";
};
outputs = inputs: {
nixosConfigurations = {
myhost = nixpkgs.lib.nixosSystem {
modules = [
inputs.nix-minecraft.nixosModules.minecraft-servers
];
};
};
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment