From a7608ace946789d47b37a46b206ddfbfc60801ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leonardo=20Eug=C3=AAnio?= Date: Thu, 31 Oct 2024 19:59:35 -0300 Subject: [PATCH] factorio: automate updating server --- hosts/monolith/factorio-server.nix | 9 +-------- pkgs/default.nix | 3 +++ pkgs/factorio-headless/default.nix | 10 ++++++++++ pkgs/factorio-headless/update.sh | 14 ++++++++++++++ 4 files changed, 28 insertions(+), 8 deletions(-) create mode 100644 pkgs/factorio-headless/default.nix create mode 100755 pkgs/factorio-headless/update.sh diff --git a/hosts/monolith/factorio-server.nix b/hosts/monolith/factorio-server.nix index 0de34b1..3c893a5 100644 --- a/hosts/monolith/factorio-server.nix +++ b/hosts/monolith/factorio-server.nix @@ -2,14 +2,7 @@ { services.factorio = { enable = true; - package = pkgs.unstable.factorio-headless.overrideAttrs (_: rec { - version = "2.0.12"; - src = pkgs.fetchurl { - name = "factorio_headless_x64-${version}.tar.xz"; - url = "https://www.factorio.com/get-download/${version}/headless/linux64"; - hash = "sha256-0vgg5eJ6ZEFO0TUixNsByCs8YyPGOArgqnXbT5RIjTE="; - }; - }); + package = pkgs.factorio-headless; # I override this in ./pkgs public = true; lan = true; openFirewall = true; diff --git a/pkgs/default.nix b/pkgs/default.nix index b3f1b79..b702886 100644 --- a/pkgs/default.nix +++ b/pkgs/default.nix @@ -8,4 +8,7 @@ rec { emmet-cli = pkgs.callPackage ./emmet-cli.nix { }; material-wifi-icons = pkgs.callPackage ./material-wifi-icons.nix { }; gnome-pass-search-provider = pkgs.callPackage ./gnome-pass-search-provider.nix { }; + factorio-headless = pkgs.callPackage ./factorio-headless { + inherit (pkgs.unstable) factorio-headless; + }; } diff --git a/pkgs/factorio-headless/default.nix b/pkgs/factorio-headless/default.nix new file mode 100644 index 0000000..b6d34ef --- /dev/null +++ b/pkgs/factorio-headless/default.nix @@ -0,0 +1,10 @@ +{ factorio-headless, pkgs }: + +factorio-headless.overrideAttrs (_: rec { + version = "2.0.13"; + src = pkgs.fetchurl { + name = "factorio_headless_x64-${version}.tar.xz"; + url = "https://www.factorio.com/get-download/${version}/headless/linux64"; + hash = "sha256-J7NpAaOeWTrfKEGMAoYULGx6n4PRVpY8c2m9QFolx9E="; + }; +}) diff --git a/pkgs/factorio-headless/update.sh b/pkgs/factorio-headless/update.sh new file mode 100755 index 0000000..9f7bce9 --- /dev/null +++ b/pkgs/factorio-headless/update.sh @@ -0,0 +1,14 @@ +#!/bin/sh + +set -xe + +cd "$(dirname $0)" + +current_version="$(rg '^.*?version\s*=\s*"(.+)".*?$' --replace '$1' ./default.nix)" +current_hash="$(rg '^.*?hash\s*=\s*"(.+)".*?$' --replace '$1' ./default.nix)" + +new_version="$(curl https://factorio.com/api/latest-releases | jq -r .stable.headless)" +new_hash="$(nix-hash --to-sri --type sha256 $(nix-prefetch-url --type sha256 https://www.factorio.com/get-download/${new_version}/headless/linux64))" + +sd "$current_version" "$new_version" ./default.nix +sd "$current_hash" "$new_hash" ./default.nix