Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nixos/phpfpm: fix apply global phpOptions #72767

Merged
merged 1 commit into from Nov 11, 2019
Merged

Conversation

@Izorkin
Copy link
Contributor

Izorkin commented Nov 4, 2019

Motivation for this change

Fixed apply of parameter config.services.phpfpm.phpOptions

Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS linux)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nix-review --run "nix-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Determined the impact on package closure size (by running nix path-info -S before and after)
  • Ensured that relevant documentation is up to date
  • Fits CONTRIBUTING.md.
Notify maintainers

cc @

@Izorkin

This comment has been minimized.

Copy link
Contributor Author

Izorkin commented Nov 4, 2019

Copy link
Contributor

aanderse left a comment

Why are we renaming? I like the names the way they are. If the documentation isn't clear enough can we please just update the documentation instead?

nixos/modules/services/web-servers/phpfpm/default.nix Outdated Show resolved Hide resolved
@Izorkin

This comment has been minimized.

Copy link
Contributor Author

Izorkin commented Nov 4, 2019

The name of the option immediately shows that it applies to all pools.
Before:

  services.phpfpm = {
    phpOptions = ''
      date.timezone = "Europe/Moscow"
      error_log = /var/log/phpfpm.log
      session.save_handler = memcached
      session.save_path = "127.0.0.1:11211"
    '';
    settings = {
      "rlimit_core" = "unlimited";
      "rlimit_files" = "131072";
    };
    pools = {
      "site-01" = {
        phpPackage = pkgs.php;
        user = "wwwrun";
        group = "wwwrun";
        phpOptions = ''
          error_log = /var/log/phpfpm-site-01.log
        '';
        settings = {
          "listen.owner" = "${cfgUser01}";
          "listen.group" = "${cfgGroup01}";
          "listen.mode" = "0600";
        };
      };
    };
  };

After:

  services.phpfpm = {
    globalPhpOptions = ''
      date.timezone = "Europe/Moscow"
      error_log = /var/log/phpfpm.log
      session.save_handler = memcached
      session.save_path = "127.0.0.1:11211"
    '';
    globalSettings = {
      "rlimit_core" = "unlimited";
      "rlimit_files" = "131072";
    };
    pools = {
      "site-01" = {
        phpPackage = pkgs.php;
        user = "wwwrun";
        group = "wwwrun";
        phpOptions = ''
          error_log = /var/log/phpfpm-site-01.log
        '';
        settings = {
          "listen.owner" = "${cfgUser01}";
          "listen.group" = "${cfgGroup01}";
          "listen.mode" = "0600";
        };
      };
    };
  };

And here it is easy to deteсt which parameters belong to global:

  fpmCfgFile = pool: poolOpts: pkgs.writeText "phpfpm-${pool}.conf" ''
    [global]
    ${concatStringsSep "\n" (mapAttrsToList (n: v: "${n} = ${toStr v}") cfg.globalSettings)}
    ${optionalString (cfg.extraConfig != null) cfg.extraConfig}

    [${pool}]
    ${concatStringsSep "\n" (mapAttrsToList (n: v: "${n} = ${toStr v}") poolOpts.settings)}
    ${concatStringsSep "\n" (mapAttrsToList (n: v: "env[${n}] = ${toStr v}") poolOpts.phpEnv)}
    ${optionalString (poolOpts.extraConfig != null) poolOpts.extraConfig}
  '';

  phpIni = poolOpts: pkgs.runCommand "php.ini" {
    inherit (poolOpts) phpPackage phpOptions;
    preferLocalBuild = true;
    nixDefaults = ''
      sendmail_path = "/run/wrappers/bin/sendmail -t -i"
    '';
    globalPhpOptions = ''
      ${cfg.globalPhpOptions}
    '';
    passAsFile = [ "nixDefaults" "globalPhpOptions" "phpOptions" ];
  } ''
    cat ${poolOpts.phpPackage}/etc/php.ini $nixDefaultsPath $globalPhpOptionsPath $phpOptionsPath > $out
  '';


@Izorkin Izorkin force-pushed the Izorkin:phpfpm-fix branch from 209388f to 2d41713 Nov 4, 2019
Copy link
Contributor

etu left a comment

The same as @aanderse.

I don't see the point in this rename and I think we shouldn't do it.

Maybe it's possible to do if we do a big refactor or something at the same time so we actually gain some more benefits from the module. But as far as I can see from reading the diff here... we don't really change anything that much really...

@Izorkin Izorkin force-pushed the Izorkin:phpfpm-fix branch from 2d41713 to 20391c8 Nov 5, 2019
@Izorkin Izorkin changed the title nixos/phpfpm: fix and rename options nixos/phpfpm: fix apply global phpOptions Nov 5, 2019
@Izorkin

This comment has been minimized.

Copy link
Contributor Author

Izorkin commented Nov 5, 2019

Ok. Updated PR.

Copy link
Contributor

aanderse left a comment

@Izorkin please try this instead:

