mirror of
https://github.com/nix-community/disko.git
synced 2024-09-19 02:27:27 +03:00
swap: support swapDevices.*.discardPolicy option
This commit is contained in:
parent
e1b3ae2b4e
commit
8a02c0507c
@ -35,6 +35,7 @@
|
|||||||
size = "100%";
|
size = "100%";
|
||||||
content = {
|
content = {
|
||||||
type = "swap";
|
type = "swap";
|
||||||
|
discardPolicy = "both";
|
||||||
resumeDevice = true; # resume from hiberation from this device
|
resumeDevice = true; # resume from hiberation from this device
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
@ -11,6 +11,18 @@
|
|||||||
default = device;
|
default = device;
|
||||||
description = "Device";
|
description = "Device";
|
||||||
};
|
};
|
||||||
|
discardPolicy = lib.mkOption {
|
||||||
|
default = null;
|
||||||
|
example = "once";
|
||||||
|
type = lib.types.nullOr (lib.types.enum [ "once" "pages" "both" ]);
|
||||||
|
description = lib.mdDoc ''
|
||||||
|
Specify the discard policy for the swap device. If "once", then the
|
||||||
|
whole swap space is discarded at swapon invocation. If "pages",
|
||||||
|
asynchronous discard on freed pages is performed, before returning to
|
||||||
|
the available pages pool. With "both", both policies are activated.
|
||||||
|
See swapon(8) for more information.
|
||||||
|
'';
|
||||||
|
};
|
||||||
extraArgs = lib.mkOption {
|
extraArgs = lib.mkOption {
|
||||||
type = lib.types.listOf lib.types.str;
|
type = lib.types.listOf lib.types.str;
|
||||||
default = [ ];
|
default = [ ];
|
||||||
@ -53,7 +65,11 @@
|
|||||||
default = lib.optionalAttrs (!config.randomEncryption) {
|
default = lib.optionalAttrs (!config.randomEncryption) {
|
||||||
fs.${config.device} = ''
|
fs.${config.device} = ''
|
||||||
if ! swapon --show | grep -q "^$(readlink -f ${config.device}) "; then
|
if ! swapon --show | grep -q "^$(readlink -f ${config.device}) "; then
|
||||||
swapon ${config.device}
|
swapon ${
|
||||||
|
lib.optionalString (config.discardPolicy != null)
|
||||||
|
"--discard${lib.optionalString (config.discardPolicy != "both")
|
||||||
|
"=${config.discardPolicy}"
|
||||||
|
}"} ${config.device}
|
||||||
fi
|
fi
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
@ -64,7 +80,7 @@
|
|||||||
default = [{
|
default = [{
|
||||||
swapDevices = [{
|
swapDevices = [{
|
||||||
device = config.device;
|
device = config.device;
|
||||||
randomEncryption = config.randomEncryption;
|
inherit (config) discardPolicy randomEncryption;
|
||||||
}];
|
}];
|
||||||
boot.resumeDevice = lib.mkIf config.resumeDevice config.device;
|
boot.resumeDevice = lib.mkIf config.resumeDevice config.device;
|
||||||
}];
|
}];
|
||||||
|
Loading…
Reference in New Issue
Block a user