1
0
Fork 0

Minor tweak

This commit is contained in:
Aires 2024-05-30 15:38:48 -04:00
parent f47d85b5a6
commit 3f55ebdbe3

View file

@ -8,6 +8,20 @@
let let
cfg = config.host.services.autoUpgrade; 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 in
{ {
options = { options = {
@ -31,22 +45,14 @@ in
Type = "oneshot"; Type = "oneshot";
User = "root"; User = "root";
}; };
path = with pkgs; [ path = pathPkgs;
coreutils
gnutar
xz.bin
gzip
git
config.nix.package.out
nh
openssh
sudo
];
script = '' script = ''
cd ${config.users.users.aires.home}/Development/nix-configuration cd ${config.secret.nixConfigFolder}
# Check if there are changes from Git # 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 fetch
sudo -u aires git diff --exit-code main origin/main 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 if [ $? -eq 1 ]; then
sudo -u aires git pull --recurse-submodules sudo -u aires git pull --recurse-submodules
nh os switch nh os switch
@ -71,23 +77,17 @@ in
Type = "oneshot"; Type = "oneshot";
User = config.users.users.aires.name; User = config.users.users.aires.name;
}; };
path = with pkgs; [ path = pathPkgs;
# Courtesy of https://discourse.nixos.org/t/how-to-use-other-packages-binary-in-systemd-service-configuration/14363 # Git diffing strategy courtesy of https://stackoverflow.com/a/40255467
coreutils
gnutar
xz.bin
gzip
git
config.nix.package.out
openssh
];
script = '' script = ''
set -eu set -eu
cd ${config.secrets.nixConfigFolder} cd ${config.secrets.nixConfigFolder}
# Make sure we're up-to-date
git pull --recurse-submodules git pull --recurse-submodules
nix flake update nix flake update
git add flake.lock 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
''; '';
}; };