diff options
-rw-r--r-- | nixos/doc/manual/man-nixos-generate-config.xml | 9 | ||||
-rw-r--r-- | nixos/modules/installer/tools/nixos-generate-config.pl | 47 |
2 files changed, 37 insertions, 19 deletions
diff --git a/nixos/doc/manual/man-nixos-generate-config.xml b/nixos/doc/manual/man-nixos-generate-config.xml index 0771753f689..e4fba4a40a9 100644 --- a/nixos/doc/manual/man-nixos-generate-config.xml +++ b/nixos/doc/manual/man-nixos-generate-config.xml @@ -118,6 +118,15 @@ </listitem> </varlistentry> + <varlistentry> + <term><option>--show-hardware-config</option></term> + <listitem> + <para>Don't generate <filename>configuration.nix</filename> or + <filename>hardware-configuration.nix</filename> and print the + hardware configuration to stdout only.</para> + </listitem> + </varlistentry> + </variablelist> </refsection> diff --git a/nixos/modules/installer/tools/nixos-generate-config.pl b/nixos/modules/installer/tools/nixos-generate-config.pl index a4d22410806..c6ac72e113b 100644 --- a/nixos/modules/installer/tools/nixos-generate-config.pl +++ b/nixos/modules/installer/tools/nixos-generate-config.pl @@ -24,6 +24,7 @@ my $outDir = "/etc/nixos"; my $rootDir = ""; # = / my $force = 0; my $noFilesystems = 0; +my $showHardwareConfig = 0; for (my $n = 0; $n < scalar @ARGV; $n++) { my $arg = $ARGV[$n]; @@ -47,6 +48,9 @@ for (my $n = 0; $n < scalar @ARGV; $n++) { elsif ($arg eq "--no-filesystems") { $noFilesystems = 1; } + elsif ($arg eq "--show-hardware-config") { + $showHardwareConfig = 1; + } else { die "$0: unrecognized argument ‘$arg’\n"; } @@ -336,19 +340,13 @@ my $initrdAvailableKernelModules = toNixExpr(uniq @initrdAvailableKernelModules) my $kernelModules = toNixExpr(uniq @kernelModules); my $modulePackages = toNixExpr(uniq @modulePackages); -$outDir = "$rootDir$outDir"; - -my $fn = "$outDir/hardware-configuration.nix"; -print STDERR "writing $fn...\n"; -mkpath($outDir, 0, 0755); - my $fsAndSwap = ""; if (!$noFilesystems) { $fsAndSwap = "\n${fileSystems} "; $fsAndSwap .= "swapDevices =" . multiLineList(" ", @swapDevices) . ";\n"; } -write_file($fn, <<EOF); +my $hwConfig = <<EOF; # Do not modify this file! It was generated by ‘nixos-generate-config’ # and may be overwritten by future invocations. Please make changes # to /etc/nixos/configuration.nix instead. @@ -366,14 +364,24 @@ ${\join "", (map { " $_\n" } (uniq @attrs))}} EOF -# Generate a basic configuration.nix, unless one already exists. -$fn = "$outDir/configuration.nix"; -if ($force || ! -e $fn) { +if ($showHardwareConfig) { + print STDOUT $hwConfig; +} else { + $outDir = "$rootDir$outDir"; + + my $fn = "$outDir/hardware-configuration.nix"; print STDERR "writing $fn...\n"; + mkpath($outDir, 0, 0755); + write_file($fn, $hwConfig); + + # Generate a basic configuration.nix, unless one already exists. + $fn = "$outDir/configuration.nix"; + if ($force || ! -e $fn) { + print STDERR "writing $fn...\n"; - my $bootloaderConfig; - if (-e "/sys/firmware/efi/efivars") { - $bootLoaderConfig = <<EOF; + my $bootloaderConfig; + if (-e "/sys/firmware/efi/efivars") { + $bootLoaderConfig = <<EOF; # Use the gummiboot efi boot loader. boot.loader.grub.enable = false; boot.loader.gummiboot.enable = true; @@ -382,17 +390,17 @@ if ($force || ! -e $fn) { # EFI booting requires kernel >= 3.10 boot.kernelPackages = pkgs.linuxPackages_3_10; EOF - } else { - $bootLoaderConfig = <<EOF; + } else { + $bootLoaderConfig = <<EOF; # Use the GRUB 2 boot loader. boot.loader.grub.enable = true; boot.loader.grub.version = 2; # Define on which hard drive you want to install Grub. # boot.loader.grub.device = "/dev/sda"; EOF - } + } - write_file($fn, <<EOF); + write_file($fn, <<EOF); # Edit this configuration file to define what should be installed on # your system. Help is available in the configuration.nix(5) man page # and in the NixOS manual (accessible by running ‘nixos-help’). @@ -453,8 +461,9 @@ $bootLoaderConfig # services.xserver.desktopManager.kde4.enable = true; } EOF -} else { - print STDERR "warning: not overwriting existing $fn\n"; + } else { + print STDERR "warning: not overwriting existing $fn\n"; + } } # workaround for a bug in substituteAll |