Building a NixOS configuration from a Nix expression is already possible, but the way the user should do it is non-obvious, hacky and error prone. (See 'Technical details')
I suggest we define a top level function in NixPkgs called nixosConfig
.
As this is relevant to the overall architecture, I would like to know the opinion and advice of @edolstra and @nbp
Note that /pkgs
currently only imports /nixos
at https://github.com/NixOS/nixpkgs/blob/69698ec11cc0619d84b14764fa9e708fe7e7223c/pkgs/desktops/gnome-3/installer.nix#L6
The user is currently faced with the following choices:
import <nixpkgs/nixos>
or import (pkgs.path + "/nixos")
/nixos
or nixos/lib/eval-config.nix
system
argumentpkgs
argumentI suggest we define a function pkgs.nixosConfig
that is a small wrapper around nixos/lib/eval-config.nix
. Its responsibility is to
pkgs
into the new NixOS configurationeval-config.nix
, like the system
parameter (builtins.currentSystem
)The following definition works for my application in an overlay, but can probably be improved.
nixosConfig = { modules, system ? super.system, baseModules ? null }:
import (super.path + "/nixos/lib/eval-config.nix") ({
inherit system modules;
pkgs = self;
} // (if baseModules == null then {} else { inherit baseModules; }));
I'll make a PR if you think this is a good idea.
@williammpratt, That was a little unexpected, but thank you for your feedback.
I am not just saying this to defend my actions, but to point out a minor flaw in the process here. You've pointed out the need for documentation. I will also check the RFCs (and issue tracker) to help improve the community processes' documentation and reduce this kind of friction for maintainers and future contributors.
I have blocked williammpratt, who appears to be the latest incarnation of a user we've blocked several times before for making abusive comments in NixOS repositories.
@roberth Please don't be discouraged by williammpratt, who doesn't speak for any NixOS contributors.
Personally I would love to see more "special" functions like eval-config.nix
exported via pkgs
or lib
. I end up importing them via <nixpkgs/...>
quite a bit in my own configs, and that has the problem of being tied to NIX_PATH
when I'm trying to move everything to a project-wide "pinned" Nixpkgs.
What a shame. Thank you Eelco. I will polish and document the thing and open a PR tomorrow.
@roberth Thanks for opening this issue. This is definitely a great idea!
I can foresee such expression to have multiple outputs such as a system-output / vm-output / ...
@nbp, I've made a pull request, https://github.com/NixOS/nixpkgs/pull/32422
Most helpful comment
I have blocked williammpratt, who appears to be the latest incarnation of a user we've blocked several times before for making abusive comments in NixOS repositories.
@roberth Please don't be discouraged by williammpratt, who doesn't speak for any NixOS contributors.