aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--flake.nix104
1 files changed, 64 insertions, 40 deletions
diff --git a/flake.nix b/flake.nix
index d7c73aa..5403ff7 100644
--- a/flake.nix
+++ b/flake.nix
@@ -1,48 +1,72 @@
{
- inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.05"; };
- outputs = { self, nixpkgs }: {
- nixosModule = { lib, config, ... }: {
- options = {
- services.pia = {
- enable = nixpkgs.lib.mkOption {
- default = false;
- type = nixpkgs.lib.types.bool;
- };
- authUserPass = {
- username = nixpkgs.lib.mkOption {
+ 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.str;
+ type = nixpkgs.lib.types.bool;
};
- password = nixpkgs.lib.mkOption {
- default = false;
- type = nixpkgs.lib.types.str;
+
+ 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;
+
+ 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)
+ )
+ )
+ );
};
- fixup = (builtins.replaceStrings [ ".ovpn" "_" ] [ "" "-" ]);
- servers =
- (builtins.filter (name: !(isNull (builtins.match ".+ovpn$" name)))
- (builtins.attrNames (builtins.readDir resources)));
- make_server = (name: {
- name = fixup name;
- value = {
- autoStart = false;
- authUserPass = config.services.pia.authUserPass;
- config = "config ${resources}/${name}";
- updateResolvConf = true;
- };
- });
- in builtins.listToAttrs (map make_server servers);
- };
+ };
};
- };
}