blob: 5403ff752fa2f9e228cff351a033193f84a1b019 (
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
{
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.05";
outputs =
{ nixpkgs, self }:
{
nixosModules.default =
{ config, ... }:
{
options.services.pia = {
enable = nixpkgs.lib.mkOption {
default = false;
type = nixpkgs.lib.types.bool;
};
authUserPass = {
username = nixpkgs.lib.mkOption {
default = false;
type = nixpkgs.lib.types.str;
};
password = nixpkgs.lib.mkOption {
default = false;
type = nixpkgs.lib.types.str;
};
};
};
config = nixpkgs.lib.mkIf config.services.pia.enable {
services.openvpn.servers =
let
resources = nixpkgs.legacyPackages.x86_64-linux.fetchzip {
name = "pia-vpn-config";
url = "https://www.privateinternetaccess.com/openvpn/openvpn.zip";
sha256 = "ZA8RS6eIjMVQfBt+9hYyhaq8LByy5oJaO9Ed+x8KtW8=";
stripRoot = false;
};
in
builtins.listToAttrs (
map
(name: {
name =
(builtins.replaceStrings
[
".ovpn"
"_"
]
[
""
"-"
]
)
name;
value = {
inherit (config.services.pia) authUserPass;
autoStart = false;
config = "config ${resources}/${name}";
updateResolvConf = true;
};
})
(
builtins.filter (name: !((builtins.match ".+ovpn$" name) == null)) (
builtins.attrNames (builtins.readDir resources)
)
)
);
};
};
};
}
|