How to modify a package (as a dependency)

I need to alter the guile installation by applying this patch: guile.git - GNU Guile

This altered guile installation needs to be an input for another package derivative.

How do I go about doing that?

Roughly:

the_other.override {
  guile = guile.overrideAttrs (oa: {
    patches = (oa.patches or []) ++ [ your.patch ];
  });
}

We need more info to be more exact

3 Likes

We need more info to be more exact

Right. I am working with this derivation. It almost works but the guile dependency needs the aforementioned patch.

let
  pkgs = import <nixpkgs> {};
  unstable = import <nixos-unstable> {};
in with pkgs;
  stdenv.mkDerivation {
    name = "lokke";
    src = pkgs.fetchgit {
      name = "lokke-repo";
      url = "https://github.com/lokke-org/lokke.git";
      rev = "1e14bd689d3f04d64b4ea4b481307e8d381a71d3";
      sha256 = "0p3z35fiwdsw6mkpbq3fn10g67y6klvvmvyc81xdw1lz55mazwi3";
    };
    nativeBuildInputs = [autoreconfHook];
    buildInputs = [man gettext pcre2 pcre2.dev
                   libunistring libunistring.dev
                   guile_3_0 guile_3_0.dev
                   autoconf automake
                   libtool pkg-config];
    postPatch = ''
      patchShebangs .
      ./setup
    '';
    doCheck = true;
  }

@NobbZ

I came up with this.

let
  pkgs = import <nixpkgs> {};
  patched_guile = pkgs.guile_3_0.overrideAttrs (oa: {
    patches = (oa.patches or []) ++ [
      "
diff --git a/module/ice-9/psyntax.scm b/module/ice-9/psyntax.scm
index 663d927..bd4bd67 100644
--- a/module/ice-9/psyntax.scm
+++ b/module/ice-9/psyntax.scm
@@ -2157,6 +2157,7 @@
                       (lambda ()
                         (gen-syntax src #'(e1 e2 ...) r maps ellipsis? mod))
                     (lambda (e maps) (values (gen-vector e) maps))))
+                 (x (eq? (syntax->datum #'x) #nil) (values '(quote #nil) maps))
                  (() (values '(quote ()) maps))
                  (_ (values `(quote ,e) maps))))))"];
  });
in with pkgs;
  stdenv.mkDerivation {
    name = "lokke";
    src = pkgs.fetchgit {
      name = "lokke-repo";
      url = "https://github.com/lokke-org/lokke.git";
      rev = "1e14bd689d3f04d64b4ea4b481307e8d381a71d3";
      sha256 = "0p3z35fiwdsw6mkpbq3fn10g67y6klvvmvyc81xdw1lz55mazwi3";
    };
    nativeBuildInputs = [autoreconfHook];
    buildInputs = [man gettext pcre2 pcre2.dev
                   libunistring libunistring.dev
                   patched_guile patched_guile.dev
                   autoconf automake
                   libtool pkg-config];
    postPatch = ''
      patchShebangs .
      ./setup
    '';
    doCheck = true;
  }

I think it tries to apply the patch but fails. Have I structured the patch syntax incorrectly?

applying patch diff
/nix/store/z7wz8q1i0j4jmfpn87wpakwma6q0k90n-stdenv-linux/setup: line 990: diff: No such file or directory
builder for '/nix/store/72np0fabx6p6zwi9b1bq0012lq8vjsq8-guile-3.0.7.drv' failed with exit code 1

You can not write the patch “inline” as a string. It needs to be a path pointing to a file.

Using writeText* should work.

1 Like

Thanks. That worked.