Hello there,
I’m currently having the following problem: I have a bunch of nix
files (which contain attrsets
) that I’d like to store some settings in, some of these settings are read out and used by a module I’ve written, but I’d like to add an extraConfig
section, that will contain some nixos configuration code, e.g.:
{
a = {
foo = "...";
bar = ''
...
'';
};
b = {
foo = [];
baz = [];
};
extraConfig = {
networking.extraHosts = ''
1.2.3.4 some-host-name
192.168.1.1 some-host-name
'';
};
}
What currently works is that I can access sections a
and b
in my module code and assign their content to the respective NixOS configuration keys inside of my module. I’m using import
to do this on the separate sections with a let
statement like this:
...
someNixConfigKey = let
a = builtins.concatLists (map .. (map (x: (import x).a) [ "/path/to/file0.nix" "/path/to/file1.nix"]));
in a;
...
Now what I’d like to do with the extraConfig
section is basically to go over all of my nix
files and simply load the extraConfig
section into my configuration. I can access it using import
, however from what I’ve gathered so far, import
simply returns the content of the files (or sections of files), so simply writing an import
statement into my module won’t work. The next thing I wanted to try out was to use the imports
variable, but it seems to only store file paths, not configuration snippets…
My question is: is there a way for me to grab part of an attrset
from a file and simply use it as part of my configuration
?
(I know that I could basically just define all the options in extraConfig
as key/value pairs in my module and load them this way - maybe this would even be the cleaner approach - but I still kind of wonder if this is possible in nix
)
Many thanks in advance!