diff options
| author | Gregor Kleen <gkleen@yggdrasil.li> | 2020-03-08 22:46:45 +0100 | 
|---|---|---|
| committer | Gregor Kleen <gkleen@yggdrasil.li> | 2020-03-08 22:46:45 +0100 | 
| commit | 368898379638a33578613b2169fa8c4205c44902 (patch) | |
| tree | 6285ca782f83dc9fb2fe29dec1b113636b633182 | |
| parent | c75b6f1cb45ccbb41af696a2c1bf8176d7bd921e (diff) | |
| download | utils-368898379638a33578613b2169fa8c4205c44902.tar utils-368898379638a33578613b2169fa8c4205c44902.tar.gz utils-368898379638a33578613b2169fa8c4205c44902.tar.bz2 utils-368898379638a33578613b2169fa8c4205c44902.tar.xz utils-368898379638a33578613b2169fa8c4205c44902.zip | |
...
| -rw-r--r-- | nix/default.nix | 1 | ||||
| -rw-r--r-- | nix/notmuch-ssh.nix | 34 | ||||
| -rw-r--r-- | notmuch-ssh-client | 6 | ||||
| -rw-r--r-- | notmuch-ssh-server | 30 | 
4 files changed, 71 insertions, 0 deletions
| 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 { | |||
| 9 | recv = self.callPackage ./recv.nix {}; | 9 | recv = self.callPackage ./recv.nix {}; | 
| 10 | notmuch-tcp = self.callPackage ./notmuch-tcp.nix {}; | 10 | notmuch-tcp = self.callPackage ./notmuch-tcp.nix {}; | 
| 11 | notmuch-links = self.callPackage ./notmuch-links.nix { inherit notmuch-tcp; }; | 11 | notmuch-links = self.callPackage ./notmuch-links.nix { inherit notmuch-tcp; }; | 
| 12 | notmuch-ssh = self.callPackage ./notmuch-ssh.nix {}; | ||
| 12 | persistent-nix-shell = self.callPackage ./persistent-nix-shell.nix {}; | 13 | persistent-nix-shell = self.callPackage ./persistent-nix-shell.nix {}; | 
| 13 | worktime = self.callPackage ./worktime.nix {}; | 14 | worktime = self.callPackage ./worktime.nix {}; | 
| 14 | } | 15 | } | 
| 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 @@ | |||
| 1 | { stdenv | ||
| 2 | , python38 | ||
| 3 | , zsh | ||
| 4 | , notmuch | ||
| 5 | , openssh | ||
| 6 | }: | ||
| 7 | |||
| 8 | stdenv.mkDerivation rec { | ||
| 9 | pname = "notmuch-ssh"; | ||
| 10 | version = "1.0"; | ||
| 11 | src = [../notmuch-ssh-client ../notmuch-ssh-server]; | ||
| 12 | |||
| 13 | phases = [ "unpackPhase" "buildPhase" "installPhase" ]; | ||
| 14 | |||
| 15 | python = python38.withPackages (ps: with ps; [pyxdg configparser]); | ||
| 16 | inherit zsh notmuch openssh; | ||
| 17 | |||
| 18 | unpackPhase = '' | ||
| 19 | for srcFile in $src; do | ||
| 20 | cp $srcFile $(stripHash $srcFile) | ||
| 21 | done | ||
| 22 | ''; | ||
| 23 | |||
| 24 | buildPhase = '' | ||
| 25 | substituteAllInPlace notmuch-ssh-client | ||
| 26 | substituteAllInPlace notmuch-ssh-server | ||
| 27 | ''; | ||
| 28 | |||
| 29 | installPhase = '' | ||
| 30 | install -m 0755 -D -t $out/bin \ | ||
| 31 | notmuch-ssh-client notmuch-ssh-server | ||
| 32 | ln -s notmuch-ssh-client $out/bin/notmuch-ssh | ||
| 33 | ''; | ||
| 34 | } | ||
| 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 @@ | |||
| 1 | #!@zsh@/bin/zsh | ||
| 2 | |||
| 3 | instance=${NOTMUCH_INSTANCE:-mail} | ||
| 4 | host=${NOTMUCH_HOST:-notmuch.odin} | ||
| 5 | |||
| 6 | 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 @@ | |||
| 1 | #!@python@/bin/python | ||
| 2 | |||
| 3 | import os | ||
| 4 | import sys | ||
| 5 | import shlex | ||
| 6 | from xdg import BaseDirectory | ||
| 7 | from pathlib import Path | ||
| 8 | from configparser import ConfigParser | ||
| 9 | |||
| 10 | |||
| 11 | config = ConfigParser() | ||
| 12 | config_file = BaseDirectory.load_first_config('notmuch-ssh') | ||
| 13 | if config_file is not None: | ||
| 14 | config.read(config_file) | ||
| 15 | |||
| 16 | original_command = os.environ.get('SSH_ORIGINAL_COMMAND') | ||
| 17 | |||
| 18 | if original_command is None: | ||
| 19 | sys.exit(os.EX_USAGE) | ||
| 20 | |||
| 21 | original_command = shlex.split(original_command, comments = True) | ||
| 22 | |||
| 23 | if len(original_command) < 1: | ||
| 24 | sys.exit(os.EX_USAGE) | ||
| 25 | |||
| 26 | config_section = original_command[0] | ||
| 27 | |||
| 28 | command_environment = config.items(config_section) if config.has_section(config_section) else config.items(config.default_section) | ||
| 29 | |||
| 30 | os.execvpe('@notmuch@/bin/notmuch', original_command[1:], command_environment) | ||
