diff options
author | aszlig <aszlig@redmoonstudios.org> | 2013-10-23 16:42:34 +0200 |
---|---|---|
committer | aszlig <aszlig@redmoonstudios.org> | 2013-10-23 17:16:17 +0200 |
commit | f182fdf6ed3acf820a5f619eda9bffee1ecd1c46 (patch) | |
tree | a1a3ace18bc7aa9272a5732838bfd9c3bb0f8186 /nixos/modules/installer/tools/nixos-generate-config.pl | |
parent | e2c546ce4a583d74389dadaad3f1af44860336ac (diff) | |
download | nixpkgs-f182fdf6ed3acf820a5f619eda9bffee1ecd1c46.tar nixpkgs-f182fdf6ed3acf820a5f619eda9bffee1ecd1c46.tar.gz nixpkgs-f182fdf6ed3acf820a5f619eda9bffee1ecd1c46.tar.bz2 nixpkgs-f182fdf6ed3acf820a5f619eda9bffee1ecd1c46.tar.lz nixpkgs-f182fdf6ed3acf820a5f619eda9bffee1ecd1c46.tar.xz nixpkgs-f182fdf6ed3acf820a5f619eda9bffee1ecd1c46.tar.zst nixpkgs-f182fdf6ed3acf820a5f619eda9bffee1ecd1c46.zip |
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>
Diffstat (limited to 'nixos/modules/installer/tools/nixos-generate-config.pl')
-rw-r--r-- | nixos/modules/installer/tools/nixos-generate-config.pl | 47 |
1 files changed, 28 insertions, 19 deletions
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 |