19

What is the NixOS-way to put a configuration file in /etc?

E.g. I want to drop /etc/nanorc. I found some forum entries talking about programming it into /etc/nixos/configuration.nix, but could not find any documentation about that...

0

2 Answers 2

22

To create a file in /etc on NixOS, use environment.etc in configuration.nix. Here's an example:

environment.etc = {
  # Creates /etc/nanorc
  nanorc = {
    text = ''
      whatever you want to put in the file goes here.
    '';

    # The UNIX file mode bits
    mode = "0440";
  };
};
15

Additionally, you can also add a file from a path with:

environment.etc = {
  somerc.source = /etc/somerc;
};

Or a directory:

environment.etc = {
  aDir.source = ./aDir;
};

Or a package path:

environment.etc = {
  "X11/xorg.conf.d/90-super.conf".source = "${pkgs.displayfix}/share/displayfix/data/90-super.conf";
};
2
  • 1
    Doesn't your first example /etc/somerc point to itself? Commented Oct 24, 2021 at 13:14
  • I recall I was adding an etc file of my local machine to another machine with NixOps. What do you suggest? Should I just puth a /path/to/file instead? Commented Oct 24, 2021 at 22:31

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .