2017-09-05 20:58:25 +00:00
|
|
|
with import <stockholm/lib>;
|
|
|
|
{ config, pkgs, ... }: let
|
|
|
|
cfg = config.krebs.announce-activation;
|
|
|
|
announce-activation = pkgs.writeDash "announce-activation" ''
|
|
|
|
set -efu
|
|
|
|
message=$(${cfg.get-message})
|
|
|
|
exec ${pkgs.irc-announce}/bin/irc-announce \
|
|
|
|
${shell.escape cfg.irc.server} \
|
|
|
|
${shell.escape (toString cfg.irc.port)} \
|
|
|
|
${shell.escape cfg.irc.nick} \
|
|
|
|
${shell.escape cfg.irc.channel} \
|
2021-09-05 20:51:37 +00:00
|
|
|
${escapeShellArg cfg.irc.tls} \
|
2017-09-05 20:58:25 +00:00
|
|
|
"$message"
|
|
|
|
'';
|
|
|
|
default-get-message = pkgs.writeDash "announce-activation-get-message" ''
|
|
|
|
set -efu
|
|
|
|
PATH=${makeBinPath [
|
|
|
|
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 = {
|
|
|
|
enable = mkEnableOption "announce-activation";
|
|
|
|
get-message = mkOption {
|
|
|
|
default = default-get-message;
|
|
|
|
type = types.package;
|
|
|
|
};
|
|
|
|
irc = {
|
|
|
|
# TODO rename channel to target?
|
|
|
|
channel = mkOption {
|
2017-10-01 12:26:12 +00:00
|
|
|
default = "#xxx";
|
2017-09-05 20:58:25 +00:00
|
|
|
type = types.str; # TODO types.irc-channel
|
|
|
|
};
|
|
|
|
nick = mkOption {
|
|
|
|
default = config.krebs.build.host.name;
|
|
|
|
type = types.label;
|
|
|
|
};
|
|
|
|
port = mkOption {
|
|
|
|
default = 6667;
|
|
|
|
type = types.int;
|
|
|
|
};
|
|
|
|
server = mkOption {
|
2017-10-01 11:41:41 +00:00
|
|
|
default = "irc.r";
|
2017-09-05 20:58:25 +00:00
|
|
|
type = types.hostname;
|
|
|
|
};
|
2021-09-05 20:51:37 +00:00
|
|
|
tls = mkOption {
|
|
|
|
default = false;
|
|
|
|
type = types.bool;
|
|
|
|
};
|
2017-09-05 20:58:25 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
config = mkIf cfg.enable {
|
2018-09-18 20:39:53 +00:00
|
|
|
system.activationScripts.announce-activation = stringAfter [ "etc" ] ''
|
2017-09-05 20:58:25 +00:00
|
|
|
${announce-activation}
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
}
|