Create text file in a package folder



I’m new to NixOS. I have installed fail2ban on my NixOS system.

How can I create a new etc/fail2ban/filter.d/<my-filter-name> text file with my own content within my configuration.nix?

Bonus question: where is that documented?


Nix packages are supposed to be configured [1] to pick their
configuration data from /etc, not the package directory, which is
immutable anyway.

You can use
environment.etc."fail2ban/filter.d/<my-filter-name>".source in your
configuration.nix to create the file in /etc:

[1]: Sometimes, the packagers miss this and the package only tries to
find the configuration in ${pkg}/etc. This is a bug and needs to be


You mean .text instead of .source right?


Yeah, you can use .text if you want to embed it directly into you configuration.nix