From 368898379638a33578613b2169fa8c4205c44902 Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Sun, 8 Mar 2020 22:46:45 +0100 Subject: ... --- nix/default.nix | 1 + nix/notmuch-ssh.nix | 34 ++++++++++++++++++++++++++++++++++ notmuch-ssh-client | 6 ++++++ notmuch-ssh-server | 30 ++++++++++++++++++++++++++++++ 4 files changed, 71 insertions(+) create mode 100644 nix/notmuch-ssh.nix create mode 100644 notmuch-ssh-client create mode 100644 notmuch-ssh-server diff --git a/nix/default.nix b/nix/default.nix index 5665a9d..af5f4b7 100644 --- a/nix/default.nix +++ b/nix/default.nix @@ -9,6 +9,7 @@ rec { recv = self.callPackage ./recv.nix {}; notmuch-tcp = self.callPackage ./notmuch-tcp.nix {}; notmuch-links = self.callPackage ./notmuch-links.nix { inherit notmuch-tcp; }; + notmuch-ssh = self.callPackage ./notmuch-ssh.nix {}; persistent-nix-shell = self.callPackage ./persistent-nix-shell.nix {}; worktime = self.callPackage ./worktime.nix {}; } diff --git a/nix/notmuch-ssh.nix b/nix/notmuch-ssh.nix new file mode 100644 index 0000000..6d8bb6c --- /dev/null +++ b/nix/notmuch-ssh.nix @@ -0,0 +1,34 @@ +{ stdenv +, python38 +, zsh +, notmuch +, openssh +}: + +stdenv.mkDerivation rec { + pname = "notmuch-ssh"; + version = "1.0"; + src = [../notmuch-ssh-client ../notmuch-ssh-server]; + + phases = [ "unpackPhase" "buildPhase" "installPhase" ]; + + python = python38.withPackages (ps: with ps; [pyxdg configparser]); + inherit zsh notmuch openssh; + + unpackPhase = '' + for srcFile in $src; do + cp $srcFile $(stripHash $srcFile) + done + ''; + + buildPhase = '' + substituteAllInPlace notmuch-ssh-client + substituteAllInPlace notmuch-ssh-server + ''; + + installPhase = '' + install -m 0755 -D -t $out/bin \ + notmuch-ssh-client notmuch-ssh-server + ln -s notmuch-ssh-client $out/bin/notmuch-ssh + ''; +} diff --git a/notmuch-ssh-client b/notmuch-ssh-client new file mode 100644 index 0000000..6983fbe --- /dev/null +++ b/notmuch-ssh-client @@ -0,0 +1,6 @@ +#!@zsh@/bin/zsh + +instance=${NOTMUCH_INSTANCE:-mail} +host=${NOTMUCH_HOST:-notmuch.odin} + +exec -- @openssh@/bin/ssh ${host} -- ${instance} $@ diff --git a/notmuch-ssh-server b/notmuch-ssh-server new file mode 100644 index 0000000..6a7a2ed --- /dev/null +++ b/notmuch-ssh-server @@ -0,0 +1,30 @@ +#!@python@/bin/python + +import os +import sys +import shlex +from xdg import BaseDirectory +from pathlib import Path +from configparser import ConfigParser + + +config = ConfigParser() +config_file = BaseDirectory.load_first_config('notmuch-ssh') +if config_file is not None: + config.read(config_file) + +original_command = os.environ.get('SSH_ORIGINAL_COMMAND') + +if original_command is None: + sys.exit(os.EX_USAGE) + +original_command = shlex.split(original_command, comments = True) + +if len(original_command) < 1: + sys.exit(os.EX_USAGE) + +config_section = original_command[0] + +command_environment = config.items(config_section) if config.has_section(config_section) else config.items(config.default_section) + +os.execvpe('@notmuch@/bin/notmuch', original_command[1:], command_environment) -- cgit v1.2.3