Skip to content

Commit

Permalink
+ enable snapy
Browse files Browse the repository at this point in the history
  • Loading branch information
oluceps committed Feb 20, 2024
1 parent 14133c0 commit 55599da
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
15 changes: 15 additions & 0 deletions hosts/hastur/spec.nix
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,21 @@
# xserver.enable = true;
# xserver.displayManager.gdm.enable = true;
# xserver.desktopManager.gnome.enable = true;
snapy.instances = [
{
name = "persist";
source = "/persist";
keep = "2hr";
calendar = "*:0/3";
}
{
name = "var";
source = "/var";
keep = "2hr";
calendar = "*:0/3";
}
];

tailscale = { enable = true; openFirewall = true; };

dae.enable = true;
Expand Down
15 changes: 6 additions & 9 deletions modules/snapy.nix
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ in
};
keep = mkOption {
type = types.str;
default = "3day";
default = "3hr";
};
};
});
Expand Down Expand Up @@ -55,25 +55,22 @@ in
description = "${s.name} snapy daemon";
serviceConfig =
{
# DynamicUser = true;
User = "root";
ExecStart =
let btrfs = lib.getExe' pkgs.btrfs-progs "btrfs"; in
toString (pkgs.lib.getExe (pkgs.nuenv.writeScriptBin
{
name = "snapy";
script = ''
let date_format = "%Y-%m-%d_%H:%M:%S%z"
# take snapshot
date now | format date "%m-%d_%H:%M:%S" | ${btrfs} subvol snapshot -r ${s.source} $'${s.source}/.snapshots/($in)'
date now | format date $date_format | ${btrfs} subvol snapshot -r ${s.source} $'${s.source}/.snapshots/($in)'
date now
# rm out-dated
ls ${s.source}/.snapshots | filter { |i| ((date now) - $i.modified) > ${s.keep} } | each { |d| ${btrfs} sub del $d.name }
# clean outdated
ls ${s.source}/.snapshots | filter { |i| ((date now) - ($i.name | into datetime --format $date_format)) > ${s.keep} } | each { |d| ${btrfs} sub del $d.name }
'';
}));

# AmbientCapabilities = [ "CAP_SYS_ADMIN" "CAP_SYS_RESOURCE" "CAP_DAC_OVERRIDE" ];
# CapabilityBoundingSet = [ "CAP_SYS_ADMIN" "CAP_SYS_RESOURCE" "CAP_DAC_OVERRIDE" ];
};
};
})
Expand Down

0 comments on commit 55599da

Please sign in to comment.