From 3704f9c3417fa6c909ba03ab779734e391e128d0 Mon Sep 17 00:00:00 2001 From: tv Date: Tue, 5 Sep 2017 22:58:25 +0200 Subject: krebs.announce-activation: init --- krebs/3modules/announce-activation.nix | 60 ++++++++++++++++++++++++++++++++++ krebs/3modules/default.nix | 1 + 2 files changed, 61 insertions(+) create mode 100644 krebs/3modules/announce-activation.nix diff --git a/krebs/3modules/announce-activation.nix b/krebs/3modules/announce-activation.nix new file mode 100644 index 000000000..5a3a788c2 --- /dev/null +++ b/krebs/3modules/announce-activation.nix @@ -0,0 +1,60 @@ +with import ; +{ 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} \ + "$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 { + default = "#retiolum"; + 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 { + default = "ni.r"; + type = types.hostname; + }; + }; + }; + config = mkIf cfg.enable { + system.activationScripts.announce-activation = '' + ${announce-activation} + ''; + }; +} diff --git a/krebs/3modules/default.nix b/krebs/3modules/default.nix index abb3d37eb..42df3f053 100644 --- a/krebs/3modules/default.nix +++ b/krebs/3modules/default.nix @@ -6,6 +6,7 @@ let out = { imports = [ + ./announce-activation.nix ./apt-cacher-ng.nix ./backup.nix ./bepasty-server.nix -- cgit v1.2.3 From 77e9bd83e2208d1d732ef505e0e996a2440d5d7c Mon Sep 17 00:00:00 2001 From: tv Date: Tue, 5 Sep 2017 23:00:00 +0200 Subject: krebs configs: enable announce-activation --- krebs/2configs/default.nix | 1 + 1 file changed, 1 insertion(+) diff --git a/krebs/2configs/default.nix b/krebs/2configs/default.nix index e7ece87b6..c3400e171 100644 --- a/krebs/2configs/default.nix +++ b/krebs/2configs/default.nix @@ -5,6 +5,7 @@ with import ; imports = [ ./backup.nix ]; + krebs.announce-activation.enable = true; krebs.enable = true; krebs.tinc.retiolum.enable = true; -- cgit v1.2.3