feat: add update-checker [WIP]

This commit is contained in:
Swarsel 2024-08-10 16:47:46 +02:00
parent bbaee7acd8
commit 2da6d3182d
Signed by: swarsel
GPG key ID: 26A54C31F2A4FD84
8 changed files with 141 additions and 24 deletions

1
.gitignore vendored
View file

@ -1,2 +1,3 @@
secrets/keys/pubring.kbx secrets/keys/pubring.kbx
secrets/keys/private-keys-v1.d/ secrets/keys/private-keys-v1.d/
result

View file

@ -4147,6 +4147,7 @@ As such, I also define three additional overlays:
waybarupdate = callPackage ./waybarupdate { }; waybarupdate = callPackage ./waybarupdate { };
opacitytoggle = callPackage ./opacitytoggle { }; opacitytoggle = callPackage ./opacitytoggle { };
fs-diff = callPackage ./fs-diff { }; fs-diff = callPackage ./fs-diff { };
update-checker = callPackage ./update-checker { };
} }
#+end_src #+end_src
@ -4558,6 +4559,35 @@ done
} }
#+end_src #+end_src
**** update-checker
#+begin_src shell :tangle scripts/update-checker.sh
updates="$(cd ~/.dotfiles && nix flake lock --update-input nixpkgs && nix build .#nixosConfigurations."$HOSTNAME".config.system.build.toplevel && nvd diff /run/current-system ./result | grep -c '\[U')"
alt="has-updates"
if [[ $updates -eq 0 ]]; then
alt="updated"
fi
tooltip="System updated"
if [[ $updates != 0 ]]; then
tooltip=$(cd ~/.dotfiles && nvd diff /run/current-system ./result | grep -e '\[U' | awk '{ for (i=3; i<NF; i++) printf $i " "; if (NF >= 3) print $NF; }' ORS='\\n' )
fi
echo "{ \"text\":\"$updates\", \"alt\":\"$alt\", \"tooltip\":\"$tooltip\" }"
#+end_src
#+begin_src nix :tangle pkgs/update-checker/default.nix
{ writeShellApplication, sway}:
writeShellApplication {
name = "update-checker";
text = builtins.readFile ../../scripts/update-checker.sh;
}
#+end_src
*** Overlays *** Overlays
@ -4566,9 +4596,25 @@ done
{ inputs, ... }: { { inputs, ... }: {
additions = final: _prev: import ../pkgs { pkgs = final; }; additions = final: _prev: import ../pkgs { pkgs = final; };
modifications = final: _prev: { modifications = final: _prev: {
# example = prev.example.overrideAttrs (oldAttrs: rec { vesktop = _prev.vesktop.override {
# ... withSystemVencord = true;
# }); };
nerdfonts = _prev.nerdfonts.override {
fonts = [ "FiraMono" "FiraCode" "NerdFontsSymbolsOnly" ];
};
firefox = _prev.firefox.override {
nativeMessagingHosts = [
_prev.tridactyl-native
_prev.browserpass
_prev.plasma5Packages.plasma-browser-integration
];
};
prismlauncher = _prev.prismlauncher.override {
glfw = _prev.glfw-wayland-minecraft;
};
# river = prev.river.overrideAttrs (oldAttrs: rec { # river = prev.river.overrideAttrs (oldAttrs: rec {
# pname = "river"; # pname = "river";
@ -6609,6 +6655,7 @@ Programming languages and default lsp's are defined here: [[#h:0e7e8bea-ec58-499
waybarupdate waybarupdate
opacitytoggle opacitytoggle
fs-diff fs-diff
update-checker
(pkgs.writeScriptBin "project" '' (pkgs.writeScriptBin "project" ''
#! ${pkgs.bash}/bin/bash #! ${pkgs.bash}/bin/bash
@ -7593,6 +7640,19 @@ The rest of this configuration is found here:
interval = 60; interval = 60;
}; };
"custom/nix-updates" = {
exec = "update-checker";
on-click = "update-checker && notify-send 'The system has been updated'";
interval = 3600;
tooltip = true;
return-type = "json";
format = "{} {icon} ?";
format-icons = {
has-updates = "";
updated= "";
};
};
"group/hardware" = { "group/hardware" = {
orientation = "inherit"; orientation = "inherit";
drawer = { drawer = {
@ -7603,6 +7663,8 @@ The rest of this configuration is found here:
"temperature" "temperature"
"power-profiles-daemon" "power-profiles-daemon"
"custom/left-arrow-light" "custom/left-arrow-light"
"custom/left-arrow-dark"
"custom/left-arrow-light"
"disk" "disk"
"custom/left-arrow-dark" "custom/left-arrow-dark"
"memory" "memory"
@ -8408,10 +8470,12 @@ This tangles the flake.nix file; This block only needs to be touched when updati
nixConfig = { nixConfig = {
extra-substituters = [ extra-substituters = [
"https://nix-community.cachix.org" "https://nix-community.cachix.org"
"https://cache.ngi0.nixos.org/"
]; ];
extra-trusted-public-keys = [ extra-trusted-public-keys = [
"nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs=" "nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs="
"cache.ngi0.nixos.org-1:KqH5CBLNSyX184S9BKZJo1LxrxJ9ltnY2uAs5c/f1MA="
]; ];
}; };

View file

@ -4,10 +4,12 @@
nixConfig = { nixConfig = {
extra-substituters = [ extra-substituters = [
"https://nix-community.cachix.org" "https://nix-community.cachix.org"
"https://cache.ngi0.nixos.org/"
]; ];
extra-trusted-public-keys = [ extra-trusted-public-keys = [
"nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs=" "nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs="
"cache.ngi0.nixos.org-1:KqH5CBLNSyX184S9BKZJo1LxrxJ9ltnY2uAs5c/f1MA="
]; ];
}; };

View file

@ -14,4 +14,5 @@ in
waybarupdate = callPackage ./waybarupdate { }; waybarupdate = callPackage ./waybarupdate { };
opacitytoggle = callPackage ./opacitytoggle { }; opacitytoggle = callPackage ./opacitytoggle { };
fs-diff = callPackage ./fs-diff { }; fs-diff = callPackage ./fs-diff { };
update-checker = callPackage ./update-checker { };
} }

View file

@ -0,0 +1,6 @@
{ writeShellApplication, sway }:
writeShellApplication {
name = "update-checker";
text = builtins.readFile ../../scripts/update-checker.sh;
}

View file

@ -29,6 +29,19 @@
interval = 60; interval = 60;
}; };
"custom/nix-updates" = {
exec = "update-checker";
on-click = "update-checker && notify-send 'The system has been updated'";
interval = 3600;
tooltip = true;
return-type = "json";
format = "{} {icon} ?";
format-icons = {
has-updates = "";
updated = "";
};
};
"group/hardware" = { "group/hardware" = {
orientation = "inherit"; orientation = "inherit";
drawer = { drawer = {
@ -39,6 +52,8 @@
"temperature" "temperature"
"power-profiles-daemon" "power-profiles-daemon"
"custom/left-arrow-light" "custom/left-arrow-light"
"custom/left-arrow-dark"
"custom/left-arrow-light"
"disk" "disk"
"custom/left-arrow-dark" "custom/left-arrow-dark"
"memory" "memory"
@ -159,6 +174,13 @@
on-click-right = "kitty -o confirm_os_window_close=0 btm"; on-click-right = "kitty -o confirm_os_window_close=0 btm";
}; };
"custom/vpn" = {
format = "VPN ";
exec = "echo '{\"class\": \"connected\"}'";
exec-if = "test -d /proc/sys/net/ipv4/conf/tun0";
return-type = "json";
interval = 5;
};
battery = { battery = {
states = { states = {
"warning" = 60; "warning" = 60;

View file

@ -65,6 +65,11 @@ window#waybar.hidden {
animation-direction: alternate; animation-direction: alternate;
} }
#custom-nix-updates {
color: white;
padding: 0 3px;
}
#custom-outer-right-arrow-dark, #custom-outer-right-arrow-dark,
#custom-outer-left-arrow-dark { #custom-outer-left-arrow-dark {
color: @background; color: @background;
@ -99,6 +104,7 @@ window#waybar.hidden {
} }
#network, #network,
#custom-vpn,
#clock.2, #clock.2,
#battery, #battery,
#cpu, #cpu,
@ -130,6 +136,7 @@ window#waybar.hidden {
background: @foreground-critical; background: @foreground-critical;
} }
#custom-vpn,
#network { #network {
color: #cc99c9; color: #cc99c9;
} }
@ -220,6 +227,7 @@ window#waybar.hidden {
#temperature, #temperature,
#power-profiles-daemon, #power-profiles-daemon,
#network, #network,
#custom-vpn,
#mpris, #mpris,
#battery, #battery,
#custom-pseudobat, #custom-pseudobat,

13
scripts/update-checker.sh Normal file
View file

@ -0,0 +1,13 @@
updates="$(cd ~/.dotfiles && nix flake lock --update-input nixpkgs && nix build .#nixosConfigurations."$HOSTNAME".config.system.build.toplevel && nvd diff /run/current-system ./result | grep -c '\[U')"
alt="has-updates"
if [[ $updates -eq 0 ]]; then
alt="updated"
fi
tooltip="System updated"
if [[ $updates != 0 ]]; then
tooltip=$(cd ~/.dotfiles && nvd diff /run/current-system ./result | grep -e '\[U' | awk '{ for (i=3; i<NF; i++) printf $i " "; if (NF >= 3) print $NF; }' ORS='\\n' )
fi
echo "{ \"text\":\"$updates\", \"alt\":\"$alt\", \"tooltip\":\"$tooltip\" }"