Update configuration.nix

This commit is contained in:
ska
2025-12-22 11:01:09 +00:00
parent b4fba9ee55
commit b6ebd92f02

View File

@@ -152,48 +152,57 @@
# GIT AUTOUPDATE SCRIPT (RUNTIMEEXECUTED)
############################################################
environment.etc."update-nixos-config.sh" = {
mode = "0700";
text = ''
#!/run/current-system/sw/bin/bash
set -e
# === Auto-update script with full PATH and NIX_PATH ===
environment.etc."update-nixos-config.sh".text = ''
#!/run/current-system/sw/bin/bash
set -e
PATH="/run/current-system/sw/bin"
# Ensure all system tools are available
export PATH="/run/current-system/sw/bin:/nix/var/nix/profiles/default/bin"
export NIX_PATH="nixpkgs=/nix/var/nix/profiles/per-user/root/channels/nixos"
DIR="/var/lib/nixos-config"
REPO="https://git.skarockoi.de/ska/nixos-production.git"
LOCAL_PATH="/var/lib/nixos-config"
REPO_URL="https://git.skarockoi.de/ska/nixos-production.git"
if [ ! -d "$DIR/.git" ]; then
mkdir -p "$DIR"
git clone "$REPO" "$DIR"
fi
cd "$DIR"
if [ ! -d "$LOCAL_PATH/.git" ]; then
mkdir -p "$LOCAL_PATH"
chmod 700 "$LOCAL_PATH"
echo "Cloning config from $REPO_URL..."
git clone "$REPO_URL" "$LOCAL_PATH"
else
cd "$LOCAL_PATH"
echo "Fetching updates..."
git fetch origin
if [ "$(git rev-parse HEAD)" != "$(git rev-parse origin/main)" ]; then
LOCAL_HEAD=$(git rev-parse HEAD)
REMOTE_HEAD=$(git rev-parse origin/main)
if [ "$LOCAL_HEAD" != "$REMOTE_HEAD" ]; then
echo "New config available. Updating..."
git reset --hard origin/main
nixos-rebuild switch
nixos-rebuild switch -I nixos-config="$LOCAL_PATH/configuration.nix"
echo "System updated successfully."
else
echo "Config is already up to date."
fi
'';
};
############################################################
# SYSTEMD SERVICE + TIMER (CORRECT EXECUTION)
############################################################
fi
'';
environment.etc."update-nixos-config.sh".mode = "0700";
# === Systemd service (simple, no extra path needed) ===
systemd.services.nixos-git-update = {
description = "Update NixOS config from git";
description = "Update NixOS from public Git config";
script = "/etc/update-nixos-config.sh";
serviceConfig = {
Type = "oneshot";
ExecStart = "/etc/update-nixos-config.sh";
User = "root";
Group = "root";
};
};
systemd.timers.nixos-git-update = {
description = "Check for config updates hourly";
wantedBy = [ "timers.target" ];
timerConfig = {
OnBootSec = "1min";
OnBootSec = "60s";
OnUnitActiveSec = "1h";
};
};