diff options
| author | Fuwn <[email protected]> | 2024-10-02 12:55:22 +0000 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2024-10-02 13:38:00 +0000 |
| commit | 27fb5c26e022422b4939f2445a0eb17a3a108cb2 (patch) | |
| tree | 0482793cc29b1e3c77f45d3b42ae8075adbb2c80 | |
| parent | Add AGPL V3 (diff) | |
| download | pia.nix-27fb5c26e022422b4939f2445a0eb17a3a108cb2.tar.xz pia.nix-27fb5c26e022422b4939f2445a0eb17a3a108cb2.zip | |
format(flake.nix): reformat
| -rw-r--r-- | flake.nix | 104 |
1 files changed, 64 insertions, 40 deletions
@@ -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); - }; + }; }; - }; } |