How to add a file to builddir NixOS

Hello, I’m very new to NixOS so forgive me if I use wrong terminology.
So, basically I’m trying to build Dwm using my custom config, which I am able to do with this:

...
(dwm.overrideAttrs (oldAttrs: rec {
      patches = [ ... ];
      configFile = writeText "config.h" (builtins.readFile ./dwm-config.h);
      postPatch = "${oldAttrs.postPatch}\n cp ${configFile} config.def.h";
    }))

However, my configfile depends on a header that I created called “colors.h”.
How do I add that file to the “builddir” so it is accessible to the compiler?
Thank you in advance.

Options:

  1. replicate the current solutions
(dwm.overrideAttrs (oldAttrs: rec {
      patches = [ ... ];
      configFile = writeText "config.h" (builtins.readFile ./dwm-config.h);
      colorsH =  writeText "colors.h" (builtins.readFile ./colors.h);
      postPatch = "${oldAttrs.postPatch}\n cp ${configFile} config.def.h \n cp ${colorsH} color.h";
    }))
  1. passAsFile
(dwm.overrideAttrs (oldAttrs: rec {
      patches = [ ... ];
      configFile = writeText "config.h" (builtins.readFile ./dwm-config.h);
      colorsH = builtins.readFile ./colors.h;
      passAsFile = (oldAttrs.passAsFiles or []) ++ ["colorsH"];
      postPatch = "${oldAttrs.postPatch}\n cp ${configFile} config.def.h; cp $colorsH color.h";
    }))
  1. If i’m not wrong, when you pass a path is it does what writeText does for you.
(dwm.overrideAttrs (oldAttrs: rec {
      patches = [ ... ];
      configFile = writeText "config.h" (builtins.readFile ./dwm-config.h);
      postPatch = ''
        ${oldAttrs.postPatch or ""}
        cp ${configFile} config.def.h
        cp ${./colors.h} color.h
      '';
    }))

edit: typos

Can confirm solution 1 works, only you wrote “color.h” intstead of “colors.h”. Thank you for your time!

1 Like