git.iko.soy/typeable/nixpkgs
on master help sign in
nginx: allow basic auth passwords to be specified in a file
commit4d40adb86d03b856e12984048ced8902e3f73fd3 authorBen Wolsieffer <benwolsieffer@gmail.com> dateWed 4 Apr 2018, 21:47 (9 years ago) parentc84dad3
2 files changed+17−11
nixos/modules/services/web-servers/nginx/default.nix+9−11 nixos/modules/services/web-servers/nginx/vhost-options.nix+8
nixos/modules/services/web-servers/nginx/default.nix+9−11
@@ -218,7 +218,10 @@ let
218218 ssl_certificate_key ${vhost.sslCertificateKey};
219219 ''}
220220
221− ${optionalString (vhost.basicAuth != {}) (mkBasicAuth vhostName vhost.basicAuth)}
221+ ${optionalString (vhost.basicAuthFile != null || vhost.basicAuth != {}) ''
222+ auth_basic secured;
223+ auth_basic_user_file ${if vhost.basicAuthFile != null then vhost.basicAuthFile else mkHtpasswd vhostName vhost.basicAuth};
224+ ''}
222225
223226 ${mkLocations vhost.locations}
224227
@@ -248,16 +251,11 @@ let
248251 ${optionalString (config.proxyPass != null && cfg.recommendedProxySettings) "include ${recommendedProxyConfig};"}
249252 }
250253 '') locations);
251− mkBasicAuth = vhostName: authDef: let
252− htpasswdFile = pkgs.writeText "${vhostName}.htpasswd" (
253− concatStringsSep "\n" (mapAttrsToList (user: password: ''
254− ${user}:{PLAIN}${password}
255− '') authDef)
256− );
257− in ''
258− auth_basic secured;
259− auth_basic_user_file ${htpasswdFile};
260− '';
254+ mkHtpasswd = vhostName: authDef: pkgs.writeText "${vhostName}.htpasswd" (
255+ concatStringsSep "\n" (mapAttrsToList (user: password: ''
256+ ${user}:{PLAIN}${password}
257+ '') authDef)
258+ );
261259in
262260
263261{
nixos/modules/services/web-servers/nginx/vhost-options.nix+8
@@ -193,6 +193,14 @@ with lib;
193193 '';
194194 };
195195
196+ basicAuthFile = mkOption {
197+ type = types.nullOr types.path;
198+ default = null;
199+ description = ''
200+ Basic Auth password file for a vhost.
201+ '';
202+ };
203+
196204 locations = mkOption {
197205 type = types.attrsOf (types.submodule (import ./location-options.nix {
198206 inherit lib;