Modifying environement.etc.file from multiple imports

I’m currently building a module for an in-house project that will be deployed on NixOS.

I’m having trouble to figure out how I can modify the same “etc” from multiple nix files (I just want them to append sections in the generated text file).

In my default.nix file I import a moduleA.nix (the time being, more module will be added).

In default.nix I set the content of the configuration file this way:

config = mkIf cfg.enable {
  environment.etc."test.conf" = ''
    # My content
  '';
};

In moduleA.nix if I do this:

config = mkIf cfg.moduleA.enable {
  environment.etc."test.conf" = ''
    # My ModuleA content
  '';
};

I get the following error:

error: value is a string while a set was expected, at /home/ely/Code/OpenSource/nixpkgs/lib/modules.nix:304:62

I guess I’m not doing it right ?

What would be the right approach for doing this ?

I thought I could maybe create a list of strings then use builtins.concatStringsSep but I have the feeling that would be very hacky to do it this way (and I’m not sure how I could implement it).

Thanks

You are missing .text attribute, see environment.etc.<name?>.text.

Also, you might want to consider using RFC 0042 to allow more fine-grained merging than line level. Here is a nice example: smartdns: init at 30 by LEXUGE · Pull Request #80931 · NixOS/nixpkgs · GitHub

Oh, my bad, I had the .text attribute I’ve forgot it on my post, sorry about that.

I will check out the RFC and the pull request, thanks for pointing it :slight_smile: