How to put a few files in a folder?

I’m trying to create an Nginx configuration that templates an index.html using Nix and then put it along with some other files like CSS files into a folder and set it’s location to root in Nginx location block.

I know I can create a file by using one of the trivial builders like writeText to create a single file, or writeTextDir to create a single file in a folder. But how do I do multiple files in a folder, out of which one is generated by a function, and others might just be static files I want to add?

I’ve been doing a bunch of googling and I can’t find the right way to query for this.


If you have a directory somewhere, you can refer to its path and it will automatically be added to the nix store.

I’m not super familiar with nginx, but I think it would be something like this:

Say you have the files in some directory ./my-site then you do

services.nginx.virtualHosts.<name>.locations.<name>.root = ./my-site;

Right, but what if under ./my-site where I have for example main.css and main.js I also want to add an index.html that I’ve templated in nix through a function?

Ah, in that case, you can use buildEnv

1 Like

Looks like exactly what I need. Thank you!