From b6ebd92f02913510c41255b89537283c0e3ff9e2 Mon Sep 17 00:00:00 2001 From: ska Date: Mon, 22 Dec 2025 11:01:09 +0000 Subject: [PATCH] Update configuration.nix --- configuration.nix | 61 +++++++++++++++++++++++++++-------------------- 1 file changed, 35 insertions(+), 26 deletions(-) diff --git a/configuration.nix b/configuration.nix index 0753463..170d2c3 100644 --- a/configuration.nix +++ b/configuration.nix @@ -152,48 +152,57 @@ # GIT AUTO‑UPDATE SCRIPT (RUNTIME‑EXECUTED) ############################################################ - 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"; }; };