swap: support swapDevices.*.priority option

This just forwards to the underlying NixOS option and expands the mount
script to exhibit the same behavior.
This commit is contained in:
Giel van Schijndel 2024-05-06 11:43:53 +02:00
parent 8a02c0507c
commit c5a25d5ced
No known key found for this signature in database
GPG Key ID: 3E52E1D396DFB43B
2 changed files with 15 additions and 2 deletions

View File

@ -29,6 +29,7 @@
content = { content = {
type = "swap"; type = "swap";
randomEncryption = true; randomEncryption = true;
priority = 100; # prefer to encrypt as long as we have space for it
}; };
}; };
plainSwap = { plainSwap = {

View File

@ -28,6 +28,15 @@
default = [ ]; default = [ ];
description = "Extra arguments"; description = "Extra arguments";
}; };
priority = lib.mkOption {
type = lib.types.nullOr lib.types.int;
default = null;
description = lib.mdDoc ''
Specify the priority of the swap device. Priority is a value between 0 and 32767.
Higher numbers indicate higher priority.
null lets the kernel choose a priority, which will show up as a negative value.
'';
};
randomEncryption = lib.mkOption { randomEncryption = lib.mkOption {
type = lib.types.bool; type = lib.types.bool;
default = false; default = false;
@ -69,7 +78,10 @@
lib.optionalString (config.discardPolicy != null) lib.optionalString (config.discardPolicy != null)
"--discard${lib.optionalString (config.discardPolicy != "both") "--discard${lib.optionalString (config.discardPolicy != "both")
"=${config.discardPolicy}" "=${config.discardPolicy}"
}"} ${config.device} }"} ${
lib.optionalString (config.priority != null)
"--priority=${toString config.priority}"
} ${config.device}
fi fi
''; '';
}; };
@ -80,7 +92,7 @@
default = [{ default = [{
swapDevices = [{ swapDevices = [{
device = config.device; device = config.device;
inherit (config) discardPolicy randomEncryption; inherit (config) discardPolicy priority randomEncryption;
}]; }];
boot.resumeDevice = lib.mkIf config.resumeDevice config.device; boot.resumeDevice = lib.mkIf config.resumeDevice config.device;
}]; }];