From 3f55ebdbe3c25a01b1d4139a39b4faf11f0106f9 Mon Sep 17 00:00:00 2001 From: Andre Date: Thu, 30 May 2024 15:38:48 -0400 Subject: [PATCH 1/2] Minor tweak --- modules/services/autoupgrade.nix | 48 ++++++++++++++++---------------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/modules/services/autoupgrade.nix b/modules/services/autoupgrade.nix index 4f10f84..51a4e41 100644 --- a/modules/services/autoupgrade.nix +++ b/modules/services/autoupgrade.nix @@ -8,6 +8,20 @@ let cfg = config.host.services.autoUpgrade; + + # List of packages to include in each service's $PATH + pathPks = with pkgs; [ + # Courtesy of https://discourse.nixos.org/t/how-to-use-other-packages-binary-in-systemd-service-configuration/14363 + coreutils + gnutar + xz.bin + gzip + git + config.nix.package.out + nh + openssh + sudo + ]; in { options = { @@ -31,22 +45,14 @@ in Type = "oneshot"; User = "root"; }; - path = with pkgs; [ - coreutils - gnutar - xz.bin - gzip - git - config.nix.package.out - nh - openssh - sudo - ]; + path = pathPkgs; script = '' - cd ${config.users.users.aires.home}/Development/nix-configuration - # Check if there are changes from Git + cd ${config.secret.nixConfigFolder} + # Check if there are changes from Git. + # Since we're running this as root, we need to su into the user who owns the config folder. sudo -u aires git fetch sudo -u aires git diff --exit-code main origin/main + # If we have changes (git diff returns 1), pull changes and run the update if [ $? -eq 1 ]; then sudo -u aires git pull --recurse-submodules nh os switch @@ -71,23 +77,17 @@ in Type = "oneshot"; User = config.users.users.aires.name; }; - path = with pkgs; [ - # Courtesy of https://discourse.nixos.org/t/how-to-use-other-packages-binary-in-systemd-service-configuration/14363 - coreutils - gnutar - xz.bin - gzip - git - config.nix.package.out - openssh - ]; + path = pathPkgs; + # Git diffing strategy courtesy of https://stackoverflow.com/a/40255467 script = '' set -eu cd ${config.secrets.nixConfigFolder} + # Make sure we're up-to-date git pull --recurse-submodules nix flake update git add flake.lock - git diff --quiet && git diff --staged --quiet || git commit -am "Update flake.lock" && git push # Courtesy of https://stackoverflow.com/a/40255467 + # Only commit and push if the lock file has changed, otherwise quietly exit + git diff --quiet && git diff --staged --quiet || git commit -am "Update flake.lock" && git push ''; }; From 28b14a9ce39450ad56400bd02035e5b92f86d482 Mon Sep 17 00:00:00 2001 From: Andre Date: Thu, 30 May 2024 18:02:54 -0400 Subject: [PATCH 2/2] Typos --- flake.lock | 2 +- modules/services/autoupgrade.nix | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/flake.lock b/flake.lock index 9b117bc..ab3f108 100644 --- a/flake.lock +++ b/flake.lock @@ -252,7 +252,7 @@ "locked": { "lastModified": 1717092160, "narHash": "sha256-dype0zRMyP94Uo8YC1vWQ6lkvXLYMep6+Xo7AW4K9cs=", - "ref": "42ddf14d36d9fab1eb070f51fdf1991d1a21dde9", + "ref": "refs/heads/main", "rev": "42ddf14d36d9fab1eb070f51fdf1991d1a21dde9", "revCount": 42, "type": "git", diff --git a/modules/services/autoupgrade.nix b/modules/services/autoupgrade.nix index 51a4e41..fca180f 100644 --- a/modules/services/autoupgrade.nix +++ b/modules/services/autoupgrade.nix @@ -10,7 +10,7 @@ let cfg = config.host.services.autoUpgrade; # List of packages to include in each service's $PATH - pathPks = with pkgs; [ + pathPkgs = with pkgs; [ # Courtesy of https://discourse.nixos.org/t/how-to-use-other-packages-binary-in-systemd-service-configuration/14363 coreutils gnutar @@ -47,7 +47,7 @@ in }; path = pathPkgs; script = '' - cd ${config.secret.nixConfigFolder} + cd ${config.secrets.nixConfigFolder} # Check if there are changes from Git. # Since we're running this as root, we need to su into the user who owns the config folder. sudo -u aires git fetch