From a2396328163d9a22ea33f6c7c0ef050ded27961f Mon Sep 17 00:00:00 2001 From: Martin Benonisen Date: Wed, 20 Mar 2024 15:15:46 +0100 Subject: [PATCH] nixplz --- user/default.nix | 1 + user/packages/default.nix | 5 ++++ user/services/ssh-office.nix | 45 ++++++++++++++++++++++++++++++++++++ 3 files changed, 51 insertions(+) create mode 100644 user/services/ssh-office.nix diff --git a/user/default.nix b/user/default.nix index aaed0ad..5433a34 100644 --- a/user/default.nix +++ b/user/default.nix @@ -19,6 +19,7 @@ ./zsh ./packages ./ssh + ./services/ssh-office.nix ]; firefox.enable = true; tmux.enable = true; diff --git a/user/packages/default.nix b/user/packages/default.nix index 9fb7bf7..b845eca 100644 --- a/user/packages/default.nix +++ b/user/packages/default.nix @@ -2,6 +2,7 @@ home.packages = with pkgs; [ # Generic tools age + discord alacritty unstable.btop bzip2 @@ -75,5 +76,9 @@ # Rust rustup + # homemade + sshotp + ssh-dresden + ]; } diff --git a/user/services/ssh-office.nix b/user/services/ssh-office.nix new file mode 100644 index 0000000..750af3b --- /dev/null +++ b/user/services/ssh-office.nix @@ -0,0 +1,45 @@ +{ pkgs, config, ...}: +let +sshotp = pkgs.writeScriptBin "sshotp" + '' + #!/usr/bin/env expect + set stty_init -echo + set timeout 300 + set totp [lindex $argv 0]; + puts "Our TOTP $totp" + spawn ssh -D 20000 dresden.uio.no + expect { + -re {.*(Verification_Code):} { + send -- "$totp\r" + exp_continue + } + -re {.*dresden.*} { + wait + } + } + ''; +ssh-dresden = pkgs.writeShellApplication { + name = "ssh-dresden"; + runtimeInputs = [ pkgs.rbw pkgs.expect ]; + text = '' + #!/usr/bin/env bash + totp=$(rbw get -f "TOTP" rlogin) + expect -f ${sshotp}/bin/sshotp "$totp" + ''; + +}; +in +{ + systemd.user.services.ssh-office = { + Unit = { + Description = "Office ssh session"; + }; + Service = { + Type = "simple"; + ExecStart = "${ssh-dresden}/bin/ssh-dresden"; + }; + Install = { + WantedBy = [ "default.target" ]; + }; + }; +} \ No newline at end of file