18

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...

2 Answers2

20

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";
  };
};
14

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";
};