From 098fd77b3e86c8c3357f8ada01b62f4092fcf5ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Motiejus=20Jak=C5=A1tys?= Date: Thu, 5 Jan 2023 13:23:29 +0200 Subject: [PATCH] add snaplink I know snaplink should be put to the nix store, but currently I have no idea how to do it. --- configuration.nix | 1 + krops.nix | 3 +++ scripts/snaplink | 10 ++++++++++ 3 files changed, 14 insertions(+) create mode 100755 scripts/snaplink diff --git a/configuration.nix b/configuration.nix index 04cc01d..54d74d5 100644 --- a/configuration.nix +++ b/configuration.nix @@ -85,6 +85,7 @@ let ssh_pubkeys = { daily = 7; autosnap = true; autoprune = true; + post_snapshot_script = "/var/src/snaplink"; }; datasets."rpool/nixos/home".use_template = [ "prod" ]; datasets."rpool/nixos/var".use_template = [ "prod" ]; diff --git a/krops.nix b/krops.nix index dc60e1b..6a930b6 100644 --- a/krops.nix +++ b/krops.nix @@ -9,6 +9,9 @@ let { nixpkgs.symlink = "/root/.nix-defexpr/channels/nixos"; nixos-config.file = toString ./configuration.nix; + + # TODO: how to make this nix-managed? + snaplink.file = toString ./scripts/snaplink; secrets.pass = { dir = toString ./secrets; name = "hel1-a"; diff --git a/scripts/snaplink b/scripts/snaplink new file mode 100755 index 0000000..1250dab --- /dev/null +++ b/scripts/snaplink @@ -0,0 +1,10 @@ +#!/usr/bin/env bash +set -euo pipefail +_fatal() { >&2 echo "ERROR: $*"; exit 1; } +mountpoint=$(zfs list -H -t filesystem -o mountpoint "$SANOID_TARGET") +[[ -n "$mountpoint" ]] || _fatal "expected non-empty $SANOID_TARGET" +snap_path="$mountpoint/.zfs/snapshot/$SANOID_SNAPNAME" +[[ -d "$snap_path" ]] || _fatal "expected to find a directory in $snap_path" +link_path="$mountpoint/.snapshot-latest" +ln -sf "$snap_path" "$link_path" +>&2 printf "successfully created %s -> %s\n" "$link_path" "$snap_path"