Why nix use nix.conf as configuration, not a nix file like config.nix?

Why nix use nix.conf as configuration, not a nix file like config.nix? Because nix is the compiler of nix lang, use nix lang as the configuration language of nix looks more reasonable and nature, right? Is there anything I haven’t known to stop nix using nix lang as configuration?

I notice /etc/nixos/configuration.nix generate /etc/nix/nix.conf from nix.*. Can we generate .config/nix.conf from a nix file like /etc/nixos/configuration.nix by standalone nix?

I’m not sure this is the right answer, but I’d say this is because nix files should not be thought of as configuration files, but as programs that generate configuration files (among other things). So, for Nix itself, just like any other program, it makes sense to have configuration files written in a configuration-like format (not nix), and have them generated with Nix.

For user-side configuration files, I’d recommend using home-manager, which, I believe, is capable of generating nix configuration files. You can use it as a nixos module if you want to handle that in a system configuration file such as /etc/nixos/configuration.nix, but you can also use it as a standalone.

nix.conf configures the nix evaluator, so you either run into a circular dependency problem, or only let a subset of nix to be used

1 Like

Can we use a default nix evaluator to evaluate config.nix, then use the configured nix evaluator to do other things?

But then we’re running into what @viperML described - you’re locking the user into a particular subset and/or configuration of nix for specifically config.nix and given the options nix takes, there wouldn’t be much benefit to it.

Also nix.conf is emitted by a NixOS module so if that were to be replaced with config.nix we’d either need to have a function in nixpkgs which can take a nix attrset and emit nix based on it, or we’d need some kind of builtin to stringify nix expressions. Both of which are less than ideal

1 Like