您将如何使用带有 nixpkgs 的 vpn-slice(非守护程序安装,macOS Catalina)为 openconnect 配置派生或覆盖?

How would you configure a derivation or overlay for openconnect with vpn-slice with nixpkgs (non-daemon install, macOS Catalina)?

我最近开始使用 nix 包管理器作为 single user install(非守护进程)。

我想知道如何配置 openconnect,最好使用 vpn-slicevpnc 脚本替代品,以便轻松安全地拆分隧道

我可以看到 openconnect. I assume I’d want to use something like either an override and/or an overlay 的默认 nix 包配置。 (我还不清楚这两者之间的区别,以及什么时候你会使用一个而不是另一个。)

尽管如此,我想弄清楚如何使用 nix 配置的步骤自然是这些:

  1. 基本二进制安装(覆盖/覆盖/派生)
  2. 配置特定的 vpn 连接
  3. 正在启动(提示输入密码和二次 otp 密码)
  4. 正在停止

理想情况下集成 oath-toolkit 会很棒。例如,oathtool --totp -b <secret>

我发现一个不错的选择是创建一个 nix shell file.

例如vpn-wrapper.nix:

with import <nixpkgs> {};
with pkgs.python37Packages;

let

    python = python37;
    openconnect = pkgs.openconnect.overrideAttrs (oldAttrs: rec {
      buildInputs = oldAttrs.buildInputs ++ [ libproxy ];
      configureFlags = oldAttrs.configureFlags ++ [ "--with-libproxy" ];
    });
    vpn-slice = buildPythonPackage rec {
      name = "vpn-slice";
      version = "v0.13";

      src = pkgs.fetchFromGitHub {
         owner = "dlenski";
     repo = "${name}";
     rev = "${version}";
     sha256 = "1ibrwal80z27c2mh9hx85idmzilx6cpcmgc15z3lyz57bz0krigb";
      };

      propagatedBuildInputs = [ setproctitle ];

      meta = {
        homepage = "https://github.com/dlenski/vpn-slice";
        description = "vpnc-script replacement for easy and secure split-tunnel VPN setup";
        license = stdenv.lib.licenses.gpl3Plus;
        maintainers = with maintainers; [ dlenski ];
      };
    };

in mkShell {
   name = "vpn-env";
   buildInputs = [ vpn-slice openconnect libproxy ];
   shellHook = ''
     echo "Ready to slice your vpn!"
   '';
}

然后你可以通过脚本执行openconnect:

#!/usr/bin/env nix-shell
#! nix-shell vpn-wrapper.nix -i bash

OPENCONNECT=$(which openconnect)
VPNSLICE=$(which vpn-slice)

USERNAME=

$OPENCONNECT --libproxy --passwd-on-stdin --user=“$USERNAME” -s $VPNSCLICE ...

可以找到更扩展的示例(一个 wip)here