nixos-config/configurations/nixos/pureintent/devbox.nix
Sridhar Ratnakumar 54e0b0f276 xb
2026-07-08 16:04:06 -04:00

65 lines
2 KiB
Nix

# Depends on programs.jumphost.socks5Proxy (https://github.com/srid/jumphost-nix)
# for the local SOCKS5 listener. See modules/home/work/juspay.nix:29-31.
{ config, flake, pkgs, ... }:
let
socksPort = config.home-manager.users.${flake.config.me.username}.programs.jumphost.socks5Proxy.port;
proxychainsBin = "${config.programs.proxychains.package}/bin/proxychains4";
proxyExports = ''
export ALL_PROXY=socks5://127.0.0.1:${toString socksPort}
export HTTPS_PROXY=socks5://127.0.0.1:${toString socksPort}
export HTTP_PROXY=socks5://127.0.0.1:${toString socksPort}
'';
vanjaram-run = pkgs.writeShellScriptBin "vanjaram-run" ''
${proxyExports}
exec ${proxychainsBin} "$@"
'';
xbPkg = flake.inputs.xyne-boxes.packages.${pkgs.stdenv.hostPlatform.system}.default;
# Context: https://github.com/juspay/xyne-boxes/pull/14#issuecomment-4918563982
puHost = "10.10.68.56";
wrapXyneBoxes = name: pkgs.writeShellScriptBin name ''
${proxyExports}
export PU_HOST=${puHost}
exec ${proxychainsBin} ${xbPkg}/bin/${name} "$@"
'';
xyne-boxes = wrapXyneBoxes "xyne-boxes";
pu = wrapXyneBoxes "pu";
in
{
programs.proxychains = {
enable = true;
quietMode = true;
chain.type = "strict";
proxyDNS = true;
proxies.devbox = {
enable = true;
type = "socks5";
host = "127.0.0.1";
port = socksPort;
};
};
environment.systemPackages = [
vanjaram-run
pu
xyne-boxes
];
# pu writes per-instance ssh_config files under ~/.pu-state/<name>/. Including
# them lets `ssh <name>` work directly. The inner ssh those configs spawn goes
# to `pu@<PU_HOST>` which is only reachable via vanjaram — route any ssh to
# user `pu` through the SOCKS5 proxy.
home-manager.users.${flake.config.me.username}.programs.ssh = {
includes = [ "~/.pu-state/*/ssh_config" ];
matchBlocks."pu-jumphost" = {
match = "user pu";
proxyCommand = "${pkgs.netcat-openbsd}/bin/nc -X 5 -x 127.0.0.1:${toString socksPort} %h %p";
};
};
}