diff options
| author | Fuwn <[email protected]> | 2024-11-05 11:31:52 +0000 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2024-11-05 11:31:52 +0000 |
| commit | e82543d5299b85110791a27f34149e8fdbc72bd7 (patch) | |
| tree | 21373e914bec316e0db7592f9206bfd1e6f08e7d | |
| parent | fix(flake): correct environment packages (diff) | |
| download | pia.nix-e82543d5299b85110791a27f34149e8fdbc72bd7.tar.xz pia.nix-e82543d5299b85110791a27f34149e8fdbc72bd7.zip | |
feat(flake): secrets file support
| -rw-r--r-- | README.md | 6 | ||||
| -rw-r--r-- | flake.nix | 56 |
2 files changed, 43 insertions, 19 deletions
@@ -28,8 +28,14 @@ attribute set. ```nix { config, ... }: { services.pia.enable = true; + + # Hardcoded username and password services.pia.authUserPass.username = "hooty"; services.pia.authUserPass.password = "hunter42"; + + # Alternatively, you can use the `authUserPassFile` attribute if you are using + # a Nix secrets manager. Here's an example using sops-nix. + services.pia.authUserPassFile = config.sops.secrets.pia.path; } ``` @@ -46,24 +46,33 @@ nixosModules.default = { config, ... }: { - options.services.pia = { - enable = lib.mkOption { - default = false; - type = lib.types.bool; - }; - - authUserPass = { - username = lib.mkOption { + options.services.pia = + let + inherit (lib) mkOption; + in + { + enable = mkOption { default = false; - type = lib.types.str; + type = lib.types.bool; }; - password = lib.mkOption { - default = false; - type = lib.types.str; + 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 = [ @@ -95,13 +104,22 @@ ) name; - value = { - inherit (config.services.pia) authUserPass; + value = + let + pia = config.services.pia; + hardcoded = pia.authUserPassFile == /dev/null; + in + { + authUserPass = if hardcoded then pia.authUserPass else null; + autoStart = false; + updateResolvConf = true; - autoStart = false; - config = "config ${resources}/${name}"; - 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) ( |