Skip to content

php.packages: Make packages overridable#107044

Merged
jtojnar merged 2 commits into
NixOS:masterfrom
jtojnar:overridable-php-packages
Dec 22, 2020
Merged

php.packages: Make packages overridable#107044
jtojnar merged 2 commits into
NixOS:masterfrom
jtojnar:overridable-php-packages

Conversation

@jtojnar

@jtojnar jtojnar commented Dec 16, 2020

Copy link
Copy Markdown
Member
Motivation for this change

This will allow patching extensions without having to manually having to patch all occurrences in the dependency tree (like I did in fossar/selfoss@cb22131), see clean-up PR depending on this PR.

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 nixpkgs-review --run "nixpkgs-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.

This will make it easier to make overridable.

Had to rename `packages` attribute to `tools` in `php-packages.nix` because `packages` is shadowed by `makeScope`.
@jtojnar jtojnar requested a review from a team December 16, 2020 17:30
jtojnar added a commit to fossar/selfoss that referenced this pull request Dec 16, 2020
Seeing the state of various methods to install dependencies to PHP
(pyenv, nvm and phpenv and custom PHP tarballs on Travis,
Docker and who knows what on GitHub actions), I have decided to
switch to Nix for installing all dependencies.

Unfortunately, Nixpkgs repository does not contain old PHP versions
but it is trivial with Nix to build them ourselves. We will be able to
use Cachix to avoid rebuilding them over and over again.

This is only a first step, the actual switch to Nix on CI will come later.

Also the Nixpkgs PHP infrastructure does not support overriding nicely,
I opened NixOS/nixpkgs#107044 to address that.
This will allow patching extensions without having to manually having to patch all occurrences in the dependency tree.
@jtojnar jtojnar force-pushed the overridable-php-packages branch from 2fe6351 to b2594c7 Compare December 16, 2020 17:32
@ofborg ofborg Bot added 8.has: documentation This PR adds or changes documentation 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. 10.rebuild-linux: 0 This PR does not cause any packages to rebuild on Linux. labels Dec 16, 2020
@aanderse

Copy link
Copy Markdown
Member

Unfortunately, Nixpkgs repository does not contain old PHP versions
but it is trivial with Nix to build them ourselves. We will be able to
use Cachix to avoid rebuilding them over and over again.

It sounds like you're going to publish this for broad use? I have a few internal applications I need to support still running 5.6 and this would be really nice... Would you mind sending me a ping when this is available?

@jtojnar

jtojnar commented Dec 17, 2020

Copy link
Copy Markdown
Member Author

@aanderse It is already in the selfoss repository (see the links in the OP). Though I hope to remove PHP 5.6 as soon as I manage to release selfoss 2.19, which is the last version I promised PHP 5 support for.

@aanderse

Copy link
Copy Markdown
Member

@jtojnar there isn't a binary cache yet, though, is there? Thanks! Awesome work.

@jtojnar

jtojnar commented Dec 17, 2020

Copy link
Copy Markdown
Member Author

@aanderse Yes, there is. Turns out Cachix is amazing: cachix use fossar

@FRidh

FRidh commented Dec 19, 2020

Copy link
Copy Markdown
Member

Related PR for emacs #107152. We really need to converge on a single interface here (partially NixOS/rfcs#67).

, version
, sha256
, extraPatches ? []
, packageOverrides ? (final: prev: {})

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Python nowadays also supports overrideScope' but it has not been documented yet. My intention is to deprecate this packageOverrides because it does not compose.

@jtojnar jtojnar Dec 19, 2020

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does actually compose:

let
  pkgs = import ./. { };

  idOverlay = final: prev: {};
  composeOverlays =
    old:
    new:

    final:
    prev:

    let
      oldInstantiated = old final prev;
      prevWithOld = prev // oldInstantiated;
    in
      oldInstantiated // new final prevWithOld;

  oldPhp = pkgs.php.override {
    packageOverrides = final: prev: {
      extensions = prev.extensions // {
        mysqlnd = prev.extensions.mysqlnd.overrideAttrs (attrs: {
          foo = "foo";
        });
      };
    };
  };
in
  oldPhp.override (oldOverrides: {
    packageOverrides = composeOverlays (oldOverrides.packageOverrides or idOverlay) (final: prev: {
      extensions = prev.extensions // {
        mysqlnd = prev.extensions.mysqlnd.overrideAttrs (attrs: {
          foo = prev.extensions.mysqlnd.foo or "" + "bar";
        });
      };
    });
  })

But yeah, it is a mouthful.

@FRidh

FRidh commented Dec 19, 2020

Copy link
Copy Markdown
Member

Wrote a draft for an RFC on this topic NixOS/rfcs#83.

@jtojnar jtojnar merged commit 3dfcc7e into NixOS:master Dec 22, 2020
@jtojnar jtojnar deleted the overridable-php-packages branch December 22, 2020 21:39
@jtojnar

jtojnar commented Dec 22, 2020

Copy link
Copy Markdown
Member Author

Merging as is for now, will update it to match the RFC once we figure it out.

@etu etu left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I approve of these changes since it doesn't make sense to wait around for the RFC process to happen. This brings us benefits right now, and we can match the RFC API later on.

@jtojnar

jtojnar commented Jan 9, 2021

Copy link
Copy Markdown
Member Author

@aanderse I have extracted the PHP expressions into a separate repository: https://github.com/fossar/nix-phps

@aanderse

aanderse commented Jan 9, 2021

Copy link
Copy Markdown
Member

@jtojnar thank you very much! That is great! ✨

@nixos-discourse

Copy link
Copy Markdown

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/php-extensions-not-building-against-php-with-overridden-attributes/11451/2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

8.has: documentation This PR adds or changes documentation 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. 10.rebuild-linux: 0 This PR does not cause any packages to rebuild on Linux.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants