git.iko.soy/typeable/nixpkgs
on master help sign in
nixos/piwik: use nginx' virtualHost submodule

instead of redeclaring part of the options. Backward-compatible change. This gives the same flexibility to the user as nginx itself. This also resolves the piwik module break from nginx' enableSSL introduction from #27426.

commit746cc06f1365c2c2f704f78e0e53452a3aae2ff8 authorFlorian Jacob <projects+git@florianjacob.de> dateWed 30 Aug 2017, 15:01 (9 years ago) parented6bd02
1 file changed+22−39
nixos/modules/services/web-apps/piwik.nix+22−39
nixos/modules/services/web-apps/piwik.nix+22−39
@@ -57,41 +57,20 @@ in {
5757 };
5858
5959 nginx = mkOption {
60− # TODO: for maximum flexibility, it would be nice to use nginx's vhost_options module
61− # but this only makes sense if we can somehow specify defaults suitable for piwik.
62− # But users can always copy the piwik nginx config to their configuration.nix and customize it.
63− type = types.nullOr (types.submodule {
64− options = {
65− virtualHost = mkOption {
66− type = types.str;
67− default = "piwik.${config.networking.hostName}";
68− example = "piwik.$\{config.networking.hostName\}";
69− description = ''
70− Name of the nginx virtualhost to use and set up.
71− '';
72− };
73− enableSSL = mkOption {
74− type = types.bool;
75− default = true;
76− description = "Whether to enable https.";
77− };
78− forceSSL = mkOption {
79− type = types.bool;
80− default = true;
81− description = "Whether to always redirect to https.";
82− };
83− enableACME = mkOption {
84− type = types.bool;
85− default = true;
86− description = "Whether to ask Let's Encrypt to sign a certificate for this vhost.";
87− };
88− };
89− });
60+ type = types.nullOr (types.submodule (import ../web-servers/nginx/vhost-options.nix {
61+ inherit config lib;
62+ }));
9063 default = null;
91− example = { virtualHost = "stats.$\{config.networking.hostName\}"; };
64+ example = {
65+ serverName = "stats.$\{config.networking.hostName\}";
66+ enableACME = false;
67+ };
9268 description = ''
93− The options to use to configure an nginx virtualHost.
94− If null (the default), no nginx virtualHost will be configured.
69+ With this option, you can customize an nginx virtualHost which already has sensible defaults for piwik.
70+ Set this to {} to just enable the virtualHost if you don't need any customization.
71+ If enabled, then by default, the serverName is piwik.$\{config.networking.hostName\}, SSL is active,
72+ and certificates are acquired via ACME.
73+ If this is set to null (the default), no nginx virtualHost will be configured.
9574 '';
9675 };
9776 };
@@ -170,11 +149,15 @@ in {
170149 # References:
171150 # https://fralef.me/piwik-hardening-with-nginx-and-php-fpm.html
172151 # https://github.com/perusio/piwik-nginx
173− ${cfg.nginx.virtualHost} = {
174− root = "${pkgs.piwik}/share";
175− enableSSL = cfg.nginx.enableSSL;
176− enableACME = cfg.nginx.enableACME;
177− forceSSL = cfg.nginx.forceSSL;
152+ "${user}.${config.networking.hostName}" = mkMerge [ cfg.nginx {
153+ # don't allow to override root, as it will almost certainly break piwik
154+ root = mkForce "${pkgs.piwik}/share";
155+
156+ # allow to override SSL settings if necessary, i.e. when using another method than ACME
157+ # but enable them by default, as sensitive login and piwik data should not be transmitted in clear text.
158+ addSSL = mkDefault true;
159+ forceSSL = mkDefault true;
160+ enableACME = mkDefault true;
178161
179162 locations."/" = {
180163 index = "index.php";
@@ -208,7 +191,7 @@ in {
208191 locations."= /piwik.js".extraConfig = ''
209192 expires 1M;
210193 '';
211− };
194+ }];
212195 };
213196 };
214197