grace/dots

dotfiles/nix configs

git clone https://git.gae.moe/grace/dots

Grace Yoderi gotta stop doing these massive changesb70d9f9

main
1.3 KiB45 linesraw
1{
2  config,
3  lib,
4  pkgs,
5  ...
6}:
7
8let
9  notify = pkgs.writeShellScript "notify-nixos-switch" ''
10    credentials=/etc/secrets/ntfy-nixos-switch.curl
11    if [ ! -r "$credentials" ]; then
12      exit 0
13    fi
14
15    printf 'Successfully switched %s to %s\n' \
16      ${lib.escapeShellArg config.networking.hostName} \
17      "$(${pkgs.coreutils}/bin/readlink -f /run/current-system)" |
18      ${pkgs.curl}/bin/curl \
19        --config "$credentials" \
20        --fail --silent --show-error \
21        --connect-timeout 3 --max-time 10 \
22        --header ${lib.escapeShellArg "Title: ${config.networking.hostName}: NixOS switch succeeded"} \
23        --data-binary @- \
24        --output /dev/null \
25        https://ntfy.gae.moe/nixos
26  '';
27
28  switch = pkgs.writeShellScript "switch-to-configuration-notify" ''
29    "''${0%/*}/switch-to-configuration-unnotified" "$@"
30    status=$?
31    if [ "$status" -eq 0 ] && [ "''${1:-}" = switch ]; then
32      "''${0%/*}/notify-nixos-switch" || true
33    fi
34    exit "$status"
35  '';
36in
37{
38  config = lib.mkIf config.system.switch.enable {
39    system.activatableSystemBuilderCommands = lib.mkAfter ''
40      mv "$out/bin/switch-to-configuration" "$out/bin/switch-to-configuration-unnotified"
41      ln -s ${notify} "$out/bin/notify-nixos-switch"
42      ln -s ${switch} "$out/bin/switch-to-configuration"
43    '';
44  };
45}