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: add --flake option #379750

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

pinpox
Copy link
Member

@pinpox pinpox commented Feb 6, 2025

This adds a --flake option to nixos-generate-config which optionally also generates a flake.nix file alongside of configuration.nix and hardware-configuration.nix. It gives people stumbling across tutorials that explain flake-based setups an easy starting point with a simple flake, without impacting existing or non-flake configusrations.

Things done

  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandboxing enabled in nix.conf? (See Nix manual)
    • sandbox = relaxed
    • sandbox = true
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • 25.05 Release Notes (or backporting 24.11 and 25.05 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
  • Fits CONTRIBUTING.md.

Add a 👍 reaction to pull requests you find important.

@github-actions github-actions bot added 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 8.has: module (update) This PR changes an existing module in `nixos/` 8.has: documentation This PR adds or changes documentation labels Feb 6, 2025
@ofborg ofborg bot added the 2.status: merge conflict This PR has merge conflicts with the target branch label Feb 6, 2025
@pinpox pinpox requested a review from a-kenji February 6, 2025 03:32
@eclairevoyant
Copy link
Contributor

Seems like this needs rebasing on a recent commit first?

@pinpox pinpox force-pushed the nixos-generate-config-flake branch from 0f238de to 481b89f Compare February 6, 2025 06:39
@ofborg ofborg bot removed the 2.status: merge conflict This PR has merge conflicts with the target branch label Feb 6, 2025
@pinpox pinpox force-pushed the nixos-generate-config-flake branch 3 times, most recently from 7ed3895 to 3b816db Compare February 6, 2025 06:45
@pinpox pinpox force-pushed the nixos-generate-config-flake branch 4 times, most recently from ccd7db5 to 614c5ca Compare February 6, 2025 06:55
@pinpox pinpox force-pushed the nixos-generate-config-flake branch from 614c5ca to b91d914 Compare February 6, 2025 08:06
@pinpox
Copy link
Member Author

pinpox commented Feb 6, 2025

@eclairevoyant You are right, it is rebased now.

Copy link
Contributor

@eclairevoyant eclairevoyant left a comment

Choose a reason for hiding this comment

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

IMO we should add something to the release notes as well.

outputs = inputs\@{ self, nixpkgs, ... }: {
# NOTE: 'nixos' is the default hostname set by the installer
nixosConfigurations.nixos = nixpkgs.lib.nixosSystem {
system = "${pkgs.stdenv.hostPlatform.system}";
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
system = "${pkgs.stdenv.hostPlatform.system}";

nixpkgs.hostPlatform should already get set in hardware-configuration.nix, and passing system to lib.nixosSystem is deprecated:

nixpkgs/flake.nix

Lines 52 to 54 in 121c18d

Legacy inputs:
- `system`: Legacy alias for `nixpkgs.hostPlatform`, but this is already set in the generated `hardware-configuration.nix`, included by `configuration.nix`.

{
inputs = {

# NOTE: Replace "nixos-${config.system.nixos.release}" on new releases
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
# NOTE: Replace "nixos-${config.system.nixos.release}" on new releases
# NOTE: Replace "nixos-${config.system.nixos.release}" (after reading the release notes) on new releases

Comment on lines +207 to +209
This is an internal option. No backward compatibility is guaranteed.
Use at your own risk!

Copy link
Contributor

@eclairevoyant eclairevoyant Feb 6, 2025

Choose a reason for hiding this comment

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

Nit: this is probably superfluous, internal options don't even appear in the docs, so if someone found out about it, they are already looking at the code

Comment on lines +68 to +69
# NOTE: 'nixos' is the default hostname set by the installer
nixosConfigurations.nixos = nixpkgs.lib.nixosSystem {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
# NOTE: 'nixos' is the default hostname set by the installer
nixosConfigurations.nixos = nixpkgs.lib.nixosSystem {
# NOTE: '${options.networking.hostName.default}' is the default hostname
nixosConfigurations.${options.networking.hostName.default} = nixpkgs.lib.nixosSystem {

Copy link
Contributor

@a-kenji a-kenji left a comment

Choose a reason for hiding this comment

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

LGTM, pending eclairevoyant's changes.

@wegank wegank added the 12.approvals: 1 This PR was reviewed and approved by one reputable person label Feb 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 8.has: documentation This PR adds or changes documentation 8.has: module (update) This PR changes an existing module in `nixos/` 10.rebuild-darwin: 1-10 10.rebuild-linux: 1-10 12.approvals: 1 This PR was reviewed and approved by one reputable person
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants