2023-07-01 19:02:01 +02:00
|
|
|
{ diskoLib, config, options, lib, parent, device, ... }:
|
2023-01-28 16:19:13 +01:00
|
|
|
{
|
|
|
|
|
options = {
|
|
|
|
|
type = lib.mkOption {
|
|
|
|
|
type = lib.types.enum [ "swap" ];
|
|
|
|
|
internal = true;
|
|
|
|
|
description = "Type";
|
|
|
|
|
};
|
2023-07-01 19:02:01 +02:00
|
|
|
device = lib.mkOption {
|
|
|
|
|
type = lib.types.str;
|
|
|
|
|
default = device;
|
|
|
|
|
description = "Device";
|
|
|
|
|
};
|
2023-01-28 16:19:13 +01:00
|
|
|
randomEncryption = lib.mkOption {
|
|
|
|
|
type = lib.types.bool;
|
|
|
|
|
default = false;
|
|
|
|
|
description = "Whether to randomly encrypt the swap";
|
|
|
|
|
};
|
2023-06-07 13:42:39 +02:00
|
|
|
_parent = lib.mkOption {
|
|
|
|
|
internal = true;
|
|
|
|
|
default = parent;
|
|
|
|
|
};
|
2023-01-28 16:19:13 +01:00
|
|
|
_meta = lib.mkOption {
|
|
|
|
|
internal = true;
|
|
|
|
|
readOnly = true;
|
|
|
|
|
type = lib.types.functionTo diskoLib.jsonType;
|
2023-06-06 13:32:47 +02:00
|
|
|
default = _dev: { };
|
2023-01-28 16:19:13 +01:00
|
|
|
description = "Metadata";
|
|
|
|
|
};
|
|
|
|
|
_create = diskoLib.mkCreateOption {
|
|
|
|
|
inherit config options;
|
2023-07-01 19:02:01 +02:00
|
|
|
default = ''
|
|
|
|
|
mkswap ${config.device}
|
2023-01-28 16:19:13 +01:00
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
_mount = diskoLib.mkMountOption {
|
|
|
|
|
inherit config options;
|
2023-07-01 19:02:01 +02:00
|
|
|
default = {
|
|
|
|
|
fs.${config.device} = ''
|
|
|
|
|
if ! swapon --show | grep -q '^${config.device} '; then
|
|
|
|
|
swapon ${config.device}
|
2023-01-28 16:19:13 +01:00
|
|
|
fi
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
_config = lib.mkOption {
|
|
|
|
|
internal = true;
|
|
|
|
|
readOnly = true;
|
2023-07-01 19:02:01 +02:00
|
|
|
default = [{
|
2023-01-28 16:19:13 +01:00
|
|
|
swapDevices = [{
|
2023-07-01 19:02:01 +02:00
|
|
|
device = config.device;
|
2023-02-07 15:37:12 +00:00
|
|
|
randomEncryption = config.randomEncryption;
|
2023-01-28 16:19:13 +01:00
|
|
|
}];
|
|
|
|
|
}];
|
|
|
|
|
description = "NixOS configuration";
|
|
|
|
|
};
|
|
|
|
|
_pkgs = lib.mkOption {
|
|
|
|
|
internal = true;
|
|
|
|
|
readOnly = true;
|
|
|
|
|
type = lib.types.functionTo (lib.types.listOf lib.types.package);
|
|
|
|
|
default = pkgs: [ pkgs.gnugrep pkgs.util-linux ];
|
|
|
|
|
description = "Packages";
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
}
|