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::Spec;
|
||||||
|
use File::Path;
|
||||||
use File::Basename;
|
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 = ();
|
my @attrs = ();
|
||||||
@ -62,13 +83,13 @@ sub pciCheck {
|
|||||||
my $vendor = readFile "$path/vendor";
|
my $vendor = readFile "$path/vendor";
|
||||||
my $device = readFile "$path/device";
|
my $device = readFile "$path/device";
|
||||||
my $class = readFile "$path/class";
|
my $class = readFile "$path/class";
|
||||||
|
|
||||||
my $module;
|
my $module;
|
||||||
if (-e "$path/driver/module") {
|
if (-e "$path/driver/module") {
|
||||||
$module = basename `readlink -f $path/driver/module`;
|
$module = basename `readlink -f $path/driver/module`;
|
||||||
chomp $module;
|
chomp $module;
|
||||||
}
|
}
|
||||||
|
|
||||||
debug "$path: $vendor $device $class";
|
debug "$path: $vendor $device $class";
|
||||||
debug " $module" if defined $module;
|
debug " $module" if defined $module;
|
||||||
debug "\n";
|
debug "\n";
|
||||||
@ -140,11 +161,11 @@ sub usbCheck {
|
|||||||
$module = basename `readlink -f $path/driver/module`;
|
$module = basename `readlink -f $path/driver/module`;
|
||||||
chomp $module;
|
chomp $module;
|
||||||
}
|
}
|
||||||
|
|
||||||
debug "$path: $class $subclass $protocol";
|
debug "$path: $class $subclass $protocol";
|
||||||
debug " $module" if defined $module;
|
debug " $module" if defined $module;
|
||||||
debug "\n";
|
debug "\n";
|
||||||
|
|
||||||
if (defined $module) {
|
if (defined $module) {
|
||||||
if (# Mass-storage controller. Definitely important.
|
if (# Mass-storage controller. Definitely important.
|
||||||
$class eq "08" ||
|
$class eq "08" ||
|
||||||
@ -191,7 +212,7 @@ if ($dmi =~ /Manufacturer: innotek/) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
# Generate the configuration file.
|
# Generate the hardware configuration file.
|
||||||
|
|
||||||
sub removeDups {
|
sub removeDups {
|
||||||
my %seen;
|
my %seen;
|
||||||
@ -229,10 +250,14 @@ my $modulePackages = toNixExpr(removeDups @modulePackages);
|
|||||||
my $attrs = multiLineList(" ", removeDups @attrs);
|
my $attrs = multiLineList(" ", removeDups @attrs);
|
||||||
my $imports = multiLineList(" ", removeDups @imports);
|
my $imports = multiLineList(" ", removeDups @imports);
|
||||||
|
|
||||||
|
my $fn = "$outDir/hardware.nix";
|
||||||
|
print STDERR "writing $fn...\n";
|
||||||
|
mkpath($outDir, 0, 0755);
|
||||||
|
|
||||||
print <<EOF ;
|
write_file($fn, <<EOF);
|
||||||
# This is a generated file. Do not modify!
|
# Do not modify this file! It was generated by ‘nixos-generate-config’
|
||||||
# Make changes to /etc/nixos/configuration.nix instead.
|
# and may be overwritten by future invocations. Please make changes
|
||||||
|
# to /etc/nixos/configuration.nix instead.
|
||||||
{ config, pkgs, ... }:
|
{ config, pkgs, ... }:
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -245,4 +270,5 @@ print <<EOF ;
|
|||||||
nix.maxJobs = $cpus;
|
nix.maxJobs = $cpus;
|
||||||
$attrs}
|
$attrs}
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
# workaround for a bug in substituteAll
|
# workaround for a bug in substituteAll
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
# This module generates nixos-install, nixos-rebuild,
|
# This module generates nixos-install, nixos-rebuild,
|
||||||
# nixos-hardware-scan, etc.
|
# nixos-generate-config, etc.
|
||||||
|
|
||||||
{ config, pkgs, modulesPath, ... }:
|
{ config, pkgs, modulesPath, ... }:
|
||||||
|
|
||||||
@ -37,7 +37,8 @@ let
|
|||||||
nixos-generate-config = makeProg {
|
nixos-generate-config = makeProg {
|
||||||
name = "nixos-generate-config";
|
name = "nixos-generate-config";
|
||||||
src = ./nixos-generate-config.pl;
|
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 {
|
nixos-option = makeProg {
|
||||||
|
Loading…
Reference in New Issue
Block a user