nixos-generate-config: Add --show-hardware-config.

So, we get the old behaviour of nixos-hardware-scane if we run the
following command:

nixos-generate-config --no-filesystems --show-hardware-config

This allows to use scripts in order to fetch NixOS specific hardware
information, without the need to duplicate code elsewhere.

Signed-off-by: aszlig <aszlig@redmoonstudios.org>

aszlig f182fdf6 e2c546ce

Changed files
+37 -19
nixos
doc
modules
installer
+9
nixos/doc/manual/man-nixos-generate-config.xml
···
</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>
+28 -19
nixos/modules/installer/tools/nixos-generate-config.pl
···
my $rootDir = ""; # = /
my $force = 0;
my $noFilesystems = 0;
+
my $showHardwareConfig = 0;
for (my $n = 0; $n < scalar @ARGV; $n++) {
my $arg = $ARGV[$n];
···
}
elsif ($arg eq "--no-filesystems") {
$noFilesystems = 1;
+
}
+
elsif ($arg eq "--show-hardware-config") {
+
$showHardwareConfig = 1;
}
else {
die "$0: unrecognized argument ‘$arg’\n";
···
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.
···
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);
-
my $bootloaderConfig;
-
if (-e "/sys/firmware/efi/efivars") {
-
$bootLoaderConfig = <<EOF;
+
# 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;
# Use the gummiboot efi boot loader.
boot.loader.grub.enable = false;
boot.loader.gummiboot.enable = true;
···
# 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’).
···
# 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