-
Notifications
You must be signed in to change notification settings - Fork 0
/
pia-system.nix
64 lines (53 loc) · 1.56 KB
/
pia-system.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
{ config, pkgs, ... }:
with builtins;
let pia-config = with pkgs; stdenv.mkDerivation rec {
name = "pia-config";
buildInputs = [
unzip
libuuid
];
src = fetchurl {
url = "https://www.privateinternetaccess.com/openvpn/openvpn.zip";
sha256 = "6f899ff3a040be09499c90091f1f91859487ab176c54c610f6d4be2c74e5f32f";
};
unpackPhase = ''
unzip $src
'';
installPhase = ''
mkdir -p "$out/uuids"
ls *.ovpn | while read FILE; do
uuidgen --md5 -n @url -N "$FILE" > "$out/uuids/$FILE"
done
mkdir -p "$out/config"
mv *.ovpn "$out/config"
mkdir -p "$out/certs"
mv *.crt *.pem "$out/certs"
'';
fixupPhase = ''
sed -i "s|crl.rsa.2048.pem|$out/certs/\0|g" "$out"/config/*.ovpn
sed -i "s|ca.rsa.2048.crt|$out/certs/\0|g" "$out"/config/*.ovpn
sed -i "s|auth-user-pass|auth-user-pass ${./pia-login.conf}|g" "$out"/config/*.ovpn
'';
};
in
{
environment.systemPackages = with pkgs; [
openresolv
];
# Configure all our servers
# Use with `sudo systemctl start openvpn-us-east`
services.openvpn.servers = let
vpn_str = with (import <nixpkgs> {}).lib.strings;
file: removeSuffix ".ovpn" (toLower (replaceStrings [" "] ["-"] file));
in
foldl' (init: file: init // {
"${vpn_str file}" = {
config = readFile "${pia-config}/config/${file}";
autoStart = false;
up = "echo nameserver $nameserver | ${pkgs.openresolv}/sbin/resolvconf -m 0 -a $dev";
down = "${pkgs.openresolv}/sbin/resolvconf -d $dev";
};
}) {} (
attrNames (readDir "${pia-config}/config")
);
}