summary refs log tree commit diff
path: root/nixos
diff options
context:
space:
mode:
authorEelco Dolstra <eelco.dolstra@logicblox.com>2013-10-11 16:05:31 +0200
committerEelco Dolstra <eelco.dolstra@logicblox.com>2013-10-13 17:35:56 +0200
commit677d9882b0e3eedc116b6fc77d93717ac7918907 (patch)
treecd763442e6c44564c683639dd55d8e18cf2ab872 /nixos
parent440fe8f05da84c37262ce4459d63febdded44f95 (diff)
downloadnixpkgs-677d9882b0e3eedc116b6fc77d93717ac7918907.tar
nixpkgs-677d9882b0e3eedc116b6fc77d93717ac7918907.tar.gz
nixpkgs-677d9882b0e3eedc116b6fc77d93717ac7918907.tar.bz2
nixpkgs-677d9882b0e3eedc116b6fc77d93717ac7918907.tar.lz
nixpkgs-677d9882b0e3eedc116b6fc77d93717ac7918907.tar.xz
nixpkgs-677d9882b0e3eedc116b6fc77d93717ac7918907.tar.zst
nixpkgs-677d9882b0e3eedc116b6fc77d93717ac7918907.zip
nixos-generate-config: Generate swapDevices
Diffstat (limited to 'nixos')
-rw-r--r--nixos/modules/installer/tools/nixos-generate-config.pl42
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 a70c9daff23..efb250c081d 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";