-
-
Notifications
You must be signed in to change notification settings - Fork 14.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: phanirithvij <phanirithvij2000@gmail.com> Apply suggestions from code review Co-authored-by: Luflosi <luflosi@luflosi.de>
- Loading branch information
1 parent
cab4f47
commit 24fb007
Showing
3 changed files
with
121 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
{ | ||
config, | ||
lib, | ||
pkgs, | ||
... | ||
}: | ||
let | ||
cfg = config.services.swapspace; | ||
inherit (lib) | ||
types | ||
mkOption | ||
mkPackageOption | ||
mkEnableOption | ||
; | ||
configFile = pkgs.writeText "swapspace.conf" (lib.generators.toKeyValue { } cfg.settings); | ||
in | ||
{ | ||
options.services.swapspace = { | ||
enable = mkEnableOption "Swapspace, a dynamic swap space manager"; | ||
package = mkPackageOption pkgs "swapspace" { }; | ||
extraArgs = mkOption { | ||
type = types.str; | ||
default = ""; | ||
example = "-P -v"; | ||
description = "Any extra arguments to pass to swapspace"; | ||
}; | ||
settings = mkOption { | ||
type = types.submodule { | ||
options = { | ||
swappath = mkOption { | ||
type = types.str; | ||
default = "/var/lib/swapspace"; | ||
description = "Location where swapspace may create and delete swapfiles"; | ||
}; | ||
lower_freelimit = mkOption { | ||
type = types.ints.between 0 99; | ||
default = 20; | ||
description = "Lower free-space threshold: if the percentage of free space drops below this number, additional swapspace is allocated"; | ||
}; | ||
upper_freelimit = mkOption { | ||
type = types.ints.between 0 100; | ||
default = 60; | ||
description = "Upper free-space threshold: if the percentage of free space exceeds this number, swapspace will attempt to free up swapspace"; | ||
}; | ||
freetarget = mkOption { | ||
type = types.ints.between 2 99; | ||
default = 30; | ||
description = '' | ||
Percentage of free space swapspace should aim for when adding swapspace. | ||
This should fall somewhere between lower_freelimit and upper_freelimit. | ||
''; | ||
}; | ||
min_swapsize = mkOption { | ||
type = types.str; | ||
default = "4m"; | ||
description = "Smallest allowed size for individual swapfiles"; | ||
}; | ||
max_swapsize = mkOption { | ||
type = types.str; | ||
default = "2t"; | ||
description = "Greatest allowed size for individual swapfiles"; | ||
}; | ||
cooldown = mkOption { | ||
type = types.ints.unsigned; | ||
default = 600; | ||
description = '' | ||
Duration (roughly in seconds) of the moratorium on swap allocation that is instated if disk space runs out, or the cooldown time after a new swapfile is successfully allocated before swapspace will consider deallocating swap space again. | ||
The default cooldown period is about 10 minutes. | ||
''; | ||
}; | ||
buffer_elasticity = mkOption { | ||
type = types.ints.between 0 100; | ||
default = 30; | ||
description = ''Percentage of buffer space considered to be "free"''; | ||
}; | ||
cache_elasticity = mkOption { | ||
type = types.ints.between 0 100; | ||
default = 80; | ||
description = ''Percentage of cache space considered to be "free"''; | ||
}; | ||
}; | ||
}; | ||
default = { }; | ||
description = '' | ||
Config file for swapspace. | ||
See the options here: <https://github.com/Tookmund/Swapspace/blob/master/swapspace.conf> | ||
''; | ||
}; | ||
}; | ||
|
||
config = lib.mkIf cfg.enable { | ||
systemd.tmpfiles.rules = [ "d '${cfg.settings.swappath}' 0700 - - - - " ]; | ||
environment.systemPackages = [ cfg.package ]; | ||
systemd.services.swapspace = { | ||
after = [ | ||
"local-fs.target" | ||
"swap.target" | ||
]; | ||
requires = [ | ||
"local-fs.target" | ||
"swap.target" | ||
]; | ||
wantedBy = [ "multi-user.target" ]; | ||
documentation = [ "man:swapspace(8)" ]; | ||
description = "Swapspace, a dynamic swap space manager"; | ||
serviceConfig = { | ||
ExecStart = "${lib.getExe cfg.package} -c ${configFile} ${cfg.extraArgs}"; | ||
}; | ||
}; | ||
}; | ||
|
||
meta = { | ||
maintainers = with lib.maintainers; [ | ||
Luflosi | ||
phanirithvij | ||
]; | ||
}; | ||
} |