diff options
author | Eelco Dolstra <eelco.dolstra@logicblox.com> | 2013-10-11 16:05:31 +0200 |
---|---|---|
committer | Eelco Dolstra <eelco.dolstra@logicblox.com> | 2013-10-13 17:35:56 +0200 |
commit | 677d9882b0e3eedc116b6fc77d93717ac7918907 (patch) | |
tree | cd763442e6c44564c683639dd55d8e18cf2ab872 /nixos | |
parent | 440fe8f05da84c37262ce4459d63febdded44f95 (diff) | |
download | nixlib-677d9882b0e3eedc116b6fc77d93717ac7918907.tar nixlib-677d9882b0e3eedc116b6fc77d93717ac7918907.tar.gz nixlib-677d9882b0e3eedc116b6fc77d93717ac7918907.tar.bz2 nixlib-677d9882b0e3eedc116b6fc77d93717ac7918907.tar.lz nixlib-677d9882b0e3eedc116b6fc77d93717ac7918907.tar.xz nixlib-677d9882b0e3eedc116b6fc77d93717ac7918907.tar.zst nixlib-677d9882b0e3eedc116b6fc77d93717ac7918907.zip |
nixos-generate-config: Generate swapDevices
Diffstat (limited to 'nixos')
-rw-r--r-- | nixos/modules/installer/tools/nixos-generate-config.pl | 42 |
1 files changed, 24 insertions, 18 deletions
diff --git a/nixos/modules/installer/tools/nixos-generate-config.pl b/nixos/modules/installer/tools/nixos-generate-config.pl index a70c9daff23b..efb250c081d0 100644 --- a/nixos/modules/installer/tools/nixos-generate-config.pl +++ b/nixos/modules/installer/tools/nixos-generate-config.pl @@ -131,6 +131,8 @@ foreach my $path (glob "/sys/bus/pci/devices/*") { pciCheck $path; } +push @attrs, "services.xserver.videoDrivers = [ \"$videoDriver\" ];" if $videoDriver; + # Idem for USB devices. @@ -172,7 +174,6 @@ foreach my $path (glob "/sys/bus/usb/devices/*") { # Add the modules for all block devices. - foreach my $path (glob "/sys/class/block/*") { my $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 # additions. 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. sub removeDups { @@ -220,19 +226,21 @@ sub toNixExpr { sub multiLineList { my $indent = shift; - my $res = ""; - $res = "\n" if scalar @_ > 0; + return "[ ]" if !@_; + $res = "\n${indent}[ "; + my $first = 1; foreach my $s (@_) { - $res .= "$indent$s\n"; + $res .= "$indent " if !$first; + $first = 0; + $res .= "$s\n"; } + $res .= "$indent]"; return $res; } my $initrdKernelModules = toNixExpr(removeDups @initrdKernelModules); my $kernelModules = toNixExpr(removeDups @kernelModules); my $modulePackages = toNixExpr(removeDups @modulePackages); -my $attrs = multiLineList(" ", removeDups @attrs); -my $imports = multiLineList(" ", removeDups @imports); my $fn = "$outDir/hardware-configuration.nix"; print STDERR "writing $fn...\n"; @@ -245,16 +253,19 @@ write_file($fn, <<EOF); { config, pkgs, ... }: { - imports = [$imports ]; + imports = ${\multiLineList(" ", @imports)}; boot.initrd.kernelModules = [$initrdKernelModules ]; boot.kernelModules = [$kernelModules ]; boot.extraModulePackages = [$modulePackages ]; + swapDevices = ${\multiLineList(" ", @swapDevices)}; + nix.maxJobs = $cpus; -$attrs} +${\join "", (map { " $_\n" } (removeDups @attrs))}} EOF + # Generate a basic configuration.nix, unless one already exists. $fn = "$outDir/configuration.nix"; if (! -e $fn) { @@ -317,11 +328,6 @@ $bootLoaderConfig # options = "data=journal"; # }; - # List swap partitions activated at boot time. - swapDevices = - [ # { device = "/dev/disk/by-label/swap"; } - ]; - # Select internationalisation properties. # i18n = { # consoleFont = "lat9w-16"; |