NixOS defined by a flake, I want to use a specific version for two packages

git repo: GitHub - michaelhesemann/nixos

self explanatory; I want to use the ‘dotlan’ host with the php and mysql packages at version 5.6.36 and 8.0.34 respectively. I think overlays are what to do here, but the build fails with:

nixos-rebuild --flake .#dotlan test --impure
building the system configuration...
error: builder for '/nix/store/zn72bfr25x8nvbk1bb1bzkryzbbn68rd-php-8.2.16.drv' failed with exit code 1;
       last 10 log lines:
       > The text leading up to this was:
       > --------------------------
       > |diff -ru a/sapi/apache2handler/config.m4 b/sapi/apache2handler/config.m4
       > |--- a/sapi/apache2handler/config.m4       2018-11-07 15:35:23.000000000 +0000
       > |+++ b/sapi/apache2handler/config.m4       2018-11-27 00:32:28.000000000 +0000
       > --------------------------
       > File to patch:
       > Skip this patch? [y]
       > Skipping patch.
       > 1 out of 1 hunk ignored
       For full logs, run 'nix log /nix/store/zn72bfr25x8nvbk1bb1bzkryzbbn68rd-php-8.2.16.drv'.
error: 1 dependencies of derivation '/nix/store/qra0n0dl6hzx4d339x5zsc0459ndg63h-php-with-extensions-8.2.16.drv' failed to build
error: 1 dependencies of derivation '/nix/store/b3lzjj1315hw0nc6qwy0ai0v5yks6cmy-system-path.drv' failed to build
error: 1 dependencies of derivation '/nix/store/9x60ayx623z01fld7fcka1r253ghlln2-nixos-system-nixos-23.11.20240309.b94a968.drv' failed to build

Any ideas? thanks in advance

full log:

nix log /nix/store/zn72bfr25x8nvbk1bb1bzkryzbbn68rd-php-8.2.16.drv
warning: The interpretation of store paths arguments ending in `.drv` recently changed. If this command is now failing try again with '/nix/store/zn72bfr25x8nvbk1bb1bzkryzbbn68rd-php-8.2.16.drv^*'
@nix { "action": "setPhase", "phase": "unpackPhase" }
Running phase: unpackPhase
unpacking source archive /nix/store/w2qnz6b80gd1p431cmj5svx9m22vyky2-5a8650469a9f8a1958ff9373bd27fb8e54c4365d.tar.gz
source root is nixpkgs-5a8650469a9f8a1958ff9373bd27fb8e54c4365d
setting SOURCE_DATE_EPOCH to timestamp 1688072080 of file nixpkgs-5a8650469a9f8a1958ff9373bd27fb8e54c4365d/pkgs/top-level/wine-packages.nix
@nix { "action": "setPhase", "phase": "patchPhase" }
Running phase: patchPhase
applying patch /nix/store/r2bw91ma55jqnlv51iwck17f05i1c76x-fix-paths-php7.patch
can't find file to patch at input line 4
Perhaps you used the wrong -p or --strip option?
The text leading up to this was:
--------------------------
|diff -ru a/ext/gettext/config.m4 b/ext/gettext/config.m4
|--- a/ext/gettext/config.m4    2018-11-07 15:35:26.000000000 +0000
|+++ b/ext/gettext/config.m4    2018-11-27 00:33:07.000000000 +0000
--------------------------
File to patch:
Skip this patch? [y]
Skipping patch.
1 out of 1 hunk ignored
can't find file to patch at input line 18
Perhaps you used the wrong -p or --strip option?
The text leading up to this was:
--------------------------
|diff -ru a/sapi/apache2handler/config.m4 b/sapi/apache2handler/config.m4
|--- a/sapi/apache2handler/config.m4    2018-11-07 15:35:23.000000000 +0000
|+++ b/sapi/apache2handler/config.m4    2018-11-27 00:32:28.000000000 +0000
--------------------------
File to patch:
Skip this patch? [y]
Skipping patch.
1 out of 1 hunk ignored

PHP in Nixpkgs applies some patches so your overridden src needs to be compatible with that or the patch will fail to apply as you see:

Also the php package expects source of PHP project such as

you are passing it source for Nixpkgs:

Also note that just overriding the src and patches likely will not be sufficient. For example, we have a whole project dedicated just for providing such overlays for PHP, and it requires many other changes of both php itself and related packages.

You could try to obtain the package from an older snapshot of Nixpkgs (as found by something like Searching and installing old versions of Nix packages or Nixhub.io | Search Historical Versions of Nix Packages) but that might introduce breakages (e.g. loading mod_php from ancient Nixpkgs might have incompatible ABI with Apache from current Nixpkgs) and security issues (Nixpkgs snapshots will obviously not receive any updates).

thank you for your reply. I will try to use a different channel first.
I unfortunately need these old versions, as the software is specifically written for that.
I’ll give an update when I’m home

ok, am home now and tried some stuff, current version is updated, but fails with:

nixos-rebuild --flake .#dotlan test
building the system configuration...
error:
       … while calling the 'head' builtin

         at /nix/store/x06xw73q4lpsa83amgnyy1fmaark3pg3-source/lib/attrsets.nix:922:11:

          921|         || pred here (elemAt values 1) (head values) then
          922|           head values
             |           ^
          923|         else

       … while evaluating the attribute 'value'

         at /nix/store/x06xw73q4lpsa83amgnyy1fmaark3pg3-source/lib/modules.nix:807:9:

          806|     in warnDeprecation opt //
          807|       { value = builtins.addErrorContext "while evaluating the option `${showOption loc}':" value;
             |         ^
          808|         inherit (res.defsFinal') highestPrio;

       (stack trace truncated; use '--show-trace' to show the full trace)

       error: attribute 'currentSystem' missing

       at /nix/store/99c3lqp2kym9hb5fjz50m4kznl131vvn-php-5-6-36/pkgs/top-level/impure.nix:87:34:

           86|   localSystem = (if args ? localSystem then {}
           87|                  else { system = builtins.currentSystem; }) // localSystem;
             |                                  ^
           88| })

Flakes use pure evaluation mode, in which builtins.currectSystem is not available. You need to specify the system explicitly import <nixpkgs> { system = "…"; } (where <nixpkgs> is the fetchgit call in your case).

1 Like

EDIT:
this works:

{ config, pkgs, nixpkgs, ... }:

let
  pkgs = import (builtins.fetchGit {
    name = "php-5-6-36";
    url = "https://github.com/NixOS/nixpkgs/";
    ref = "refs/heads/nixpkgs-unstable";
    rev = "a5c9c6373aa35597cd5a17bc5c013ed0ca462cf0";
  }) { system = "x86_64-linux"; };

  php = pkgs.php56;
in

{
  environment.systemPackages = with pkgs; [
    php
  ];
}