nixos/services.bees: remove with lib;
This commit is contained in:
parent
5a7fba4027
commit
a2e269bc37
@ -1,15 +1,12 @@
|
|||||||
{ config, lib, pkgs, ... }:
|
{ config, lib, pkgs, ... }:
|
||||||
|
|
||||||
with lib;
|
|
||||||
|
|
||||||
let
|
let
|
||||||
|
|
||||||
cfg = config.services.beesd;
|
cfg = config.services.beesd;
|
||||||
|
|
||||||
logLevels = { emerg = 0; alert = 1; crit = 2; err = 3; warning = 4; notice = 5; info = 6; debug = 7; };
|
logLevels = { emerg = 0; alert = 1; crit = 2; err = 3; warning = 4; notice = 5; info = 6; debug = 7; };
|
||||||
|
|
||||||
fsOptions = with types; {
|
fsOptions = with lib.types; {
|
||||||
options.spec = mkOption {
|
options.spec = lib.mkOption {
|
||||||
type = str;
|
type = str;
|
||||||
description = ''
|
description = ''
|
||||||
Description of how to identify the filesystem to be duplicated by this
|
Description of how to identify the filesystem to be duplicated by this
|
||||||
@ -25,8 +22,8 @@ let
|
|||||||
'';
|
'';
|
||||||
example = "LABEL=MyBulkDataDrive";
|
example = "LABEL=MyBulkDataDrive";
|
||||||
};
|
};
|
||||||
options.hashTableSizeMB = mkOption {
|
options.hashTableSizeMB = lib.mkOption {
|
||||||
type = types.addCheck types.int (n: mod n 16 == 0);
|
type = lib.types.addCheck lib.types.int (n: mod n 16 == 0);
|
||||||
default = 1024; # 1GB; default from upstream beesd script
|
default = 1024; # 1GB; default from upstream beesd script
|
||||||
description = ''
|
description = ''
|
||||||
Hash table size in MB; must be a multiple of 16.
|
Hash table size in MB; must be a multiple of 16.
|
||||||
@ -40,13 +37,13 @@ let
|
|||||||
will recognize only aligned duplicate blocks of 16KB.
|
will recognize only aligned duplicate blocks of 16KB.
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
options.verbosity = mkOption {
|
options.verbosity = lib.mkOption {
|
||||||
type = types.enum (attrNames logLevels ++ attrValues logLevels);
|
type = lib.types.enum (lib.attrNames logLevels ++ lib.attrValues logLevels);
|
||||||
apply = v: if isString v then logLevels.${v} else v;
|
apply = v: if lib.isString v then logLevels.${v} else v;
|
||||||
default = "info";
|
default = "info";
|
||||||
description = "Log verbosity (syslog keyword/level).";
|
description = "Log verbosity (syslog keyword/level).";
|
||||||
};
|
};
|
||||||
options.workDir = mkOption {
|
options.workDir = lib.mkOption {
|
||||||
type = str;
|
type = str;
|
||||||
default = ".beeshome";
|
default = ".beeshome";
|
||||||
description = ''
|
description = ''
|
||||||
@ -54,13 +51,13 @@ let
|
|||||||
the hash table will be stored.
|
the hash table will be stored.
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
options.extraOptions = mkOption {
|
options.extraOptions = lib.mkOption {
|
||||||
type = listOf str;
|
type = listOf str;
|
||||||
default = [ ];
|
default = [ ];
|
||||||
description = ''
|
description = ''
|
||||||
Extra command-line options passed to the daemon. See upstream bees documentation.
|
Extra command-line options passed to the daemon. See upstream bees documentation.
|
||||||
'';
|
'';
|
||||||
example = literalExpression ''
|
example = lib.literalExpression ''
|
||||||
[ "--thread-count" "4" ]
|
[ "--thread-count" "4" ]
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
@ -70,11 +67,11 @@ in
|
|||||||
{
|
{
|
||||||
|
|
||||||
options.services.beesd = {
|
options.services.beesd = {
|
||||||
filesystems = mkOption {
|
filesystems = lib.mkOption {
|
||||||
type = with types; attrsOf (submodule fsOptions);
|
type = with lib.types; attrsOf (submodule fsOptions);
|
||||||
description = "BTRFS filesystems to run block-level deduplication on.";
|
description = "BTRFS filesystems to run block-level deduplication on.";
|
||||||
default = { };
|
default = { };
|
||||||
example = literalExpression ''
|
example = lib.literalExpression ''
|
||||||
{
|
{
|
||||||
root = {
|
root = {
|
||||||
spec = "LABEL=root";
|
spec = "LABEL=root";
|
||||||
@ -87,8 +84,8 @@ in
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
config = {
|
config = {
|
||||||
systemd.services = mapAttrs'
|
systemd.services = lib.mapAttrs'
|
||||||
(name: fs: nameValuePair "beesd@${name}" {
|
(name: fs: lib.nameValuePair "beesd@${name}" {
|
||||||
description = "Block-level BTRFS deduplication for %i";
|
description = "Block-level BTRFS deduplication for %i";
|
||||||
after = [ "sysinit.target" ];
|
after = [ "sysinit.target" ];
|
||||||
|
|
||||||
@ -100,11 +97,11 @@ in
|
|||||||
"idxSizeMB=${toString fs.hashTableSizeMB}"
|
"idxSizeMB=${toString fs.hashTableSizeMB}"
|
||||||
"workDir=${fs.workDir}"
|
"workDir=${fs.workDir}"
|
||||||
];
|
];
|
||||||
configOptsStr = escapeShellArgs configOpts;
|
configOptsStr = lib.escapeShellArgs configOpts;
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
# Values from https://github.com/Zygo/bees/blob/v0.6.5/scripts/beesd@.service.in
|
# Values from https://github.com/Zygo/bees/blob/v0.6.5/scripts/beesd@.service.in
|
||||||
ExecStart = "${pkgs.bees}/bin/bees-service-wrapper run ${configOptsStr} -- --no-timestamps ${escapeShellArgs fs.extraOptions}";
|
ExecStart = "${pkgs.bees}/bin/bees-service-wrapper run ${configOptsStr} -- --no-timestamps ${lib.escapeShellArgs fs.extraOptions}";
|
||||||
ExecStopPost = "${pkgs.bees}/bin/bees-service-wrapper cleanup ${configOptsStr}";
|
ExecStopPost = "${pkgs.bees}/bin/bees-service-wrapper cleanup ${configOptsStr}";
|
||||||
CPUAccounting = true;
|
CPUAccounting = true;
|
||||||
CPUSchedulingPolicy = "batch";
|
CPUSchedulingPolicy = "batch";
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user