~/nixpkgs> git diff
diff --git a/nixos/modules/services/web-servers/phpfpm/default.nix b/nixos/modules/services/web-servers/phpfpm/default.nix
index 4ab7e3f0c0a..f33a740abeb 100644
--- a/nixos/modules/services/web-servers/phpfpm/default.nix
+++ b/nixos/modules/services/web-servers/phpfpm/default.nix
@@ -69,8 +69,6 @@ let
 
         phpOptions = mkOption {
           type = types.lines;
-          default = cfg.phpOptions;
-          defaultText = "config.services.phpfpm.phpOptions";
           description = ''
             "Options appended to the PHP configuration file <filename>php.ini</filename> used for this PHP-FPM pool."
           '';
@@ -137,6 +135,7 @@ let
       config = {
         socket = if poolOpts.listen == "" then "${runtimeDir}/${name}.sock" else poolOpts.listen;
         group = mkDefault poolOpts.user;
+        phpOptions = mkBefore cfg.phpOptions;
 
         settings = mapAttrs (name: mkDefault){
           listen = poolOpts.socket;

This would allow you to customize much further, more flexibility.

services.phpfpm.phpOptions = ''
  ; changes to apply to every php.ini file
'';
services.phpfpm.pools.pool1.phpOptions = ''
  ; changes which will be appended onto services.phpfpm.phpOptions for this pool
'';
services.phpfpm.pools.pool2.phpOptions = mkForce ''
  ; changes which will overwrite services.phpfpm.phpOptions for this pool
'';
@Izorkin Izorkin force-pushed the Izorkin:phpfpm-fix branch from 20391c8 to 776c3cf Nov 5, 2019
@Izorkin

This comment has been minimized.

Copy link
Contributor Author

Izorkin commented Nov 5, 2019

Thanks for this variant. Updated PR.

@Izorkin

This comment has been minimized.

Copy link
Contributor Author

Izorkin commented Nov 5, 2019

This code:

        settings = mapAttrs (name: mkDefault){
          listen = poolOpts.socket;
          user = poolOpts.user;
          group = poolOpts.group;

generates a file in this form

[test-01]
group = wwwrun
listen = 9000
listen.allowed_clients = 127.0.0.1, 129.0.0.223, 129.0.0.48
listen.backlog = 65536
listen.group = wwwrun
listen.mode = 0660
listen.owner = wwwrun
pm = dynamic
pm.max_children = 20
pm.max_requests = 400
pm.max_spare_servers = 12
pm.min_spare_servers = 2
pm.start_servers = 4
user = wwwrun

How to make lines displayed first:

[test-01]
listen = 9000
user = wwwrun
group = wwwrun
listen = 9000
listen.allowed_clients = 127.0.0.1, 129.0.0.223, 129.0.0.48
listen.backlog = 65536
listen.group = wwwrun
listen.mode = 0660
listen.owner = wwwrun
pm = dynamic
pm.max_children = 20
pm.max_requests = 400
pm.max_spare_servers = 12
pm.min_spare_servers = 2
pm.start_servers = 4
@Izorkin Izorkin force-pushed the Izorkin:phpfpm-fix branch from 776c3cf to 9a27ace Nov 5, 2019
@aanderse aanderse requested a review from Infinisil Nov 5, 2019
@aanderse aanderse requested a review from etu Nov 10, 2019
@Infinisil

This comment has been minimized.

Copy link
Member

Infinisil commented Nov 10, 2019

For future reference: Attribute sets in Nix are sorted alphabetically and there's no nice and easy way to change that for something like this.

@etu
etu approved these changes Nov 11, 2019
@aanderse aanderse merged commit d68d23b into NixOS:master Nov 11, 2019
12 checks passed
12 checks passed
Evaluation Performance Report Evaluator Performance Report
Details
grahamcofborg-eval ^.^!
Details
grahamcofborg-eval-check-meta config.nix: checkMeta = true
Details
grahamcofborg-eval-darwin nix-instantiate --arg nixpkgs { outPath=./.; revCount=999999; shortRev="ofborg"; } ./pkgs/top-level/release.nix -A darwin-tested
Details
grahamcofborg-eval-nixos nix-instantiate --arg nixpkgs { outPath=./.; revCount=999999; shortRev="ofborg"; } ./nixos/release-combined.nix -A tested
Details
grahamcofborg-eval-nixos-manual nix-instantiate --arg nixpkgs { outPath=./.; revCount=999999; shortRev="ofborg"; } ./nixos/release.nix -A manual
Details
grahamcofborg-eval-nixos-options nix-instantiate --arg nixpkgs { outPath=./.; revCount=999999; shortRev="ofborg"; } ./nixos/release.nix -A options
Details
grahamcofborg-eval-nixpkgs-manual nix-instantiate --arg nixpkgs { outPath=./.; revCount=999999; shortRev="ofborg"; } ./pkgs/top-level/release.nix -A manual
Details
grahamcofborg-eval-nixpkgs-tarball nix-instantiate --arg nixpkgs { outPath=./.; revCount=999999; shortRev="ofborg"; } ./pkgs/top-level/release.nix -A tarball
Details
grahamcofborg-eval-nixpkgs-unstable-jobset nix-instantiate --arg nixpkgs { outPath=./.; revCount=999999; shortRev="ofborg"; } ./pkgs/top-level/release.nix -A unstable
Details
grahamcofborg-eval-package-list nix-env -qa --json --file .
Details
grahamcofborg-eval-package-list-no-aliases nix-env -qa --json --file . --arg config { allowAliases = false; }
Details
@Izorkin Izorkin deleted the Izorkin:phpfpm-fix branch Nov 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.