2023-06-10 10:50:53 +00:00
|
|
|
{ config, pkgs, lib, ... }:
|
|
|
|
let
|
|
|
|
slib = import ../../lib/pure.nix { inherit lib; };
|
2017-09-05 20:58:25 +00:00
|
|
|
cfg = config.krebs.announce-activation;
|
|
|
|
announce-activation = pkgs.writeDash "announce-activation" ''
|
|
|
|
set -efu
|
|
|
|
message=$(${cfg.get-message})
|
|
|
|
exec ${pkgs.irc-announce}/bin/irc-announce \
|
2023-06-10 10:50:53 +00:00
|
|
|
${slib.shell.escape cfg.irc.server} \
|
|
|
|
${slib.shell.escape (toString cfg.irc.port)} \
|
|
|
|
${slib.shell.escape cfg.irc.nick} \
|
|
|
|
${slib.shell.escape cfg.irc.channel} \
|
|
|
|
${lib.escapeShellArg cfg.irc.tls} \
|
2017-09-05 20:58:25 +00:00
|
|
|
"$message"
|
|
|
|
'';
|
|
|
|
default-get-message = pkgs.writeDash "announce-activation-get-message" ''
|
|
|
|
set -efu
|
2023-06-10 10:50:53 +00:00
|
|
|
PATH=${lib.makeBinPath [
|
2017-09-05 20:58:25 +00:00
|
|
|
pkgs.coreutils
|
|
|
|
pkgs.gawk
|
|
|
|
pkgs.gnused
|
|
|
|
pkgs.nix
|
|
|
|
]}
|
|
|
|
profile=/nix/var/nix/profiles/system
|
|
|
|
gen_info=$(nix-env -p "$profile" --list-generations | tail -1)
|
|
|
|
gen_no=$(echo "$gen_info" | awk '{print$1}')
|
|
|
|
pretty_name=$(sed -n '/^PRETTY_NAME=/{s/.*="//;s/"$//;p}' /etc/os-release)
|
|
|
|
echo "activating generation $gen_no $pretty_name"
|
|
|
|
'';
|
|
|
|
in {
|
|
|
|
options.krebs.announce-activation = {
|
2023-06-10 10:50:53 +00:00
|
|
|
enable = lib.mkEnableOption "announce-activation";
|
|
|
|
get-message = lib.mkOption {
|
2017-09-05 20:58:25 +00:00
|
|
|
default = default-get-message;
|
2023-06-10 10:50:53 +00:00
|
|
|
type = lib.types.package;
|
2017-09-05 20:58:25 +00:00
|
|
|
};
|
|
|
|
irc = {
|
|
|
|
# TODO rename channel to target?
|
2023-06-10 10:50:53 +00:00
|
|
|
channel = lib.mkOption {
|
2017-10-01 12:26:12 +00:00
|
|
|
default = "#xxx";
|
2023-06-10 10:50:53 +00:00
|
|
|
type = lib.types.str; # TODO types.irc-channel
|
2017-09-05 20:58:25 +00:00
|
|
|
};
|
2023-06-10 10:50:53 +00:00
|
|
|
nick = lib.mkOption {
|
2017-09-05 20:58:25 +00:00
|
|
|
default = config.krebs.build.host.name;
|
2023-06-10 10:50:53 +00:00
|
|
|
type = slib.types.label;
|
2017-09-05 20:58:25 +00:00
|
|
|
};
|
2023-06-10 10:50:53 +00:00
|
|
|
port = lib.mkOption {
|
2017-09-05 20:58:25 +00:00
|
|
|
default = 6667;
|
2023-06-10 10:50:53 +00:00
|
|
|
type = lib.types.int;
|
2017-09-05 20:58:25 +00:00
|
|
|
};
|
2023-06-10 10:50:53 +00:00
|
|
|
server = lib.mkOption {
|
2017-10-01 11:41:41 +00:00
|
|
|
default = "irc.r";
|
2023-06-10 10:50:53 +00:00
|
|
|
type = slib.types.hostname;
|
2017-09-05 20:58:25 +00:00
|
|
|
};
|
2023-06-10 10:50:53 +00:00
|
|
|
tls = lib.mkOption {
|
2021-09-05 20:51:37 +00:00
|
|
|
default = false;
|
2023-06-10 10:50:53 +00:00
|
|
|
type = lib.types.bool;
|
2021-09-05 20:51:37 +00:00
|
|
|
};
|
2017-09-05 20:58:25 +00:00
|
|
|
};
|
|
|
|
};
|
2023-06-10 10:50:53 +00:00
|
|
|
config = lib.mkIf cfg.enable {
|
|
|
|
system.activationScripts.announce-activation = lib.stringAfter [ "etc" ] ''
|
2017-09-05 20:58:25 +00:00
|
|
|
${announce-activation}
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
}
|