diff --git a/nixos/doc/manual/installation/installing.chapter.md b/nixos/doc/manual/installation/installing.chapter.md index 5322e9f5e598..8ee417a108fd 100644 --- a/nixos/doc/manual/installation/installing.chapter.md +++ b/nixos/doc/manual/installation/installing.chapter.md @@ -398,6 +398,9 @@ Use the following commands: [](#ch-options). A minimal example is shown in [Example: NixOS Configuration](#ex-config). + This command accepts an optional `--flake` option, to also generate a + `flake.nix` file, if you want to set up a flake-based configuration. + The command `nixos-generate-config` can generate an initial configuration file for you: @@ -490,6 +493,14 @@ Use the following commands: from the NixOS binary cache), you can re-run `nixos-install` after fixing your `configuration.nix`. + If you opted for a flake-based configuration, you will need to pass the + `--flake` here as well and specify the name of the configuration as used in + the `flake.nix` file. For the default generated flake, this is `nixos`. + + ```ShellSession + # nixos-install --flake 'path/to/flake.nix#nixos' + ``` + As the last step, `nixos-install` will ask you to set the password for the `root` user, e.g. diff --git a/nixos/doc/manual/release-notes/rl-2505.section.md b/nixos/doc/manual/release-notes/rl-2505.section.md index 5ab69087a925..498c0af172d4 100644 --- a/nixos/doc/manual/release-notes/rl-2505.section.md +++ b/nixos/doc/manual/release-notes/rl-2505.section.md @@ -30,6 +30,8 @@ - `nixos-rebuild-ng`, a full rewrite of `nixos-rebuild` in Python, is available for testing. You can enable it by setting [system.rebuild.enableNg](options.html#opt-system.rebuild.enableNg) in your configuration (this will replace the old `nixos-rebuild`), or by adding `nixos-rebuild-ng` to your `environment.systemPackages` (in this case, it will live side-by-side with `nixos-rebuild` as `nixos-rebuild-ng`). It is expected that the next major version of NixOS (25.11) will enable `system.rebuild.enableNg` by default. +- The `nixos-generate-config` command now supports a optional `--flake` option, which will generate a flake.nix file alongside the `configuration.nix` and `hardware-configuration.nix`, providing an easy instroduction into flake-based system configurations. + - A `nixos-rebuild build-image` sub-command has been added. It allows users to build platform-specific (disk) images from their NixOS configurations. `nixos-rebuild build-image` works similar to the popular [nix-community/nixos-generators](https://github.com/nix-community/nixos-generators) project. See new [section on image building in the nixpkgs manual](https://nixos.org/manual/nixpkgs/unstable/#sec-image-nixos-rebuild-build-image). It is also available for `nixos-rebuild-ng`. diff --git a/nixos/modules/installer/tools/manpages/nixos-generate-config.8 b/nixos/modules/installer/tools/manpages/nixos-generate-config.8 index 1b95599e156a..33afcc2d3b02 100644 --- a/nixos/modules/installer/tools/manpages/nixos-generate-config.8 +++ b/nixos/modules/installer/tools/manpages/nixos-generate-config.8 @@ -12,6 +12,7 @@ .Op Fl -force .Op Fl -root Ar root .Op Fl -dir Ar dir +.Op Fl -flake . . . @@ -68,7 +69,14 @@ instead of .It Fl -force Overwrite .Pa /etc/nixos/configuration.nix -if it already exists. +(and +.Pa /etc/nixos/flake.nix +if --flake is passed) if already present. +. +.It Fl -flake +Also generate +.Pa /etc/nixos/flake.nix Ns +\&. . .It Fl -no-filesystems Omit everything concerning file systems and swap devices from the hardware configuration. diff --git a/nixos/modules/installer/tools/nixos-generate-config.pl b/nixos/modules/installer/tools/nixos-generate-config.pl index cf4173638b1a..10ff1aeafd05 100644 --- a/nixos/modules/installer/tools/nixos-generate-config.pl +++ b/nixos/modules/installer/tools/nixos-generate-config.pl @@ -35,6 +35,7 @@ my $outDir = "/etc/nixos"; my $rootDir = ""; # = / my $force = 0; my $noFilesystems = 0; +my $flake = 0; my $showHardwareConfig = 0; for (my $n = 0; $n < scalar @ARGV; $n++) { @@ -64,6 +65,9 @@ for (my $n = 0; $n < scalar @ARGV; $n++) { elsif ($arg eq "--show-hardware-config") { $showHardwareConfig = 1; } + elsif ($arg eq "--flake") { + $flake = 1; + } else { die "$0: unrecognized argument ‘$arg’\n"; } @@ -661,6 +665,19 @@ if ($showHardwareConfig) { mkpath($outDir, 0, 0755); write_file($fn, $hwConfig); + $fn = "$outDir/flake.nix"; + if ($flake) { + if ($force || ! -e $fn) { + print STDERR "writing $fn...\n"; + mkpath($outDir, 0, 0755); + write_file($fn, <