Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nixos-generate-config: enable overriding configuration.nix #66327

Merged

Conversation

basvandijk
Copy link
Member

I'm writing a custom NixOS installation ISO image for installing various machines. The image contains an interactive script that performs an automatic installation. After asking which disk to install to it will partition the disk, format the filesystems, mount them and then it will call nixos-generate-config to generate the initial /etc/nixos/configuration.nix. I would like to automatically set some things in this initial configuration like enabling SSH, setting users.users.root.openssh.authorizedKeys.keyFiles and maybe some more settings. I could of course patch or overwrite /etc/nixos/configuration.nix but that could destroy potentially useful stuff like the $bootLoaderConfig. Overriding it in NixOS would be safer.

Motivation for this change
Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nix-review --run "nix-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Determined the impact on package closure size (by running nix path-info -S before and after)
  • Ensured that relevant documentation is up to date
  • Fits CONTRIBUTING.md.
Notify maintainers

cc @edolstra @grahamc

# compatible, in order to avoid breaking some software such as database
# servers. You should change this only after NixOS release notes say you
# should.
system.stateVersion = "''${\(qw(@release@))}"; # Did you read the comment?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hrm, this is pretty ugly. Can the substitution be done here, and not in a perl escape?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great point. That should be possible I think. I'll fix it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually that seems worse, because then we have two kinds of substitution going on in this file.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well in my original commit there were actually already two substitutions going on. Now it's back to a single substituteAll call as before.

@basvandijk
Copy link
Member Author

@GrahamcOfBorg test nixos-generate-config

@edolstra
Copy link
Member

edolstra commented Aug 8, 2019

Hm, the problem with system.nixos-generate-config.configuration is that it's very tightly coupled with the implementation details of nixos-generate-config. Thus it exposes variable names like $bootLoaderConfig and requires nixos-generate-config to be written in Perl. So the existence of this option would make future changes to nixos-generate-config much harder.

@basvandijk
Copy link
Member Author

So the existence of this option would make future changes to nixos-generate-config much harder.

That's true. I did make system.nixos-generate-config.configuration an internal option so that it doesn't show up in the documentation.

I could add to the option description:

We don't guarantee any backward compatibly. Use at your own risk!

@basvandijk
Copy link
Member Author

@GrahamcOfBorg test nixos-generate-config

@basvandijk basvandijk force-pushed the parameterizable-nixos-generate-config branch from 3c8321c to 810388a Compare August 8, 2019 15:00
@edolstra
Copy link
Member

edolstra commented Aug 8, 2019

@basvandijk Ah, I didn't notice you made it internal. In that case it's fine.

@basvandijk basvandijk merged commit fae2524 into NixOS:master Aug 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants