summaryrefslogtreecommitdiffstats
path: root/lass/3modules
diff options
context:
space:
mode:
Diffstat (limited to 'lass/3modules')
-rw-r--r--lass/3modules/default.nix1
-rw-r--r--lass/3modules/ejabberd/default.nix13
-rw-r--r--lass/3modules/klem.nix75
3 files changed, 87 insertions, 2 deletions
diff --git a/lass/3modules/default.nix b/lass/3modules/default.nix
index f6179c394..335658ed8 100644
--- a/lass/3modules/default.nix
+++ b/lass/3modules/default.nix
@@ -6,6 +6,7 @@ _:
./folderPerms.nix
./hass.nix
./hosts.nix
+ ./klem.nix
./mysql-backup.nix
./news.nix
./nichtparasoup.nix
diff --git a/lass/3modules/ejabberd/default.nix b/lass/3modules/ejabberd/default.nix
index 4838a9093..20a38d572 100644
--- a/lass/3modules/ejabberd/default.nix
+++ b/lass/3modules/ejabberd/default.nix
@@ -17,6 +17,7 @@ in {
certfile = mkOption {
type = types.secret-file;
default = {
+ name = "ejabberd-certfile";
path = "${cfg.user.home}/ejabberd.pem";
owner = cfg.user;
source-path = "/var/lib/acme/lassul.us/full.pem";
@@ -25,6 +26,7 @@ in {
dhfile = mkOption {
type = types.secret-file;
default = {
+ name = "ejabberd-dhfile";
path = "${cfg.user.home}/dhparams.pem";
owner = cfg.user;
source-path = "/dev/null";
@@ -74,8 +76,15 @@ in {
systemd.services.ejabberd = {
wantedBy = [ "multi-user.target" ];
- requires = [ "secret.service" ];
- after = [ "network.target" "secret.service" ];
+ after = [
+ config.krebs.secret.files.ejabberd-certfile.service
+ config.krebs.secret.files.ejabberd-s2s_certfile.service
+ "network.target"
+ ];
+ partOf = [
+ config.krebs.secret.files.ejabberd-certfile.service
+ config.krebs.secret.files.ejabberd-s2s_certfile.service
+ ];
serviceConfig = {
ExecStartPre = "${gen-dhparam} ${cfg.dhfile.path}";
ExecStart = "${cfg.pkgs.ejabberdctl}/bin/ejabberdctl foreground";
diff --git a/lass/3modules/klem.nix b/lass/3modules/klem.nix
new file mode 100644
index 000000000..a297adcd1
--- /dev/null
+++ b/lass/3modules/klem.nix
@@ -0,0 +1,75 @@
+{ config, pkgs, ... }: with import <stockholm/lib>; let
+ cfg = config.lass.klem;
+in {
+ options.lass.klem = mkOption {
+ default = {};
+ type = types.attrsOf (types.submodule ({ config, ...}: {
+ options = {
+ target = mkOption {
+ default = ".*";
+ description = ''
+ regex of valid targets
+ can be shown with xclip -selection clipboard -t TARGETS
+ the first hit is taken as target argument
+ '';
+ type = types.str;
+ };
+ script = mkOption {
+ description = ''
+ file to run if entry is selected
+ '';
+ type = types.path;
+ };
+ label = mkOption {
+ default = config._module.args.name;
+ description = ''
+ label to show in dmenu for this script
+ '';
+ type = types.str;
+ };
+ };
+ }));
+ };
+ config = let
+ klem = pkgs.writers.writeDashBin "klem" ''
+ set -x
+
+ labels=""
+ # match filetype against patterns
+ ${concatMapStringsSep "\n" (script: ''
+ ${pkgs.xclip}/bin/xclip -selection clipboard -target TARGETS -out \
+ | grep -q '${script.target}'
+ if [ $? -eq 0 ]; then
+ labels="$labels:${script.label}"
+ fi
+ '') (attrValues cfg)}
+
+ #remove empty line, feed into dmenu
+ script=$(echo "$labels" \
+ | ${pkgs.gnused}/bin/sed 's/^://;s/:/\n/g' \
+ | ${pkgs.dmenu}/bin/dmenu)
+
+ #run the chosen script
+ case $script in
+ ${concatMapStringsSep "\n" (script: indent ''
+ ${script.label})
+ target=$(${pkgs.xclip}/bin/xclip -selection clipboard -target TARGETS -out \
+ | ${pkgs.gnugrep}/bin/grep '${script.target}' \
+ | ${pkgs.gnugrep}/bin/grep -v TARGETS \
+ | ${pkgs.coreutils}/bin/head -1)
+ ${pkgs.xclip}/bin/xclip -selection clipboard -target "$target" -out \
+ | ${script.script} \
+ | ${pkgs.xclip}/bin/xclip -selection clipboard -in
+ ;;
+ '') (attrValues cfg)}
+ esac
+ '';
+ in mkIf (cfg != {}) {
+ environment.systemPackages = [ klem ];
+ nixpkgs.overlays = [
+ (self: super: {
+ klem = klem;
+ })
+ ];
+ };
+}