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

php.packages: Make packages overridable #107044

Merged
merged 2 commits into from Dec 22, 2020

Conversation

jtojnar
Copy link
Contributor

@jtojnar jtojnar commented Dec 16, 2020

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.
@aanderse
Copy link
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
Copy link
Contributor Author

jtojnar commented Dec 17, 2020

@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
Member

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

@jtojnar
Copy link
Contributor Author

jtojnar commented Dec 17, 2020

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

@FRidh
Copy link
Member

FRidh commented Dec 19, 2020

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

@@ -13,6 +13,7 @@ let
, version
, sha256
, extraPatches ? []
, packageOverrides ? (final: prev: {})
Copy link
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.

Copy link
Contributor Author

@jtojnar jtojnar Dec 19, 2020

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
Copy link
Member

FRidh commented Dec 19, 2020

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
Copy link
Contributor Author

jtojnar commented Dec 22, 2020

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

Copy link
Contributor

@etu etu left a comment

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
Copy link
Contributor Author

jtojnar commented Jan 9, 2021

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

@aanderse
Copy link
Member

aanderse commented Jan 9, 2021

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

@nixos-discourse
Copy link

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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants