1
0
Fork 1
mirror of https://github.com/NixOS/nixpkgs.git synced 2024-11-24 06:31:02 +00:00

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>
This commit is contained in:
aszlig 2013-10-23 16:42:34 +02:00
parent e2c546ce4a
commit f182fdf6ed
No known key found for this signature in database
GPG key ID: D0EBD0EC8C2DC961
2 changed files with 38 additions and 20 deletions

View file

@ -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>

View file

@ -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) {
print STDERR "writing $fn...\n";
if ($showHardwareConfig) {
print STDOUT $hwConfig;
} else {
$outDir = "$rootDir$outDir";
my $bootloaderConfig;
if (-e "/sys/firmware/efi/efivars") {
$bootLoaderConfig = <<EOF;
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;
# 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