I propose these as for know suggested changes for interface, if it gets more than 5 upvote I attempt to make it
I didn’t check for spell errors, syntax errors, lint or any other thing yet, but I think it’s a good start,
All sort of suggestions is welcomed, suggestions to improve, nix mistake or better way to do things, …
@TLATER @nrdxp @YorikSar @ElvishJerricco @Solene @Sid
perDevOptions = {
options = {
memoryPercent = mkOption { # (0,100)
default = 50;
example = 90;
type = types.int;
description = lib.mdDoc ''
Maximum total amount of memory that can be stored in the zram swap devices
(as a percentage of your total memory). Defaults to 1/2 of your total
RAM. Run `zramctl` to check how good your zram memory device is compressed.
This doesn't define how much memory will be used by the zram swap devices.
'';
};
memoryMax = mkOption { # (0,maxRam)
default = null;
example = 4000000000;
type = with types; nullOr int;
description = lib.mdDoc ''
Maximum total amount of memory (in bytes) that can be stored in the zram
swap devices.
This doesn't define how much memory will be used by the zram swap devices.
default is null which equals to memory percent as the only limit
'';
};
priority = mkOption { # 5: warning if any swap and less than disk swap
# todo: same warning for other manual swaps as well
default = 5;
type = types.int;
description = lib.mdDoc ''
Priority of the zram swap devices. It should be a number higher than
the priority of your disk-based swap devices (so that the system will
fill the zram swap devices before falling back to disk swap).
'';
};
algorithm = mkOption {
default = "zstd";
example = "lz4";
type = with types; either (enum [ "lzo" "lz4" "zstd" "lzo-rle" "lz4hc" "842" ]) str;
description = lib.mdDoc ''
Compression algorithm. `lzo` has good compression,
but is slow. `lz4` has bad compression, but is fast.
`zstd` is both good compression and fast, but requires newer kernel.
You can check what other algorithms are supported by your zram device with
{command}`cat /sys/class/block/zram*/comp_algorithm` (this command shows,
per zram device available algorithms, therefore you can see the working algorithm
of each zram device wrapped in brackets)
'';
};
};
};
options = {
zramSwap = {
enable = mkOption {
default = false;
type = types.bool;
description = lib.mdDoc ''
Enable in-memory compressed devices and swap space provided by the zram
kernel module.
See [
https://www.kernel.org/doc/Documentation/blockdev/zram.txt
](https://www.kernel.org/doc/Documentation/blockdev/zram.txt).
'';
};
swapCount = mkOption {
default = 1;
example = 0;
type = types.int;
description = lib.mdDoc ''
Number of zram devices to be used as swap. Must be
`<= zramSwap.devCount`; default and recommended is 1.
'';
};
devCount = mkOption { #(if null equal to swapCount) (swapCount,upperlimit)
default = null;
example = 1;
type = with types; nullOr int;
description = lib.mdDoc ''
Number of zram device(s) to create.
Default is null which means, set equal to `zramSwap.swapCount`
See also
`zramSwap.swapCount`
'';
};
swapConfig = mkOption (perDevOptions ++
{
useAsSwap = mkOption {
default = false;
example = true;
type = types.bool;
description = lib.mdDoc ''
Make the zram device to be used as swap memory.
By default, explicitly defined zram devices wouldn't be
used as ram, if defined
'';
};
}
);
device = mkOption {
type = types.attrsOf (types.submodule perDevOptions);
description = lib.mdDoc ''
Configuration options for zram device(s)
'';
example = literalExpression ''
{
"2" = {
memoryPercent = 10;
priority = 4;
};
}
'';
};
};
};
perDevOptions would be defined in let section
by refrence, original interface
options = {
zramSwap = {
enable = mkOption {
default = false;
type = types.bool;
description = lib.mdDoc ''
Enable in-memory compressed devices and swap space provided by the zram
kernel module.
See [
https://www.kernel.org/doc/Documentation/blockdev/zram.txt
](https://www.kernel.org/doc/Documentation/blockdev/zram.txt).
'';
};
numDevices = mkOption {
default = 1;
type = types.int;
description = lib.mdDoc ''
Number of zram devices to create. See also
`zramSwap.swapDevices`
'';
};
swapDevices = mkOption {
default = null;
example = 1;
type = with types; nullOr int;
description = lib.mdDoc ''
Number of zram devices to be used as swap. Must be
`<= zramSwap.numDevices`.
Default is same as `zramSwap.numDevices`, recommended is 1.
'';
};
memoryPercent = mkOption {
default = 50;
type = types.int;
description = lib.mdDoc ''
Maximum total amount of memory that can be stored in the zram swap devices
(as a percentage of your total memory). Defaults to 1/2 of your total
RAM. Run `zramctl` to check how good memory is compressed.
This doesn't define how much memory will be used by the zram swap devices.
'';
};
memoryMax = mkOption {
default = null;
type = with types; nullOr int;
description = lib.mdDoc ''
Maximum total amount of memory (in bytes) that can be stored in the zram
swap devices.
This doesn't define how much memory will be used by the zram swap devices.
'';
};
priority = mkOption {
default = 5;
type = types.int;
description = lib.mdDoc ''
Priority of the zram swap devices. It should be a number higher than
the priority of your disk-based swap devices (so that the system will
fill the zram swap devices before falling back to disk swap).
'';
};
algorithm = mkOption {
default = "zstd";
example = "lz4";
type = with types; either (enum [ "lzo" "lz4" "zstd" ]) str;
description = lib.mdDoc ''
Compression algorithm. `lzo` has good compression,
but is slow. `lz4` has bad compression, but is fast.
`zstd` is both good compression and fast, but requires newer kernel.
You can check what other algorithms are supported by your zram device with
{command}`cat /sys/class/block/zram*/comp_algorithm`
'';
};
};
};