blob: 8c3f178639c6f02c4f6d5fd37c4d47f00c37ccb5 (
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
|
{
inputs = {
flake-utils.url = "github:numtide/flake-utils";
nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.05";
};
outputs =
{
flake-utils,
nixpkgs,
self,
}:
flake-utils.lib.eachDefaultSystem (
system:
let
inherit (pkgs) lib;
pkgs = import nixpkgs {
inherit system;
};
in
{
packages = {
pia = import ./cli.nix { inherit lib pkgs; };
default = self.packages.${system}.pia;
};
apps = {
default = self.apps.${system}.pia;
pia = {
type = "app";
program = "${self.packages.${system}.pia}/bin/pia";
meta = with pkgs.lib; {
description = "Private Internet Access VPN CLI for NixOS";
license = licenses.gpl3Only;
maintainers = [ maintainers.Fuwn ];
homepage = "https://github.com/Fuwn/pia.nix";
mainPackage = "pia";
platforms = platforms.linux;
};
};
};
nixosModules.default =
{ config, ... }:
{
options.services.pia =
let
inherit (lib) mkOption;
in
{
enable = mkOption {
default = false;
type = lib.types.bool;
};
authUserPass = {
username = mkOption {
default = "";
type = lib.types.str;
};
password = mkOption {
default = "";
type = lib.types.str;
};
};
authUserPassFile = mkOption {
default = /dev/null;
type = lib.types.path;
};
};
config = lib.mkIf config.services.pia.enable {
environment.systemPackages = [
self.packages.${system}.pia
];
services.openvpn.servers =
let
inherit (builtins.fromJSON (builtins.readFile "${self}/yae.json")) openvpn;
resources = pkgs.fetchzip {
inherit (openvpn) url;
name = "pia-vpn-config";
sha256 =
lib.replaceStrings
[
"sha256-"
]
[
""
]
openvpn.sha256;
stripRoot = false;
};
in
builtins.listToAttrs (
map
(name: {
name =
(builtins.replaceStrings
[
".ovpn"
"_"
]
[
""
"-"
]
)
name;
value =
let
pia = config.services.pia;
hardcoded = pia.authUserPassFile == /dev/null;
in
{
authUserPass = if hardcoded then pia.authUserPass else null;
autoStart = false;
updateResolvConf = true;
config = ''
config ${resources}/${name}
auth-nocache
${if hardcoded then "" else "auth-user-pass ${pia.authUserPassFile}"}
'';
};
})
(
builtins.filter (name: (builtins.match ".+ovpn$" name) != null) (
builtins.attrNames (builtins.readDir resources)
)
)
);
};
};
}
);
}
|