mirror of
https://github.com/NixOS/nixpkgs.git
synced 2024-11-23 07:23:20 +00:00
nixos/services.sanoid: remove with lib;
This commit is contained in:
parent
dfb290a6c6
commit
4682ba9d88
@ -1,85 +1,82 @@
|
||||
{ config, lib, pkgs, ... }:
|
||||
|
||||
with lib;
|
||||
|
||||
let
|
||||
cfg = config.services.sanoid;
|
||||
|
||||
datasetSettingsType = with types;
|
||||
datasetSettingsType = with lib.types;
|
||||
(attrsOf (nullOr (oneOf [ str int bool (listOf str) ]))) // {
|
||||
description = "dataset/template options";
|
||||
};
|
||||
|
||||
commonOptions = {
|
||||
hourly = mkOption {
|
||||
hourly = lib.mkOption {
|
||||
description = "Number of hourly snapshots.";
|
||||
type = with types; nullOr ints.unsigned;
|
||||
type = with lib.types; nullOr ints.unsigned;
|
||||
default = null;
|
||||
};
|
||||
|
||||
daily = mkOption {
|
||||
daily = lib.mkOption {
|
||||
description = "Number of daily snapshots.";
|
||||
type = with types; nullOr ints.unsigned;
|
||||
type = with lib.types; nullOr ints.unsigned;
|
||||
default = null;
|
||||
};
|
||||
|
||||
monthly = mkOption {
|
||||
monthly = lib.mkOption {
|
||||
description = "Number of monthly snapshots.";
|
||||
type = with types; nullOr ints.unsigned;
|
||||
type = with lib.types; nullOr ints.unsigned;
|
||||
default = null;
|
||||
};
|
||||
|
||||
yearly = mkOption {
|
||||
yearly = lib.mkOption {
|
||||
description = "Number of yearly snapshots.";
|
||||
type = with types; nullOr ints.unsigned;
|
||||
type = with lib.types; nullOr ints.unsigned;
|
||||
default = null;
|
||||
};
|
||||
|
||||
autoprune = mkOption {
|
||||
autoprune = lib.mkOption {
|
||||
description = "Whether to automatically prune old snapshots.";
|
||||
type = with types; nullOr bool;
|
||||
type = with lib.types; nullOr bool;
|
||||
default = null;
|
||||
};
|
||||
|
||||
autosnap = mkOption {
|
||||
autosnap = lib.mkOption {
|
||||
description = "Whether to automatically take snapshots.";
|
||||
type = with types; nullOr bool;
|
||||
type = with lib.types; nullOr bool;
|
||||
default = null;
|
||||
};
|
||||
};
|
||||
|
||||
datasetOptions = rec {
|
||||
use_template = mkOption {
|
||||
use_template = lib.mkOption {
|
||||
description = "Names of the templates to use for this dataset.";
|
||||
type = types.listOf (types.str // {
|
||||
check = (types.enum (attrNames cfg.templates)).check;
|
||||
type = lib.types.listOf (lib.types.str // {
|
||||
check = (lib.types.enum (lib.attrNames cfg.templates)).check;
|
||||
description = "configured template name";
|
||||
});
|
||||
default = [ ];
|
||||
};
|
||||
useTemplate = use_template;
|
||||
|
||||
recursive = mkOption {
|
||||
recursive = lib.mkOption {
|
||||
description = ''
|
||||
Whether to recursively snapshot dataset children.
|
||||
You can also set this to `"zfs"` to handle datasets
|
||||
recursively in an atomic way without the possibility to
|
||||
override settings for child datasets.
|
||||
'';
|
||||
type = with types; oneOf [ bool (enum [ "zfs" ]) ];
|
||||
type = with lib.types; oneOf [ bool (enum [ "zfs" ]) ];
|
||||
default = false;
|
||||
};
|
||||
|
||||
process_children_only = mkOption {
|
||||
process_children_only = lib.mkOption {
|
||||
description = "Whether to only snapshot child datasets if recursing.";
|
||||
type = types.bool;
|
||||
type = lib.types.bool;
|
||||
default = false;
|
||||
};
|
||||
processChildrenOnly = process_children_only;
|
||||
};
|
||||
|
||||
# Extract unique dataset names
|
||||
datasets = unique (attrNames cfg.datasets);
|
||||
datasets = lib.unique (lib.attrNames cfg.datasets);
|
||||
|
||||
# Function to build "zfs allow" and "zfs unallow" commands for the
|
||||
# filesystems we've delegated permissions to.
|
||||
@ -88,23 +85,23 @@ let
|
||||
"-+/run/booted-system/sw/bin/zfs"
|
||||
zfsAction
|
||||
"sanoid"
|
||||
(concatStringsSep "," permissions)
|
||||
(lib.concatStringsSep "," permissions)
|
||||
dataset
|
||||
];
|
||||
|
||||
configFile =
|
||||
let
|
||||
mkValueString = v:
|
||||
if builtins.isList v then concatStringsSep "," v
|
||||
else generators.mkValueStringDefault { } v;
|
||||
if lib.isList v then lib.concatStringsSep "," v
|
||||
else lib.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;
|
||||
else lib.generators.mkKeyValueDefault { inherit mkValueString; } "=" k v;
|
||||
in
|
||||
generators.toINI { inherit mkKeyValue; } cfg.settings;
|
||||
lib.generators.toINI { inherit mkKeyValue; } cfg.settings;
|
||||
|
||||
in
|
||||
{
|
||||
@ -112,12 +109,12 @@ in
|
||||
# Interface
|
||||
|
||||
options.services.sanoid = {
|
||||
enable = mkEnableOption "Sanoid ZFS snapshotting service";
|
||||
enable = lib.mkEnableOption "Sanoid ZFS snapshotting service";
|
||||
|
||||
package = lib.mkPackageOption pkgs "sanoid" {};
|
||||
|
||||
interval = mkOption {
|
||||
type = types.str;
|
||||
interval = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
default = "hourly";
|
||||
example = "daily";
|
||||
description = ''
|
||||
@ -128,19 +125,19 @@ in
|
||||
'';
|
||||
};
|
||||
|
||||
datasets = mkOption {
|
||||
type = types.attrsOf (types.submodule ({ config, options, ... }: {
|
||||
datasets = lib.mkOption {
|
||||
type = lib.types.attrsOf (lib.types.submodule ({ config, options, ... }: {
|
||||
freeformType = datasetSettingsType;
|
||||
options = commonOptions // datasetOptions;
|
||||
config.use_template = modules.mkAliasAndWrapDefsWithPriority id (options.useTemplate or { });
|
||||
config.process_children_only = modules.mkAliasAndWrapDefsWithPriority id (options.processChildrenOnly or { });
|
||||
config.use_template = lib.modules.mkAliasAndWrapDefsWithPriority lib.id (options.useTemplate or { });
|
||||
config.process_children_only = lib.modules.mkAliasAndWrapDefsWithPriority lib.id (options.processChildrenOnly or { });
|
||||
}));
|
||||
default = { };
|
||||
description = "Datasets to snapshot.";
|
||||
};
|
||||
|
||||
templates = mkOption {
|
||||
type = types.attrsOf (types.submodule {
|
||||
templates = lib.mkOption {
|
||||
type = lib.types.attrsOf (lib.types.submodule {
|
||||
freeformType = datasetSettingsType;
|
||||
options = commonOptions;
|
||||
});
|
||||
@ -148,8 +145,8 @@ in
|
||||
description = "Templates for datasets.";
|
||||
};
|
||||
|
||||
settings = mkOption {
|
||||
type = types.attrsOf datasetSettingsType;
|
||||
settings = lib.mkOption {
|
||||
type = lib.types.attrsOf datasetSettingsType;
|
||||
description = ''
|
||||
Free-form settings written directly to the config file. See
|
||||
<https://github.com/jimsalterjrs/sanoid/blob/master/sanoid.defaults.conf>
|
||||
@ -157,8 +154,8 @@ in
|
||||
'';
|
||||
};
|
||||
|
||||
extraArgs = mkOption {
|
||||
type = types.listOf types.str;
|
||||
extraArgs = lib.mkOption {
|
||||
type = lib.types.listOf lib.types.str;
|
||||
default = [ ];
|
||||
example = [ "--verbose" "--readonly" "--debug" ];
|
||||
description = ''
|
||||
@ -171,10 +168,10 @@ in
|
||||
|
||||
# Implementation
|
||||
|
||||
config = mkIf cfg.enable {
|
||||
services.sanoid.settings = mkMerge [
|
||||
(mapAttrs' (d: v: nameValuePair ("template_" + d) v) cfg.templates)
|
||||
(mapAttrs (d: v: v) cfg.datasets)
|
||||
config = lib.mkIf cfg.enable {
|
||||
services.sanoid.settings = lib.mkMerge [
|
||||
(lib.mapAttrs' (d: v: lib.nameValuePair ("template_" + d) v) cfg.templates)
|
||||
(lib.mapAttrs (d: v: v) cfg.datasets)
|
||||
];
|
||||
|
||||
systemd.services.sanoid = {
|
||||
@ -201,5 +198,5 @@ in
|
||||
};
|
||||
};
|
||||
|
||||
meta.maintainers = with maintainers; [ lopsided98 ];
|
||||
meta.maintainers = with lib.maintainers; [ lopsided98 ];
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user