nixos-generate-config: Generate swapDevices
This commit is contained in:
parent
440fe8f05d
commit
677d9882b0
@ -131,6 +131,8 @@ foreach my $path (glob "/sys/bus/pci/devices/*") {
|
|||||||
pciCheck $path;
|
pciCheck $path;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
push @attrs, "services.xserver.videoDrivers = [ \"$videoDriver\" ];" if $videoDriver;
|
||||||
|
|
||||||
|
|
||||||
# Idem for USB devices.
|
# Idem for USB devices.
|
||||||
|
|
||||||
@ -172,7 +174,6 @@ foreach my $path (glob "/sys/bus/usb/devices/*") {
|
|||||||
|
|
||||||
|
|
||||||
# Add the modules for all block devices.
|
# Add the modules for all block devices.
|
||||||
|
|
||||||
foreach my $path (glob "/sys/class/block/*") {
|
foreach my $path (glob "/sys/class/block/*") {
|
||||||
my $module;
|
my $module;
|
||||||
if (-e "$path/device/driver/module") {
|
if (-e "$path/device/driver/module") {
|
||||||
@ -183,11 +184,6 @@ foreach my $path (glob "/sys/class/block/*") {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if ($videoDriver) {
|
|
||||||
push @attrs, "services.xserver.videoDrivers = [ \"$videoDriver\" ];";
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
# Check if we're a VirtualBox guest. If so, enable the guest
|
# Check if we're a VirtualBox guest. If so, enable the guest
|
||||||
# additions.
|
# additions.
|
||||||
my $dmi = `@dmidecode@/sbin/dmidecode`;
|
my $dmi = `@dmidecode@/sbin/dmidecode`;
|
||||||
@ -196,6 +192,16 @@ if ($dmi =~ /Manufacturer: innotek/) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
# Generate the list of swap devices.
|
||||||
|
my @swaps = read_file("/proc/swaps");
|
||||||
|
shift @swaps;
|
||||||
|
my @swapDevices;
|
||||||
|
foreach my $swap (@swaps) {
|
||||||
|
$swap =~ /^(\S+)\s/;
|
||||||
|
push @swapDevices, "{ device = \"$1\"; }";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
# Generate the hardware configuration file.
|
# Generate the hardware configuration file.
|
||||||
|
|
||||||
sub removeDups {
|
sub removeDups {
|
||||||
@ -220,19 +226,21 @@ sub toNixExpr {
|
|||||||
|
|
||||||
sub multiLineList {
|
sub multiLineList {
|
||||||
my $indent = shift;
|
my $indent = shift;
|
||||||
my $res = "";
|
return "[ ]" if !@_;
|
||||||
$res = "\n" if scalar @_ > 0;
|
$res = "\n${indent}[ ";
|
||||||
|
my $first = 1;
|
||||||
foreach my $s (@_) {
|
foreach my $s (@_) {
|
||||||
$res .= "$indent$s\n";
|
$res .= "$indent " if !$first;
|
||||||
|
$first = 0;
|
||||||
|
$res .= "$s\n";
|
||||||
}
|
}
|
||||||
|
$res .= "$indent]";
|
||||||
return $res;
|
return $res;
|
||||||
}
|
}
|
||||||
|
|
||||||
my $initrdKernelModules = toNixExpr(removeDups @initrdKernelModules);
|
my $initrdKernelModules = toNixExpr(removeDups @initrdKernelModules);
|
||||||
my $kernelModules = toNixExpr(removeDups @kernelModules);
|
my $kernelModules = toNixExpr(removeDups @kernelModules);
|
||||||
my $modulePackages = toNixExpr(removeDups @modulePackages);
|
my $modulePackages = toNixExpr(removeDups @modulePackages);
|
||||||
my $attrs = multiLineList(" ", removeDups @attrs);
|
|
||||||
my $imports = multiLineList(" ", removeDups @imports);
|
|
||||||
|
|
||||||
my $fn = "$outDir/hardware-configuration.nix";
|
my $fn = "$outDir/hardware-configuration.nix";
|
||||||
print STDERR "writing $fn...\n";
|
print STDERR "writing $fn...\n";
|
||||||
@ -245,16 +253,19 @@ write_file($fn, <<EOF);
|
|||||||
{ config, pkgs, ... }:
|
{ config, pkgs, ... }:
|
||||||
|
|
||||||
{
|
{
|
||||||
imports = [$imports ];
|
imports = ${\multiLineList(" ", @imports)};
|
||||||
|
|
||||||
boot.initrd.kernelModules = [$initrdKernelModules ];
|
boot.initrd.kernelModules = [$initrdKernelModules ];
|
||||||
boot.kernelModules = [$kernelModules ];
|
boot.kernelModules = [$kernelModules ];
|
||||||
boot.extraModulePackages = [$modulePackages ];
|
boot.extraModulePackages = [$modulePackages ];
|
||||||
|
|
||||||
|
swapDevices = ${\multiLineList(" ", @swapDevices)};
|
||||||
|
|
||||||
nix.maxJobs = $cpus;
|
nix.maxJobs = $cpus;
|
||||||
$attrs}
|
${\join "", (map { " $_\n" } (removeDups @attrs))}}
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
|
|
||||||
# Generate a basic configuration.nix, unless one already exists.
|
# Generate a basic configuration.nix, unless one already exists.
|
||||||
$fn = "$outDir/configuration.nix";
|
$fn = "$outDir/configuration.nix";
|
||||||
if (! -e $fn) {
|
if (! -e $fn) {
|
||||||
@ -317,11 +328,6 @@ $bootLoaderConfig
|
|||||||
# options = "data=journal";
|
# options = "data=journal";
|
||||||
# };
|
# };
|
||||||
|
|
||||||
# List swap partitions activated at boot time.
|
|
||||||
swapDevices =
|
|
||||||
[ # { device = "/dev/disk/by-label/swap"; }
|
|
||||||
];
|
|
||||||
|
|
||||||
# Select internationalisation properties.
|
# Select internationalisation properties.
|
||||||
# i18n = {
|
# i18n = {
|
||||||
# consoleFont = "lat9w-16";
|
# consoleFont = "lat9w-16";
|
||||||
|
Loading…
x
Reference in New Issue
Block a user