sanoid: fix sanoid.conf generation
This commit is contained in:
parent
c43e0f4873
commit
b62a093a58
|
@ -10,74 +10,51 @@ let
|
|||
description = "dataset/template options";
|
||||
};
|
||||
|
||||
# Default values from https://github.com/jimsalterjrs/sanoid/blob/master/sanoid.defaults.conf
|
||||
|
||||
commonOptions = {
|
||||
hourly = mkOption {
|
||||
description = "Number of hourly snapshots.";
|
||||
type = types.ints.unsigned;
|
||||
default = 48;
|
||||
type = with types; nullOr ints.unsigned;
|
||||
default = null;
|
||||
};
|
||||
|
||||
daily = mkOption {
|
||||
description = "Number of daily snapshots.";
|
||||
type = types.ints.unsigned;
|
||||
default = 90;
|
||||
type = with types; nullOr ints.unsigned;
|
||||
default = null;
|
||||
};
|
||||
|
||||
monthly = mkOption {
|
||||
description = "Number of monthly snapshots.";
|
||||
type = types.ints.unsigned;
|
||||
default = 6;
|
||||
type = with types; nullOr ints.unsigned;
|
||||
default = null;
|
||||
};
|
||||
|
||||
yearly = mkOption {
|
||||
description = "Number of yearly snapshots.";
|
||||
type = types.ints.unsigned;
|
||||
default = 0;
|
||||
type = with types; nullOr ints.unsigned;
|
||||
default = null;
|
||||
};
|
||||
|
||||
autoprune = mkOption {
|
||||
description = "Whether to automatically prune old snapshots.";
|
||||
type = types.bool;
|
||||
default = true;
|
||||
type = with types; nullOr bool;
|
||||
default = null;
|
||||
};
|
||||
|
||||
autosnap = mkOption {
|
||||
description = "Whether to automatically take snapshots.";
|
||||
type = types.bool;
|
||||
default = true;
|
||||
};
|
||||
|
||||
settings = mkOption {
|
||||
description = ''
|
||||
Free-form settings for this template/dataset. See
|
||||
<link xlink:href="https://github.com/jimsalterjrs/sanoid/blob/master/sanoid.defaults.conf"/>
|
||||
for allowed values.
|
||||
'';
|
||||
type = datasetSettingsType;
|
||||
type = with types; nullOr bool;
|
||||
default = null;
|
||||
};
|
||||
};
|
||||
|
||||
commonConfig = config: {
|
||||
settings = {
|
||||
hourly = mkDefault config.hourly;
|
||||
daily = mkDefault config.daily;
|
||||
monthly = mkDefault config.monthly;
|
||||
yearly = mkDefault config.yearly;
|
||||
autoprune = mkDefault config.autoprune;
|
||||
autosnap = mkDefault config.autosnap;
|
||||
};
|
||||
};
|
||||
|
||||
datasetOptions = {
|
||||
useTemplate = mkOption {
|
||||
datasetOptions = rec {
|
||||
use_template = mkOption {
|
||||
description = "Names of the templates to use for this dataset.";
|
||||
type = (types.listOf (types.enum (attrNames cfg.templates))) // {
|
||||
description = "list of template names";
|
||||
};
|
||||
type = types.listOf (types.enum (attrNames cfg.templates));
|
||||
default = [];
|
||||
};
|
||||
useTemplate = use_template;
|
||||
|
||||
recursive = mkOption {
|
||||
description = "Whether to recursively snapshot dataset children.";
|
||||
|
@ -85,19 +62,12 @@ let
|
|||
default = false;
|
||||
};
|
||||
|
||||
processChildrenOnly = mkOption {
|
||||
process_children_only = mkOption {
|
||||
description = "Whether to only snapshot child datasets if recursing.";
|
||||
type = types.bool;
|
||||
default = false;
|
||||
};
|
||||
};
|
||||
|
||||
datasetConfig = config: {
|
||||
settings = {
|
||||
use_template = mkDefault config.useTemplate;
|
||||
recursive = mkDefault config.recursive;
|
||||
process_children_only = mkDefault config.processChildrenOnly;
|
||||
};
|
||||
processChildrenOnly = process_children_only;
|
||||
};
|
||||
|
||||
# Extract pool names from configured datasets
|
||||
|
@ -109,11 +79,11 @@ let
|
|||
else generators.mkValueStringDefault {} v;
|
||||
|
||||
mkKeyValue = k: v: if v == null then ""
|
||||
else if k == "processChildrenOnly" then ""
|
||||
else if k == "useTemplate" then ""
|
||||
else generators.mkKeyValueDefault { inherit mkValueString; } "=" k v;
|
||||
in generators.toINI { inherit mkKeyValue; } cfg.settings;
|
||||
|
||||
configDir = pkgs.writeTextDir "sanoid.conf" configFile;
|
||||
|
||||
in {
|
||||
|
||||
# Interface
|
||||
|
@ -135,19 +105,21 @@ in {
|
|||
};
|
||||
|
||||
datasets = mkOption {
|
||||
type = types.attrsOf (types.submodule ({ config, ... }: {
|
||||
type = types.attrsOf (types.submodule ({config, options, ...}: {
|
||||
freeformType = datasetSettingsType;
|
||||
options = commonOptions // datasetOptions;
|
||||
config = mkMerge [ (commonConfig config) (datasetConfig config) ];
|
||||
config.use_template = mkAliasDefinitions (options.useTemplate or {});
|
||||
config.process_children_only = mkAliasDefinitions (options.processChildrenOnly or {});
|
||||
}));
|
||||
default = {};
|
||||
description = "Datasets to snapshot.";
|
||||
};
|
||||
|
||||
templates = mkOption {
|
||||
type = types.attrsOf (types.submodule ({ config, ... }: {
|
||||
type = types.attrsOf (types.submodule {
|
||||
freeformType = datasetSettingsType;
|
||||
options = commonOptions;
|
||||
config = commonConfig config;
|
||||
}));
|
||||
});
|
||||
default = {};
|
||||
description = "Templates for datasets.";
|
||||
};
|
||||
|
@ -177,8 +149,8 @@ in {
|
|||
|
||||
config = mkIf cfg.enable {
|
||||
services.sanoid.settings = mkMerge [
|
||||
(mapAttrs' (d: v: nameValuePair ("template_" + d) v.settings) cfg.templates)
|
||||
(mapAttrs (d: v: v.settings) cfg.datasets)
|
||||
(mapAttrs' (d: v: nameValuePair ("template_" + d) v) cfg.templates)
|
||||
(mapAttrs (d: v: v) cfg.datasets)
|
||||
];
|
||||
|
||||
systemd.services.sanoid = {
|
||||
|
@ -191,7 +163,7 @@ in {
|
|||
ExecStart = lib.escapeShellArgs ([
|
||||
"${pkgs.sanoid}/bin/sanoid"
|
||||
"--cron"
|
||||
"--configdir" configDir
|
||||
"--configdir" (pkgs.writeTextDir "sanoid.conf" configFile)
|
||||
] ++ cfg.extraArgs);
|
||||
ExecStopPost = map (pool: lib.escapeShellArgs [
|
||||
"+/run/booted-system/sw/bin/zfs" "unallow" "sanoid" pool
|
||||
|
|
|
@ -33,7 +33,7 @@ in {
|
|||
|
||||
autosnap = true;
|
||||
};
|
||||
datasets."pool/sanoid".useTemplate = [ "test" ];
|
||||
datasets."pool/sanoid".use_template = [ "test" ];
|
||||
extraArgs = [ "--verbose" ];
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue