Update configuration.nix
This commit is contained in:
@@ -152,48 +152,57 @@
|
|||||||
# GIT AUTO‑UPDATE SCRIPT (RUNTIME‑EXECUTED)
|
# GIT AUTO‑UPDATE SCRIPT (RUNTIME‑EXECUTED)
|
||||||
############################################################
|
############################################################
|
||||||
|
|
||||||
environment.etc."update-nixos-config.sh" = {
|
# === Auto-update script with full PATH and NIX_PATH ===
|
||||||
mode = "0700";
|
environment.etc."update-nixos-config.sh".text = ''
|
||||||
text = ''
|
#!/run/current-system/sw/bin/bash
|
||||||
#!/run/current-system/sw/bin/bash
|
set -e
|
||||||
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"
|
LOCAL_PATH="/var/lib/nixos-config"
|
||||||
REPO="https://git.skarockoi.de/ska/nixos-production.git"
|
REPO_URL="https://git.skarockoi.de/ska/nixos-production.git"
|
||||||
|
|
||||||
if [ ! -d "$DIR/.git" ]; then
|
if [ ! -d "$LOCAL_PATH/.git" ]; then
|
||||||
mkdir -p "$DIR"
|
mkdir -p "$LOCAL_PATH"
|
||||||
git clone "$REPO" "$DIR"
|
chmod 700 "$LOCAL_PATH"
|
||||||
fi
|
echo "Cloning config from $REPO_URL..."
|
||||||
|
git clone "$REPO_URL" "$LOCAL_PATH"
|
||||||
cd "$DIR"
|
else
|
||||||
|
cd "$LOCAL_PATH"
|
||||||
|
echo "Fetching updates..."
|
||||||
git fetch origin
|
git fetch origin
|
||||||
|
LOCAL_HEAD=$(git rev-parse HEAD)
|
||||||
if [ "$(git rev-parse HEAD)" != "$(git rev-parse origin/main)" ]; then
|
REMOTE_HEAD=$(git rev-parse origin/main)
|
||||||
|
if [ "$LOCAL_HEAD" != "$REMOTE_HEAD" ]; then
|
||||||
|
echo "New config available. Updating..."
|
||||||
git reset --hard origin/main
|
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
|
fi
|
||||||
'';
|
fi
|
||||||
};
|
'';
|
||||||
|
environment.etc."update-nixos-config.sh".mode = "0700";
|
||||||
############################################################
|
|
||||||
# SYSTEMD SERVICE + TIMER (CORRECT EXECUTION)
|
|
||||||
############################################################
|
|
||||||
|
|
||||||
|
# === Systemd service (simple, no extra path needed) ===
|
||||||
systemd.services.nixos-git-update = {
|
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 = {
|
serviceConfig = {
|
||||||
Type = "oneshot";
|
Type = "oneshot";
|
||||||
ExecStart = "/etc/update-nixos-config.sh";
|
User = "root";
|
||||||
|
Group = "root";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
systemd.timers.nixos-git-update = {
|
systemd.timers.nixos-git-update = {
|
||||||
|
description = "Check for config updates hourly";
|
||||||
wantedBy = [ "timers.target" ];
|
wantedBy = [ "timers.target" ];
|
||||||
timerConfig = {
|
timerConfig = {
|
||||||
OnBootSec = "1min";
|
OnBootSec = "60s";
|
||||||
OnUnitActiveSec = "1h";
|
OnUnitActiveSec = "1h";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user