Apply patch to texlive package

Is there a way to apply an overlay/patch to one of the latex packages? I tried the following without success:

        pkgs = import nixpkgs {
          inherit system;
          overlays = [
            (final: prev: {
              texlive.tufte-latex = prev.texlive.tufte-latex.overrideAttrs (old: {
                patches = (old.patches or [ ]) ++ [ ./texmf/tex/latex/tufte.nofonts.patch ];
        tex = pkgs.texlive.combine {
          inherit (pkgs.texlive) latex-bin latexmk scheme-basic tufte-latex;

Here is the complete flake.nix

Can you try changing your overlay to something like this:

final: prev: {
  texlive = prev.texlive // {
    tufte-latex = prev.texlive.tufte-latex.overrideAttrs (old: {
      patches = (old.patches or [ ]) ++ [ ./texmf/tex/latex/tufte.nofonts.patch ];

as described in here.

Okay, so texlive is not a package, but an attribute set. If I make the change, it seems the tufte-latex package does not have overrideAttrs.

  error: attribute 'overrideAttrs' missing

       at /nix/store/fmcsk2c38brvpnkbgyx5d6ar3adwhvs0-source/flake.nix:15:31:

       14|               texlive = prev.texlive // {
       15|                 tufte-latex = prev.texlive.tufte-latex.overrideAttrs (old: {
         |                               ^
       16|                   patches = (old.patches or [ ]) ++ [ ./texmf/tex/latex/tufte.nofonts.patch ];

You can learn about the types of things and attributes of sets in Nix repl:

❯ nix repl '<nixpkgs>'
Welcome to Nix 2.5.1. Type :? for help.

Loading '<nixpkgs>'...
Added 15439 variables.

Then type this

nix-repl> texlive.tufte-latex.<TAB>

Hitting tab will try to autocomplete the attribute name, so in this case there is only one named pkgs:

nix-repl> texlive.tufte-latex.pkgs
[ «derivation /nix/store/1zvkpll6203v4hk46a3l1x8s73ncxis2-texlive-tufte-latex-3.5.2.drv» «derivation /nix/store/8ckanivc3smvcph0n2kr8h03aq81n237-texlive-tufte-latex.doc-3.5.2.drv» «derivation /nix/store/iiq94f5schai1k7clmsb8klcvkrwl71b-texlive-changepage-1.0c.drv» «derivation /nix/store/5cdym6cgagr26m1h1m581af6b5gkbrcf-texlive-changepage.doc-1.0c.drv» «derivation /nix/store/c1ndxw2f4fggl6cxkvy4xfdyk587lscg-texlive-changepage.source-1.0c.drv» «derivation /nix/store/q9ksq126714lfmakvwqs639508ywbw77-texlive-ifmtarg-1.2b.drv» «derivation /nix/store/bgmksgyc1ij8irymykddz9zxnxkrlz37-texlive-ifmtarg.doc-1.2b.drv» «derivation /nix/store/i7024avzspimg2g7dwzi7bswi9bnyj6w-texlive-ifmtarg.source-1.2b.drv» «derivation /nix/store/4xccfnppab6j21qr5hkf02nfkbqckc8l-texlive-paralist-2.7.drv» «derivation /nix/store/pz405vd72gig4jqhvjkzxpdypw00ssmh-texlive-paralist.doc-2.7.drv» «derivation /nix/store/5znflxwwqnk2njcmjqv0bdyd9pbmygcq-texlive-paralist.source-2.7.drv» «derivation /nix/store/z6wjii8qr4gb1613wv2271lq1bcgy33b-texlive-placeins-2.2.drv» «derivation /nix/store/mljyswx4wfw9ajxqcr09xqj044dxaak4-texlive-placeins.doc-2.2.drv» «derivation /nix/store/xkyw7ld88wbidwijwciw0fan3d5hhdnh-texlive-sauerj-15878.drv» «derivation /nix/store/5mwnhk0r8jf2b6mf1xn0yqdq1vc7mzmk-texlive-sauerj.doc-15878.drv» «derivation /nix/store/i9jvdvxrzkw56fi86c5av18crzg0fbwi-texlive-sauerj.source-15878.drv» «derivation /nix/store/3w52hgsacagb2hh0k5mhkwxpgylxlfjm-texlive-xifthen-1.4.0.drv» «derivation /nix/store/wqc40yj1vhji84n2rbkzlwx0mppg1979-texlive-xifthen.doc-1.4.0.drv» ]

It is a list of derivations, so maybe you can map over them and override the needed:

  isTufteLatex = drv: == "texlive-tufte-latex" && drv.tlType == "run";
  overrideTufteLatex = drv: drv.overrideAttrs(oldAttrs: {
map (drv: if isTufteLatex drv then overrideTufteLatex drv else drv) texlive.tufte-latex.pkgs

But this looks like an ugly hack and probably is not the solution you are looking for. I don’t know how to help you further.

Thank you! I was not aware how to get the type. This already helps me for other tasks.