summary refs log tree commit diff
path: root/nixos/modules/installer/tools/nixos-generate-config.pl
diff options
context:
space:
mode:
authorBjørn Forsman <bjorn.forsman@gmail.com>2019-06-10 20:27:04 +0200
committerBjørn Forsman <bjorn.forsman@gmail.com>2019-06-16 15:26:33 +0200
commit9e45f6feac633fdc41eaaaa1ad65d77bda252472 (patch)
tree8d9c1f6432c12c37e2d9f88da0184db15aee8b7e /nixos/modules/installer/tools/nixos-generate-config.pl
parentb0ccba1a2da2aa2460fbbf51aaba455e46bd1e27 (diff)
downloadnixpkgs-9e45f6feac633fdc41eaaaa1ad65d77bda252472.tar
nixpkgs-9e45f6feac633fdc41eaaaa1ad65d77bda252472.tar.gz
nixpkgs-9e45f6feac633fdc41eaaaa1ad65d77bda252472.tar.bz2
nixpkgs-9e45f6feac633fdc41eaaaa1ad65d77bda252472.tar.lz
nixpkgs-9e45f6feac633fdc41eaaaa1ad65d77bda252472.tar.xz
nixpkgs-9e45f6feac633fdc41eaaaa1ad65d77bda252472.tar.zst
nixpkgs-9e45f6feac633fdc41eaaaa1ad65d77bda252472.zip
nixos-generate-config: don't generate swapDevices for *files*
Up until now, the output has been the same for swap devices and swap
files:

  { device = "/var/swapfile"; }

Whereas for swap *files* it's easier to manage them declaratively in
configuration.nix:

  { device = "/var/swapfile"; size = 8192; }

(NixOS will create the swapfile, and later resize it, if the size
attribute is changed.)

With the assumption that swap files are specified in configuration.nix,
it's silly to output them to hardware-configuration.nix.
Diffstat (limited to 'nixos/modules/installer/tools/nixos-generate-config.pl')
-rw-r--r--nixos/modules/installer/tools/nixos-generate-config.pl17
1 files changed, 13 insertions, 4 deletions
diff --git a/nixos/modules/installer/tools/nixos-generate-config.pl b/nixos/modules/installer/tools/nixos-generate-config.pl
index 0ccdac30d91..9a1157d9501 100644
--- a/nixos/modules/installer/tools/nixos-generate-config.pl
+++ b/nixos/modules/installer/tools/nixos-generate-config.pl
@@ -324,10 +324,19 @@ my @swapDevices;
 if (@swaps) {
     shift @swaps;
     foreach my $swap (@swaps) {
-        $swap =~ /^(\S+)\s/;
-        next unless -e $1;
-        my $dev = findStableDevPath $1;
-        push @swapDevices, "{ device = \"$dev\"; }";
+        my @fields = split ' ', $swap;
+        my $swapFilename = $fields[0];
+        my $swapType = $fields[1];
+        next unless -e $swapFilename;
+        my $dev = findStableDevPath $swapFilename;
+        if ($swapType =~ "partition") {
+            push @swapDevices, "{ device = \"$dev\"; }";
+        } elsif ($swapType =~ "file") {
+            # swap *files* are more likely specified in configuration.nix, so
+            # ignore them here.
+        } else {
+            die "Unsupported swap type: $swapType\n";
+        }
     }
 }