nixos/swapspace: init module

Signed-off-by: phanirithvij <phanirithvij2000@gmail.com>
Co-authored-by: Luflosi <luflosi@luflosi.de>
(cherry picked from commit 80ea320fe7)
This commit is contained in:
phanirithvij 2024-10-14 22:47:34 +05:30 committed by Marco Rebhan
parent ee8d16654c
commit f12598eff2
No known key found for this signature in database
3 changed files with 123 additions and 0 deletions

View File

@ -192,6 +192,8 @@ The pre-existing [services.ankisyncd](#opt-services.ankisyncd.enable) has been m
- [Suwayomi Server](https://github.com/Suwayomi/Suwayomi-Server), a free and open source manga reader server that runs extensions built for [Tachiyomi](https://tachiyomi.org). Available as [services.suwayomi-server](#opt-services.suwayomi-server.enable). - [Suwayomi Server](https://github.com/Suwayomi/Suwayomi-Server), a free and open source manga reader server that runs extensions built for [Tachiyomi](https://tachiyomi.org). Available as [services.suwayomi-server](#opt-services.suwayomi-server.enable).
- [Swapspace](https://github.com/Tookmund/Swapspace), a dynamic swap space manager, turns your unused free space into swap automatically. Available as [services.swapspace](#opt-services.swapspace.enable).
- [TigerBeetle](https://tigerbeetle.com/), a distributed financial accounting database designed for mission critical safety and performance. Available as [services.tigerbeetle](#opt-services.tigerbeetle.enable). - [TigerBeetle](https://tigerbeetle.com/), a distributed financial accounting database designed for mission critical safety and performance. Available as [services.tigerbeetle](#opt-services.tigerbeetle.enable).
- [transfer-sh](https://github.com/dutchcoders/transfer.sh), a tool that supports easy and fast file sharing from the command-line. Available as [services.transfer-sh](#opt-services.transfer-sh.enable). - [transfer-sh](https://github.com/dutchcoders/transfer.sh), a tool that supports easy and fast file sharing from the command-line. Available as [services.transfer-sh](#opt-services.transfer-sh.enable).

View File

@ -1306,6 +1306,7 @@
./services/system/nscd.nix ./services/system/nscd.nix
./services/system/saslauthd.nix ./services/system/saslauthd.nix
./services/system/self-deploy.nix ./services/system/self-deploy.nix
./services/system/swapspace.nix
./services/system/systembus-notify.nix ./services/system/systembus-notify.nix
./services/system/systemd-lock-handler.nix ./services/system/systemd-lock-handler.nix
./services/system/uptimed.nix ./services/system/uptimed.nix

View File

@ -0,0 +1,120 @@
{
config,
lib,
pkgs,
utils,
...
}:
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.listOf 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 {
environment.systemPackages = [ cfg.package ];
systemd.packages = [ cfg.package ];
systemd.services.swapspace = {
wantedBy = [ "multi-user.target" ];
serviceConfig = {
ExecStart = [
""
"${lib.getExe cfg.package} -c ${configFile} ${utils.escapeSystemdExecArgs cfg.extraArgs}"
];
};
};
systemd.tmpfiles.settings.swapspace = {
${cfg.settings.swappath}.d = {
mode = "0700";
};
};
};
meta = {
maintainers = with lib.maintainers; [
Luflosi
phanirithvij
];
};
}