create new service and tag generations
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
{ pkgs, ... }:
|
{ pkgs, ... }:
|
||||||
let
|
let
|
||||||
configLimit = 5;
|
configLimit = 50;
|
||||||
kernel = pkgs.linuxPackages_latest;
|
kernel = pkgs.linuxPackages_latest;
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -91,6 +91,7 @@ in
|
|||||||
efibootmgr
|
efibootmgr
|
||||||
ffmpeg
|
ffmpeg
|
||||||
gcc
|
gcc
|
||||||
|
git
|
||||||
glances
|
glances
|
||||||
gparted
|
gparted
|
||||||
htop
|
htop
|
||||||
|
|||||||
@@ -274,6 +274,56 @@ in
|
|||||||
};
|
};
|
||||||
|
|
||||||
systemd.services = {
|
systemd.services = {
|
||||||
|
system-update-check = {
|
||||||
|
description = "Check for system configuration updates";
|
||||||
|
|
||||||
|
# Required packages for the service
|
||||||
|
path = with pkgs; [
|
||||||
|
git
|
||||||
|
nixos-rebuild
|
||||||
|
openssh
|
||||||
|
];
|
||||||
|
|
||||||
|
# Service configuration
|
||||||
|
serviceConfig = {
|
||||||
|
Type = "oneshot";
|
||||||
|
User = "root";
|
||||||
|
WorkingDirectory = "/etc/nixos"; # Adjust this path to your config location
|
||||||
|
};
|
||||||
|
|
||||||
|
# The script that runs to check for updates
|
||||||
|
script = ''
|
||||||
|
# Store the current commit hash
|
||||||
|
OLD_HASH=$(git rev-parse HEAD)
|
||||||
|
|
||||||
|
# Fetch updates from remote
|
||||||
|
git fetch origin main # Adjust branch name if needed
|
||||||
|
|
||||||
|
# Get the new commit hash
|
||||||
|
NEW_HASH=$(git rev-parse origin/main)
|
||||||
|
|
||||||
|
# If there are changes, pull and rebuild
|
||||||
|
if [ "$OLD_HASH" != "$NEW_HASH" ]; then
|
||||||
|
echo "Updates found, pulling changes..."
|
||||||
|
git pull origin main
|
||||||
|
|
||||||
|
# Get commit message and timestamp for the tag
|
||||||
|
COMMIT_MSG=$(git log -1 --pretty=%B | head -n1 | tr -dc '[:alnum:][:space:]-' | tr '[:space:]' '-')
|
||||||
|
TIMESTAMP=$(date +%Y%m%d-%H%M)
|
||||||
|
SHORT_HASH=$(git rev-parse --short HEAD)
|
||||||
|
|
||||||
|
# Create a profile name using the timestamp, short hash, and commit message
|
||||||
|
PROFILE_NAME="$TIMESTAMP-$SHORT_HASH-$COMMIT_MSG"
|
||||||
|
|
||||||
|
# Rebuild the system
|
||||||
|
nixos-rebuild boot --profile-name "$PROFILE_NAME"
|
||||||
|
|
||||||
|
echo "System rebuilt with profile: $PROFILE_NAME"
|
||||||
|
else
|
||||||
|
echo "No updates found"
|
||||||
|
fi
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
rsync-ssd = {
|
rsync-ssd = {
|
||||||
path = [
|
path = [
|
||||||
@@ -296,4 +346,17 @@ in
|
|||||||
wantedBy = [ "multi-user.target" ];
|
wantedBy = [ "multi-user.target" ];
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
# Create a timer to run the service periodically
|
||||||
|
systemd.timers.system-update-check = {
|
||||||
|
description = "Timer for system configuration updates";
|
||||||
|
wantedBy = [ "timers.target" ];
|
||||||
|
|
||||||
|
# Timer configuration
|
||||||
|
timerConfig = {
|
||||||
|
OnCalendar = "daily"; # Check every day
|
||||||
|
Persistent = true; # Run immediately if last run was missed
|
||||||
|
Unit = "system-update-check.service";
|
||||||
|
};
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user