nixos-generate-config: Write to /etc/nixos/hardware.nix rather than stdout
This commit is contained in:
parent
3ed41735b8
commit
fd0fd49d36
@ -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 <<EOF ;
|
||||
# This is a generated file. Do not modify!
|
||||
# Make changes to /etc/nixos/configuration.nix instead.
|
||||
write_file($fn, <<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.
|
||||
{ config, pkgs, ... }:
|
||||
|
||||
{
|
||||
@ -245,4 +270,5 @@ print <<EOF ;
|
||||
nix.maxJobs = $cpus;
|
||||
$attrs}
|
||||
EOF
|
||||
|
||||
# workaround for a bug in substituteAll
|
||||
|
@ -1,5 +1,5 @@
|
||||
# This module generates nixos-install, nixos-rebuild,
|
||||
# nixos-hardware-scan, etc.
|
||||
# nixos-generate-config, etc.
|
||||
|
||||
{ config, pkgs, modulesPath, ... }:
|
||||
|
||||
@ -37,7 +37,8 @@ let
|
||||
nixos-generate-config = makeProg {
|
||||
name = "nixos-generate-config";
|
||||
src = ./nixos-generate-config.pl;
|
||||
inherit (pkgs) perl dmidecode;
|
||||
perl = "${pkgs.perl}/bin/perl -I${pkgs.perlPackages.FileSlurp}/lib/perl5/site_perl";
|
||||
inherit (pkgs) dmidecode;
|
||||
};
|
||||
|
||||
nixos-option = makeProg {
|
||||
|
Loading…
Reference in New Issue
Block a user