From fd0fd49d36bc713b3783686a4a41f4680f874c4d Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Fri, 11 Oct 2013 14:44:32 +0200 Subject: [PATCH] nixos-generate-config: Write to /etc/nixos/hardware.nix rather than stdout --- .../installer/tools/nixos-generate-config.pl | 44 +++++++++++++++---- nixos/modules/installer/tools/tools.nix | 5 ++- 2 files changed, 38 insertions(+), 11 deletions(-) diff --git a/nixos/modules/installer/tools/nixos-generate-config.pl b/nixos/modules/installer/tools/nixos-generate-config.pl index 3204f3d40512..58508560b8e4 100644 --- a/nixos/modules/installer/tools/nixos-generate-config.pl +++ b/nixos/modules/installer/tools/nixos-generate-config.pl @@ -1,7 +1,28 @@ -#! @perl@/bin/perl -w +#! @perl@ use File::Spec; +use File::Path; use File::Basename; +use File::Slurp; + + +# Process the command line. +my $outDir = "/etc/nixos"; + +for (my $n = 0; $n < scalar @ARGV; $n++) { + my $arg = $ARGV[$n]; + if ($arg eq "--help") { + exec "man nixos-generate-config" or die; + } + elsif ($arg eq "--dir") { + $n++; + $outDir = $ARGV[$n]; + die "$0: ‘--dir’ requires an argument\n" unless defined $outDir; + } + else { + die "$0: unrecognized argument ‘$arg’\n"; + } +} my @attrs = (); @@ -62,13 +83,13 @@ sub pciCheck { my $vendor = readFile "$path/vendor"; my $device = readFile "$path/device"; my $class = readFile "$path/class"; - + my $module; if (-e "$path/driver/module") { $module = basename `readlink -f $path/driver/module`; chomp $module; } - + debug "$path: $vendor $device $class"; debug " $module" if defined $module; debug "\n"; @@ -140,11 +161,11 @@ sub usbCheck { $module = basename `readlink -f $path/driver/module`; chomp $module; } - + debug "$path: $class $subclass $protocol"; debug " $module" if defined $module; debug "\n"; - + if (defined $module) { if (# Mass-storage controller. Definitely important. $class eq "08" || @@ -191,7 +212,7 @@ if ($dmi =~ /Manufacturer: innotek/) { } -# Generate the configuration file. +# Generate the hardware configuration file. sub removeDups { my %seen; @@ -229,10 +250,14 @@ my $modulePackages = toNixExpr(removeDups @modulePackages); my $attrs = multiLineList(" ", removeDups @attrs); my $imports = multiLineList(" ", removeDups @imports); +my $fn = "$outDir/hardware.nix"; +print STDERR "writing $fn...\n"; +mkpath($outDir, 0, 0755); -print <