Could there ever be some kind of config.d or imports globbing, for easier programmatic editing?

Right now, there doesn’t seem to be a nice way to add or configure a system service programmatically, other than parsing the config file, making the changes, and exporting, which is generally not ideal.

It would be nice to have a standard config.d directory, that one could expect on any NixOS install, contents of which would be imported to config.nix.

That way, configuration could be fully modular, neatly programmatically installable, and potentially, could allow replacing the nix-env installation with a new command, that just adds a home-manager config file to a specific folder, which declares the package should be there.

1 Like

It would be nice to have a standard config.d directory, that one could expect on any NixOS install, contents of which would be imported to config.nix.

This is possible to implement in pure Nix using builtins.readDir. Importing from readDir is banned in Nixpkgs so its hard to find examples, but you are free to do this for your own config.

2 Likes

You can also e.g. import from JSON to nix, as there are lots of tools that can edit JSON.

Importing from readDir is fine in Nixpkgs, it doesn’t use IFD. The implementation of RFC 140 needs that too :slight_smile:

2 Likes

Not all NixOS installs contain their own configuration expressions.
For example, you can deploy it from a different machine using nixos-rebuild --target-host, or with flakes, it resides wherever the flake is.
Of course you can equally well have such a convention for flakes and such.

1 Like

You can do this with Haumea (see Asterix sybol on an import path in nix language? - #4 by wamserma) but unless you are using flakes this would be impure :scream:

1 Like