update to 0.16.2
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Jeffrey C. Ollie 2023-11-03 12:19:05 -05:00
parent 081a664fac
commit 25ddd648bc
Signed by: jeff
GPG key ID: 6F86035A6D97044E
2 changed files with 376 additions and 367 deletions

View file

@ -20,11 +20,11 @@
}, },
"nixpkgs": { "nixpkgs": {
"locked": { "locked": {
"lastModified": 1697851979, "lastModified": 1698846319,
"narHash": "sha256-lJ8k4qkkwdvi+t/Xc6Fn74kUuobpu9ynPGxNZR6OwoA=", "narHash": "sha256-4jyW/dqFBVpWFnhl0nvP6EN4lP7/ZqPxYRjl6var0Oc=",
"owner": "NixOS", "owner": "NixOS",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "5550a85a087c04ddcace7f892b0bdc9d8bb080c8", "rev": "34bdaaf1f0b7fb6d9091472edc968ff10a8c2857",
"type": "github" "type": "github"
}, },
"original": { "original": {

137
flake.nix
View file

@ -9,21 +9,24 @@
url = "github:numtide/flake-utils"; url = "github:numtide/flake-utils";
}; };
}; };
outputs = { self, nixpkgs, flake-utils, ... }@inputs: outputs = {
self,
nixpkgs,
flake-utils,
...
} @ inputs:
flake-utils.lib.eachDefaultSystem flake-utils.lib.eachDefaultSystem
(system: (
let system: let
pkgs = import nixpkgs { pkgs = import nixpkgs {
inherit system; inherit system;
}; };
in in {
{
packages = { packages = {
restic = restic = let
let
pname = "restic"; pname = "restic";
version = "0.16.1"; version = "0.16.2";
hash = "sha256-sMxOZEnZr2UdhmwLXQnggQzw+pXcoWmqqADlQ0yDhj8="; hash = "sha256-Qrbg8/f1ne+7c+mnUc/8CoZBjiGLohJXnu0cnc0pT4g=";
vendorHash = "sha256-Ctg6bln5kzGs7gDLo9zUpsbSybKOtHFuHvHG3cxCfac="; vendorHash = "sha256-Ctg6bln5kzGs7gDLo9zUpsbSybKOtHFuHvHG3cxCfac=";
in in
pkgs.buildGoModule { pkgs.buildGoModule {
@ -45,7 +48,7 @@
./0001-Skip-testing-restore-with-permission-failure.patch ./0001-Skip-testing-restore-with-permission-failure.patch
]; ];
subPackages = [ "cmd/restic" ]; subPackages = ["cmd/restic"];
nativeBuildInputs = [ nativeBuildInputs = [
pkgs.installShellFiles pkgs.installShellFiles
@ -58,14 +61,17 @@
# rm cmd/restic/integration_fuse_test.go # rm cmd/restic/integration_fuse_test.go
''; '';
postInstall = '' postInstall =
''
wrapProgram $out/bin/restic --prefix PATH : '${pkgs.rclone}/bin' wrapProgram $out/bin/restic --prefix PATH : '${pkgs.rclone}/bin'
'' + pkgs.lib.optionalString (pkgs.stdenv.hostPlatform == pkgs.stdenv.buildPlatform) '' ''
+ pkgs.lib.optionalString (pkgs.stdenv.hostPlatform == pkgs.stdenv.buildPlatform) ''
$out/bin/restic generate \ $out/bin/restic generate \
--bash-completion restic.bash \ --bash-completion restic.bash \
--fish-completion restic.fish \
--zsh-completion restic.zsh \ --zsh-completion restic.zsh \
--man . --man .
installShellCompletion restic.{bash,zsh} installShellCompletion restic.{bash,fish,zsh}
installManPage *.1 installManPage *.1
''; '';
@ -74,7 +80,7 @@
description = "A backup program that is fast, efficient and secure"; description = "A backup program that is fast, efficient and secure";
platforms = platforms.linux ++ platforms.darwin; platforms = platforms.linux ++ platforms.darwin;
license = licenses.bsd2; license = licenses.bsd2;
maintainers = [ maintainers.mbrgm ]; maintainers = [maintainers.mbrgm];
}; };
}; };
@ -108,22 +114,26 @@
"TZ=UTC" "TZ=UTC"
"SSL_CERT_FILE=${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt" "SSL_CERT_FILE=${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt"
]; ];
ExposedPorts = { }; ExposedPorts = {};
Volumes = { Volumes = {
"/cache" = { }; "/cache" = {};
}; };
}; };
}; };
}; };
} }
) // { )
// {
nixosModules = { nixosModules = {
restic = { config, lib, pkgs, ... }: restic = {
let config,
lib,
pkgs,
...
}: let
cfg = config.restic; cfg = config.restic;
package = self.packages.${pkgs.system}.restic; package = self.packages.${pkgs.system}.restic;
in in {
{
options = { options = {
restic = lib.options.mkOption { restic = lib.options.mkOption {
type = lib.types.submodule { type = lib.types.submodule {
@ -197,11 +207,11 @@
}; };
excludes = lib.options.mkOption { excludes = lib.options.mkOption {
type = lib.types.listOf lib.types.str; type = lib.types.listOf lib.types.str;
default = [ ]; default = [];
}; };
paths = lib.options.mkOption { paths = lib.options.mkOption {
type = lib.types.listOf lib.types.str; type = lib.types.listOf lib.types.str;
default = [ ]; default = [];
}; };
preCommand = lib.options.mkOption { preCommand = lib.options.mkOption {
type = lib.types.lines; type = lib.types.lines;
@ -220,28 +230,27 @@
}; };
}; };
config = config = let
let bucket =
{
bucket = {
"b2" = cfg.b2.bucket; "b2" = cfg.b2.bucket;
"azure" = builtins.replaceStrings [ "." ] [ "-" ] "${config.networking.hostName}.${config.networking.domain}"; "azure" = builtins.replaceStrings ["."] ["-"] "${config.networking.hostName}.${config.networking.domain}";
}.${cfg.storage}; }
.${cfg.storage};
directory = { directory =
{
"b2" = "${config.networking.hostName}.${config.networking.domain}"; "b2" = "${config.networking.hostName}.${config.networking.domain}";
"azure" = "/"; "azure" = "/";
}.${cfg.storage}; }
.${cfg.storage};
in in
lib.mkIf cfg.enable { lib.mkIf cfg.enable {
environment.systemPackages = [ environment.systemPackages = [
package package
]; ];
systemd.services.restic = systemd.services.restic = let
let
curlOptions = "--fail --silent --show-error --max-time 10 --retry 5"; curlOptions = "--fail --silent --show-error --max-time 10 --retry 5";
hcPayload = hcPayload =
if cfg.healthcheck.enable if cfg.healthcheck.enable
@ -254,20 +263,18 @@
name = "${config.networking.hostName}.${config.networking.domain}"; name = "${config.networking.hostName}.${config.networking.domain}";
timeout = cfg.healthcheck.timeout; timeout = cfg.healthcheck.timeout;
grace = cfg.healthcheck.grace; grace = cfg.healthcheck.grace;
unique = [ "name" ]; unique = ["name"];
channels = "*"; channels = "*";
} }
) )
) )
else else null;
null;
hcSetup = hcSetup =
if cfg.healthcheck.enable if cfg.healthcheck.enable
then '' then ''
HC_URL=''$(${pkgs.curl}/bin/curl ${curlOptions} --request POST --header 'Content-Type: application/json' --header "X-Api-Key: ''$(<${cfg.healthcheck.apiKeyFile})" --data @${hcPayload} "${cfg.healthcheck.apiUrl}" | ${pkgs.jq}/bin/jq -r .ping_url) HC_URL=''$(${pkgs.curl}/bin/curl ${curlOptions} --request POST --header 'Content-Type: application/json' --header "X-Api-Key: ''$(<${cfg.healthcheck.apiKeyFile})" --data @${hcPayload} "${cfg.healthcheck.apiUrl}" | ${pkgs.jq}/bin/jq -r .ping_url)
'' ''
else else "";
"";
hcStart = hcStart =
if cfg.healthcheck.enable if cfg.healthcheck.enable
then '' then ''
@ -276,8 +283,7 @@
${pkgs.curl}/bin/curl ${curlOptions} --output /dev/null "''${HC_URL}/start" || true ${pkgs.curl}/bin/curl ${curlOptions} --output /dev/null "''${HC_URL}/start" || true
fi fi
'' ''
else else "";
"";
hcStop = hcStop =
if cfg.healthcheck.enable if cfg.healthcheck.enable
then '' then ''
@ -286,15 +292,17 @@
${pkgs.curl}/bin/curl ${curlOptions} --output /dev/null "''${HC_URL}" || true ${pkgs.curl}/bin/curl ${curlOptions} --output /dev/null "''${HC_URL}" || true
fi fi
'' ''
else else "";
"";
repositoryConfig = { repositoryConfig =
{
"b2" = "b2:${bucket}:${directory}"; "b2" = "b2:${bucket}:${directory}";
"azure" = "azure:${bucket}:${directory}"; "azure" = "azure:${bucket}:${directory}";
}.${cfg.storage}; }
.${cfg.storage};
resticConfig = '' resticConfig =
''
export RESTIC_CACHE_DIR=/var/cache/restic export RESTIC_CACHE_DIR=/var/cache/restic
export RESTIC_PASSWORD_FILE=${cfg.passwordFile} export RESTIC_PASSWORD_FILE=${cfg.passwordFile}
export RESTIC_REPOSITORY=${repositoryConfig} export RESTIC_REPOSITORY=${repositoryConfig}
@ -308,26 +316,27 @@
export AZURE_ACCOUNT_NAME='${cfg.azure.accountName}' export AZURE_ACCOUNT_NAME='${cfg.azure.accountName}'
export AZURE_ACCOUNT_KEY="''$(<${cfg.azure.accountKeyFile})" export AZURE_ACCOUNT_KEY="''$(<${cfg.azure.accountKeyFile})"
''; '';
}.${cfg.storage}; }
.${cfg.storage};
backupCommands = lib.strings.concatStringsSep "\n" backupCommands =
lib.strings.concatStringsSep "\n"
( (
map map
( (
backup: backup: let
let
oneFileSystem = oneFileSystem =
if backup.oneFileSystem if backup.oneFileSystem
then then ["--one-file-system"]
[ "--one-file-system" ] else [];
else excludes =
[ ]; map
excludes = map
( (
exclude: ''--exclude="${exclude}"'' exclude: ''--exclude="${exclude}"''
) )
backup.excludes; backup.excludes;
paths = map paths =
map
( (
path: ''"${path}"'' path: ''"${path}"''
) )
@ -335,8 +344,7 @@
arguments = lib.strings.concatStringsSep " " ( arguments = lib.strings.concatStringsSep " " (
oneFileSystem ++ excludes ++ paths oneFileSystem ++ excludes ++ paths
); );
in in ''
''
${backup.preCommand} ${backup.preCommand}
${package}/bin/restic backup ${arguments} ${package}/bin/restic backup ${arguments}
${backup.postCommand} ${backup.postCommand}
@ -344,7 +352,8 @@
) )
cfg.backups cfg.backups
); );
initCheck = { initCheck =
{
"b2" = '' "b2" = ''
export RCLONE_CONFIG=/dev/null export RCLONE_CONFIG=/dev/null
export RCLONE_CONFIG_B2_TYPE=b2 export RCLONE_CONFIG_B2_TYPE=b2
@ -379,9 +388,9 @@
${package}/bin/restic init ${package}/bin/restic init
fi fi
''; '';
}.${cfg.storage}; }
in .${cfg.storage};
{ in {
serviceConfig = { serviceConfig = {
Type = "oneshot"; Type = "oneshot";
CacheDirectory = "restic"; CacheDirectory = "restic";
@ -409,7 +418,7 @@
OnCalendar = "*-*-* 02:00:00"; OnCalendar = "*-*-* 02:00:00";
RandomizedDelaySec = "60m"; RandomizedDelaySec = "60m";
}; };
wantedBy = [ "multi-user.target" ]; wantedBy = ["multi-user.target"];
}; };
}; };
}; };