9 cfg = config.services.swapspace;
16 configFile = pkgs.writeText "swapspace.conf" (lib.generators.toKeyValue { } cfg.settings);
19 options.services.swapspace = {
20 enable = mkEnableOption "Swapspace, a dynamic swap space manager";
21 package = mkPackageOption pkgs "swapspace" { };
22 extraArgs = mkOption {
23 type = types.listOf types.str;
29 description = "Any extra arguments to pass to swapspace";
32 type = types.submodule {
36 default = "/var/lib/swapspace";
37 description = "Location where swapspace may create and delete swapfiles";
39 lower_freelimit = mkOption {
40 type = types.ints.between 0 99;
42 description = "Lower free-space threshold: if the percentage of free space drops below this number, additional swapspace is allocated";
44 upper_freelimit = mkOption {
45 type = types.ints.between 0 100;
47 description = "Upper free-space threshold: if the percentage of free space exceeds this number, swapspace will attempt to free up swapspace";
49 freetarget = mkOption {
50 type = types.ints.between 2 99;
53 Percentage of free space swapspace should aim for when adding swapspace.
54 This should fall somewhere between lower_freelimit and upper_freelimit.
57 min_swapsize = mkOption {
60 description = "Smallest allowed size for individual swapfiles";
62 max_swapsize = mkOption {
65 description = "Greatest allowed size for individual swapfiles";
68 type = types.ints.unsigned;
71 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.
72 The default cooldown period is about 10 minutes.
75 buffer_elasticity = mkOption {
76 type = types.ints.between 0 100;
78 description = ''Percentage of buffer space considered to be "free"'';
80 cache_elasticity = mkOption {
81 type = types.ints.between 0 100;
83 description = ''Percentage of cache space considered to be "free"'';
89 Config file for swapspace.
90 See the options here: <https://github.com/Tookmund/Swapspace/blob/master/swapspace.conf>
95 config = lib.mkIf cfg.enable {
96 environment.systemPackages = [ cfg.package ];
97 systemd.packages = [ cfg.package ];
98 systemd.services.swapspace = {
99 wantedBy = [ "multi-user.target" ];
103 "${lib.getExe cfg.package} -c ${configFile} ${utils.escapeSystemdExecArgs cfg.extraArgs}"
107 systemd.tmpfiles.settings.swapspace = {
108 ${cfg.settings.swappath}.d = {
115 maintainers = with lib.maintainers; [