selfhostblocks/modules/blocks/sanoid/docs/default.md
2026-04-27 23:12:41 +02:00

2.3 KiB

Sanoid Block

Defined in /modules/blocks/sanoid.nix:

{
  imports = [
    inputs.selfhostblocks.nixosModules.sanoid
  ];
}

Provider Contracts

This block provides the following contracts:

Usage

Sanoid uses templates to know when snapshots should be kept or pruned.

Default Template

Backup a dataset using the default Sanoid template:

{
  shb.zfs.pools.root.datasets.home = {
    path = "/home";
  };

  shb.sanoid.backup."root/home" = {
    request = shb.zfs.pools.root.datasets.home.datasetBackup.request;
  };
}

This uses the dataset backup contract which is exposed through the ZFS module's shb.zfs.pools.<name>.datasets.<name>.datasetBackup option.

Custom Template

Create a custom template and use it:

{
  shb.zfs.pools.root.datasets.home = {
    path = "/home";
  };

  services.sanoid.templates."yearly" = {
    hourly = 10;
    daily = 3;
    monthly = 3;
    yearly = 2;
  };

  shb.sanoid.backup."root/home" = {
    request = shb.zfs.pools.root.datasets.home.datasetBackup.request;
    template = "yearly";
  };
}

Note we use the upstream services.sanoid.templates option to define the templates.

Without contract

To backup a dataset that does not provide the dataset backup contract, we can just set the request manually:

{
  shb.zfs.pools.root.datasets.home = {
    path = "/home";
  };

  shb.sanoid.backup."root/home" = {
    request.dataset = "root/home";
  };
}

Note the attr name under the shb.sanoid.backup option does not set the dataset name.

Options Reference

id-prefix: blocks-sanoid-options-
list-id: selfhostblocks-blocks-sanoid-options
source: @OPTIONS_JSON@