git.iko.soy/typeable/nixpkgs
on master help sign in
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.

commit9e45f6feac633fdc41eaaaa1ad65d77bda252472 authorBjørn Forsman <bjorn.forsman@gmail.com> dateMon 10 Jun 2019, 20:27 (7 years ago) parentb0ccba1
1 file changed+13−4
nixos/modules/installer/tools/nixos-generate-config.pl+13−4
nixos/modules/installer/tools/nixos-generate-config.pl+13−4
@@ -324,10 +324,19 @@ my @swapDevices;
324324if (@swaps) {
325325 shift @swaps;
326326 foreach my $swap (@swaps) {
327− $swap =~ /^(\S+)\s/;
328− next unless -e $1;
329− my $dev = findStableDevPath $1;
330− push @swapDevices, "{ device = \"$dev\"; }";
327+ my @fields = split ' ', $swap;
328+ my $swapFilename = $fields[0];
329+ my $swapType = $fields[1];
330+ next unless -e $swapFilename;
331+ my $dev = findStableDevPath $swapFilename;
332+ if ($swapType =~ "partition") {
333+ push @swapDevices, "{ device = \"$dev\"; }";
334+ } elsif ($swapType =~ "file") {
335+ # swap *files* are more likely specified in configuration.nix, so
336+ # ignore them here.
337+ } else {
338+ die "Unsupported swap type: $swapType\n";
339+ }
331340 }
332341}
333342