Skip to content

Commit

Permalink
nixos-generate-config: don't generate swapDevices for *files*
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bjornfor committed Jun 16, 2019
1 parent b0ccba1 commit 9e45f6f
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions nixos/modules/installer/tools/nixos-generate-config.pl
Expand Up @@ -324,10 +324,19 @@ sub findStableDevPath {
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";
}
}
}

Expand Down

0 comments on commit 9e45f6f

Please sign in to comment.