blob: 0470597493f0e48166972275564fb4274f4dd784 (
plain) (
blame)
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
|
{
inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixos-21.05"; };
outputs = { self, nixpkgs }: {
nixosModule = { config }: {
options = {
services.pia.authUserPass = {
enable = nixpkgs.lib.mkOption {
default = false;
type = nixpkgs.lib.types.bool;
};
username = nixpkgs.lib.mkOption {
default = false;
type = nixpkgs.lib.types.string;
};
password = nixpkgs.lib.mkOption {
default = false;
type = nixpkgs.lib.types.string;
};
};
};
config = nixpkgs.lib.mkIf config.services.pia.enable {
services.openvpn.servers = let
resources = nixpkgs.fetchzip {
name = "pia-vpn-config";
url = "https://www.privateinternetaccess.com/openvpn/openvpn.zip";
sha256 = "ZA8RS6eIjMVQfBt+9hYyhaq8LByy5oJaO9Ed+x8KtW8=";
stripRoot = false;
};
servers = map (builtins.replaceStrings [ ".ovpn" "_" ] [ "" "-" ])
(builtins.filter (name: !(isNull (builtins.match ".+ovpn$" name)))
(builtins.attrNames (builtins.readDir resources)));
make_server = (name: {
name = name;
value = {
autoStart = false;
authUserPass = config.services.pia.authUserPass;
config = "config ${resources}/${name}.ovpn";
updateResolvConf = true;
};
});
in builtins.listToAttrs (map make_server servers);
};
};
};
}
|