Compare commits
44 Commits
0f07029660
...
flake-upda
Author | SHA1 | Date | |
---|---|---|---|
|
bc405d562b | ||
|
ceea87ad5b | ||
|
851c8c797d | ||
|
f542f84b38 | ||
|
ed5b4cbd14 | ||
|
761015b478 | ||
|
20eaa0dae3 | ||
|
f5dd2ecc82 | ||
|
f9b71edc81 | ||
|
7719c812bd | ||
|
3c027501c5 | ||
|
d65b916d40 | ||
|
a1cde5ef34 | ||
|
686906cf77 | ||
|
37f986cefc | ||
|
1dcef60e92 | ||
|
5970fcabc8 | ||
|
766d18ad52 | ||
|
47c02828e3 | ||
|
5fff601b29 | ||
|
04236cf485 | ||
|
fcf95d1430 | ||
|
12798ff1a1 | ||
|
01572c6f3d | ||
|
cde1265492 | ||
|
225743b432 | ||
|
ac5a7b1954 | ||
|
b1ba5f6dfc | ||
|
c36161b19e | ||
|
593cb43662 | ||
|
a9045fe86a | ||
|
b001afa40d | ||
|
d54beba986 | ||
|
784fdf8af1 | ||
|
536120fadc | ||
|
ac47c73bf1 | ||
|
2d1109d012 | ||
c543bc13ea | |||
b4d1681b99 | |||
6c32ffbe94 | |||
6787243414 | |||
d350807e8c | |||
f872c8db0c | |||
8c53c66c4d |
842
flake.lock
generated
842
flake.lock
generated
File diff suppressed because it is too large
Load Diff
@@ -162,7 +162,10 @@ in {
|
||||
monitor = ",preferred,auto,1";
|
||||
|
||||
# Autostart
|
||||
exec-once = ["firefox"];
|
||||
exec-once = [
|
||||
(lib.getExe pkgs.firefox)
|
||||
(lib.getExe pkgs.waybar)
|
||||
];
|
||||
|
||||
# Look and Feel
|
||||
general = {
|
||||
|
@@ -12,7 +12,14 @@
|
||||
|
||||
"modules-center": [],
|
||||
|
||||
"modules-right": ["idle_inhibitor", "disk", "cpu", "memory", "pulseaudio", "battery", "clock", "tray"],
|
||||
"modules-right": ["idle_inhibitor", "custom/nixos-update", "disk", "cpu", "memory", "pulseaudio", "battery", "clock", "tray"],
|
||||
|
||||
"custom/nixos-update": {
|
||||
"exec": "frajul-auto-upgrade-status",
|
||||
"return-type": "json",
|
||||
"interval": 2,
|
||||
"on-click-right": "frajul-auto-upgrade-toggle"
|
||||
},
|
||||
|
||||
"hyprland/workspaces": {
|
||||
"on-scroll-up": "hyprctl dispatch workspace m+1",
|
||||
@@ -35,6 +42,7 @@
|
||||
},
|
||||
|
||||
"idle_inhibitor": {
|
||||
"start-activated": true,
|
||||
"format": "{icon}",
|
||||
"format-icons": {
|
||||
"activated": "",
|
||||
|
@@ -10,7 +10,7 @@
|
||||
in {
|
||||
programs.waybar = {
|
||||
enable = true;
|
||||
systemd.enable = true;
|
||||
# systemd.enable = true;
|
||||
settings.mainBar = builtins.fromJSON (builtins.readFile ./config.json);
|
||||
};
|
||||
|
||||
|
@@ -20,7 +20,7 @@
|
||||
"flakes"
|
||||
"ca-derivations"
|
||||
];
|
||||
# warn-dirty = false; # TODO: do I want it? also for systems
|
||||
warn-dirty = false; # TODO: do I want it? also for systems
|
||||
};
|
||||
};
|
||||
|
||||
|
@@ -32,6 +32,10 @@
|
||||
enable = true;
|
||||
overrideSettings = false;
|
||||
};
|
||||
frajulAutoUpgrade = {
|
||||
enable = true;
|
||||
flakePath = "/home/julian/.dotfiles";
|
||||
};
|
||||
};
|
||||
|
||||
services.blueman.enable = true;
|
||||
|
@@ -43,6 +43,15 @@
|
||||
cores = 0;
|
||||
};
|
||||
|
||||
system.autoUpgrade = {
|
||||
enable = true;
|
||||
flake = "git+https://gitlab.julian-mutter.de/julian/dotfiles";
|
||||
flags = [
|
||||
"--recreate-lock-file" # update lock file
|
||||
];
|
||||
dates = "02:13";
|
||||
};
|
||||
|
||||
# optimize store by hardlinking store files
|
||||
nix.optimise.automatic = true;
|
||||
nix.optimise.dates = ["03:15"];
|
||||
|
@@ -1,4 +1,5 @@
|
||||
{
|
||||
# hydra-auto-upgrade = import ./hydra-auto-upgrade.nix;
|
||||
syncthing = import ./syncthing.nix;
|
||||
frajulAutoUpgrade = import ./frajul-auto-upgrade.nix;
|
||||
}
|
||||
|
154
modules/nixos/frajul-auto-upgrade.nix
Normal file
154
modules/nixos/frajul-auto-upgrade.nix
Normal file
@@ -0,0 +1,154 @@
|
||||
{
|
||||
config,
|
||||
lib,
|
||||
pkgs,
|
||||
...
|
||||
}: let
|
||||
cfg = config.modules.frajulAutoUpgrade;
|
||||
|
||||
flagFile = "/var/lib/frajul-auto-upgrade/flag";
|
||||
lockFile = "/var/lib/frajul-auto-upgrade/lock";
|
||||
lastStatusFile = "/var/lib/frajul-auto-upgrade/last-status";
|
||||
lastAttemptFile = "/var/lib/frajul-auto-upgrade/last-attempt";
|
||||
in {
|
||||
options.modules.frajulAutoUpgrade = {
|
||||
enable = lib.mkEnableOption "NixOS auto-upgrade on boot";
|
||||
|
||||
user = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
default = "root";
|
||||
description = "User account to run the upgrade service as.";
|
||||
};
|
||||
|
||||
flakePath = lib.mkOption {
|
||||
type = lib.types.path;
|
||||
description = "The path to your flake";
|
||||
};
|
||||
};
|
||||
|
||||
config = lib.mkIf cfg.enable {
|
||||
# Ensure the flag directory exists
|
||||
systemd.tmpfiles.rules = [
|
||||
"d /var/lib/frajul-auto-upgrade 0755 root root -"
|
||||
"f ${flagFile} 0766 root root -"
|
||||
"f ${lastStatusFile} 0644 root root -"
|
||||
"f ${lastAttemptFile} 0644 root root -"
|
||||
];
|
||||
|
||||
environment.systemPackages = [
|
||||
(pkgs.writeShellScriptBin "frajul-auto-upgrade" ''
|
||||
#!/bin/sh
|
||||
FLAG_FILE="${flagFile}"
|
||||
LOCK_FILE="${lockFile}"
|
||||
LAST_STATUS_FILE="${lastStatusFile}"
|
||||
LAST_ATTEMPT_FILE="${lastAttemptFile}"
|
||||
|
||||
TODAY=$(date +%Y-%m-%d)
|
||||
|
||||
if [ ! -f "$FLAG_FILE" ] || [ "$(cat "$FLAG_FILE")" != "enabled" ]; then
|
||||
echo "Auto upgrade disabled. Exiting."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Check if already attempted today
|
||||
if [ -f "$LAST_ATTEMPT_FILE" ]; then
|
||||
LAST_ATTEMPT_DATE=$(cut -d' ' -f1 "$LAST_ATTEMPT_FILE")
|
||||
if [ "$LAST_ATTEMPT_DATE" = "$TODAY" ]; then
|
||||
echo "Update already attempted today. Skipping."
|
||||
exit 0
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ -f "$LOCK_FILE" ]; then
|
||||
echo "Already running"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo $$ > "$LOCK_FILE"
|
||||
trap 'rm -f "$LOCK_FILE"' EXIT
|
||||
|
||||
if nix flake update --flake "${cfg.flakePath}" && nixos-rebuild switch --flake "${cfg.flakePath}"; then
|
||||
echo "success" > "$LAST_STATUS_FILE"
|
||||
else
|
||||
echo "failure" > "$LAST_STATUS_FILE"
|
||||
fi
|
||||
|
||||
# Write full timestamp
|
||||
date '+%Y-%m-%d %H:%M:%S' > "$LAST_ATTEMPT_FILE"
|
||||
'')
|
||||
|
||||
(pkgs.writeShellScriptBin "frajul-auto-upgrade-status" ''
|
||||
#!/bin/sh
|
||||
FLAG_FILE="${flagFile}"
|
||||
LOCK_FILE="${lockFile}"
|
||||
LAST_STATUS_FILE="${lastStatusFile}"
|
||||
LAST_ATTEMPT_FILE="${lastAttemptFile}"
|
||||
|
||||
if [ -f "$LOCK_FILE" ]; then
|
||||
ICON=" "
|
||||
STATUS="running"
|
||||
elif [ -f "$FLAG_FILE" ] && [ "$(cat "$FLAG_FILE")" == "enabled" ]; then
|
||||
LAST_STATUS="unknown"
|
||||
LAST_ATTEMPT="never"
|
||||
if [ -f "$LAST_STATUS_FILE" ]; then
|
||||
LAST_STATUS=$(cat "$LAST_STATUS_FILE")
|
||||
fi
|
||||
|
||||
if [ -f "$LAST_ATTEMPT_FILE" ]; then
|
||||
LAST_ATTEMPT=$(cat "$LAST_ATTEMPT_FILE")
|
||||
fi
|
||||
|
||||
if [ "$LAST_STATUS" = "success" ]; then
|
||||
ICON=""
|
||||
elif [ "$LAST_STATUS" = "failure" ]; then
|
||||
ICON=""
|
||||
else
|
||||
ICON=""
|
||||
fi
|
||||
|
||||
STATUS="enabled (last attempt: $LAST_ATTEMPT, $LAST_STATUS)"
|
||||
else
|
||||
ICON=" "
|
||||
STATUS="disabled"
|
||||
fi
|
||||
|
||||
echo "{\"text\": \"$ICON\", \"tooltip\": \"NixOS Auto Update: $STATUS\"}"
|
||||
'')
|
||||
|
||||
(pkgs.writeShellScriptBin "frajul-auto-upgrade-toggle" ''
|
||||
#!/bin/sh
|
||||
FLAG_FILE="${flagFile}"
|
||||
LOCK_FILE="${lockFile}"
|
||||
|
||||
if [ ! -f "$FLAG_FILE" ] || [ "$(cat "$FLAG_FILE")" != "enabled" ]; then
|
||||
echo "enabled" > "$FLAG_FILE"
|
||||
else
|
||||
echo "disabled" > "$FLAG_FILE"
|
||||
if [ -f "$LOCK_FILE" ]; then
|
||||
kill -TERM "$(cat "$LOCK_FILE")"
|
||||
fi
|
||||
fi
|
||||
'')
|
||||
];
|
||||
|
||||
systemd.services.frajul-auto-upgrade = {
|
||||
description = "Frajul's NixOS Auto Upgrade";
|
||||
after = ["network-online.target"];
|
||||
restartIfChanged = false; # Do not start service on nixos switch
|
||||
serviceConfig = {
|
||||
Type = "oneshot";
|
||||
User = cfg.user;
|
||||
ExecStart = "/run/current-system/sw/bin/frajul-auto-upgrade";
|
||||
};
|
||||
};
|
||||
systemd.timers.frajul-auto-upgrade = {
|
||||
description = "Run Frajul's NixOS Auto Upgrade at boot";
|
||||
wantedBy = ["timers.target"];
|
||||
timerConfig = {
|
||||
OnBootSec = "1min";
|
||||
AccuracySec = "10s";
|
||||
Unit = "frajul-auto-upgrade.service";
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
Reference in New Issue
Block a user