first
This commit is contained in:
parent
c07fe53f56
commit
2fb69448b2
4 changed files with 394 additions and 282 deletions
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
/result*
|
24
0001-Skip-testing-restore-with-permission-failure.patch
Normal file
24
0001-Skip-testing-restore-with-permission-failure.patch
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
From 8e6186be04e2819b6e3586e5d1aeb8a824e1979f Mon Sep 17 00:00:00 2001
|
||||||
|
From: Simon Bruder <simon@sbruder.de>
|
||||||
|
Date: Thu, 25 Feb 2021 09:20:51 +0100
|
||||||
|
Subject: [PATCH] Skip testing restore with permission failure
|
||||||
|
|
||||||
|
The test fails in sandboxed builds.
|
||||||
|
---
|
||||||
|
cmd/restic/integration_test.go | 1 +
|
||||||
|
1 file changed, 1 insertion(+)
|
||||||
|
|
||||||
|
diff --git a/cmd/restic/integration_test.go b/cmd/restic/integration_test.go
|
||||||
|
index 7d198d33..1588ccb1 100644
|
||||||
|
--- a/cmd/restic/integration_test.go
|
||||||
|
+++ b/cmd/restic/integration_test.go
|
||||||
|
@@ -1170,6 +1170,7 @@ func TestRestoreLatest(t *testing.T) {
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestRestoreWithPermissionFailure(t *testing.T) {
|
||||||
|
+ t.Skip("Skipping testing restore with permission failure")
|
||||||
|
env, cleanup := withTestEnvironment(t)
|
||||||
|
defer cleanup()
|
||||||
|
|
||||||
|
--
|
||||||
|
2.29.2
|
42
flake.lock
Normal file
42
flake.lock
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
{
|
||||||
|
"nodes": {
|
||||||
|
"flake-utils": {
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1676283394,
|
||||||
|
"narHash": "sha256-XX2f9c3iySLCw54rJ/CZs+ZK6IQy7GXNY4nSOyu2QG4=",
|
||||||
|
"owner": "numtide",
|
||||||
|
"repo": "flake-utils",
|
||||||
|
"rev": "3db36a8b464d0c4532ba1c7dda728f4576d6d073",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "numtide",
|
||||||
|
"repo": "flake-utils",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"nixpkgs": {
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1678470307,
|
||||||
|
"narHash": "sha256-OEeMUr3ueLIXyW/OaFUX5jUdimyQwMg/7e+/Q0gC/QE=",
|
||||||
|
"owner": "NixOS",
|
||||||
|
"repo": "nixpkgs",
|
||||||
|
"rev": "0c4800d579af4ed98ecc47d464a5e7b0870c4b1f",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"id": "nixpkgs",
|
||||||
|
"ref": "nixos-unstable",
|
||||||
|
"type": "indirect"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"root": {
|
||||||
|
"inputs": {
|
||||||
|
"flake-utils": "flake-utils",
|
||||||
|
"nixpkgs": "nixpkgs"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"root": "root",
|
||||||
|
"version": 7
|
||||||
|
}
|
93
flake.nix
93
flake.nix
|
@ -1,5 +1,5 @@
|
||||||
{
|
{
|
||||||
description = "openlens";
|
description = "Restic";
|
||||||
|
|
||||||
inputs = {
|
inputs = {
|
||||||
nixpkgs = {
|
nixpkgs = {
|
||||||
|
@ -16,19 +16,70 @@
|
||||||
pkgs = import nixpkgs {
|
pkgs = import nixpkgs {
|
||||||
inherit system;
|
inherit system;
|
||||||
};
|
};
|
||||||
arch = {
|
|
||||||
"x86_64-linux" = "amd64";
|
|
||||||
}.${system};
|
|
||||||
|
|
||||||
|
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
packages = { };
|
packages = {
|
||||||
|
restic =
|
||||||
|
let
|
||||||
|
pname = "restic";
|
||||||
|
version = "0.15.1";
|
||||||
|
sha256 = "sha256-KdPslVJHH+xdUuFfmLZumP2lHzkDrrAvpDaj38SuP8o=";
|
||||||
|
vendorSha256 = "sha256-oetaCiXWEBUEf382l4sjO0SCPxkoh+bMTgIf/qJTQms=";
|
||||||
|
in
|
||||||
|
pkgs.buildGoModule {
|
||||||
|
inherit pname version;
|
||||||
|
|
||||||
|
src = pkgs.fetchFromGitHub {
|
||||||
|
owner = "restic";
|
||||||
|
repo = "restic";
|
||||||
|
rev = "v${version}";
|
||||||
|
sha256 = sha256;
|
||||||
|
};
|
||||||
|
|
||||||
|
patches = [
|
||||||
|
# The TestRestoreWithPermissionFailure test fails in Nix’s build sandbox
|
||||||
|
./0001-Skip-testing-restore-with-permission-failure.patch
|
||||||
|
];
|
||||||
|
|
||||||
|
vendorSha256 = vendorSha256;
|
||||||
|
|
||||||
|
subPackages = [ "cmd/restic" ];
|
||||||
|
|
||||||
|
nativeBuildInputs = [ pkgs.installShellFiles pkgs.makeWrapper ];
|
||||||
|
|
||||||
|
passthru.tests.restic = pkgs.nixosTests.restic;
|
||||||
|
|
||||||
|
postPatch = ''
|
||||||
|
rm cmd/restic/integration_fuse_test.go
|
||||||
|
'';
|
||||||
|
|
||||||
|
postInstall = ''
|
||||||
|
wrapProgram $out/bin/restic --prefix PATH : '${pkgs.rclone}/bin'
|
||||||
|
'' + pkgs.lib.optionalString (pkgs.stdenv.hostPlatform == pkgs.stdenv.buildPlatform) ''
|
||||||
|
$out/bin/restic generate \
|
||||||
|
--bash-completion restic.bash \
|
||||||
|
--zsh-completion restic.zsh \
|
||||||
|
--man .
|
||||||
|
installShellCompletion restic.{bash,zsh}
|
||||||
|
installManPage *.1
|
||||||
|
'';
|
||||||
|
|
||||||
|
meta = with pkgs.lib; {
|
||||||
|
homepage = "https://restic.net";
|
||||||
|
description = "A backup program that is fast, efficient and secure";
|
||||||
|
platforms = platforms.linux ++ platforms.darwin;
|
||||||
|
license = licenses.bsd2;
|
||||||
|
maintainers = [ maintainers.mbrgm ];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
}
|
}
|
||||||
) // {
|
) // {
|
||||||
nixosModules.restic = { config, lib, pkgs, ... }:
|
nixosModules = {
|
||||||
|
restic = { config, lib, pkgs, ... }:
|
||||||
let
|
let
|
||||||
cfg = config.restic;
|
cfg = config.restic;
|
||||||
|
package = self.packages.${pkgs.system}.restic;
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
options = {
|
options = {
|
||||||
|
@ -130,7 +181,7 @@
|
||||||
in
|
in
|
||||||
lib.mkIf cfg.enable {
|
lib.mkIf cfg.enable {
|
||||||
environment.systemPackages = [
|
environment.systemPackages = [
|
||||||
pkgs.restic
|
package
|
||||||
];
|
];
|
||||||
|
|
||||||
environment.etc."restic/password" = {
|
environment.etc."restic/password" = {
|
||||||
|
@ -150,6 +201,7 @@
|
||||||
''
|
''
|
||||||
else
|
else
|
||||||
"";
|
"";
|
||||||
|
|
||||||
storageConfig = {
|
storageConfig = {
|
||||||
"b2" = ''
|
"b2" = ''
|
||||||
B2_ACCOUNT_ID=${cfg.b2.account_id}
|
B2_ACCOUNT_ID=${cfg.b2.account_id}
|
||||||
|
@ -160,20 +212,12 @@
|
||||||
AZURE_ACCOUNT_KEY=${cfg.azure.account_key}
|
AZURE_ACCOUNT_KEY=${cfg.azure.account_key}
|
||||||
'';
|
'';
|
||||||
}.${cfg.storage};
|
}.${cfg.storage};
|
||||||
# if cfg.storage == "b2"
|
|
||||||
# then
|
|
||||||
# else
|
|
||||||
# "";
|
|
||||||
repositoryConfig = {
|
repositoryConfig = {
|
||||||
"b2" = "b2:${bucket}:${directory}";
|
"b2" = "b2:${bucket}:${directory}";
|
||||||
"azure" = "azure:${bucket}:${directory}";
|
"azure" = "azure:${bucket}:${directory}";
|
||||||
}.${cfg.storage};
|
}.${cfg.storage};
|
||||||
|
|
||||||
# if cfg.storage == "b2"
|
|
||||||
# then
|
|
||||||
# "b2:${cfg.b2.bucket}:${config.networking.hostName}.${config.networking.domain}"
|
|
||||||
# else
|
|
||||||
# "";
|
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
text = ''
|
text = ''
|
||||||
|
@ -270,7 +314,7 @@
|
||||||
backup.excludes;
|
backup.excludes;
|
||||||
paths = lib.strings.concatStringsSep " " backup.paths;
|
paths = lib.strings.concatStringsSep " " backup.paths;
|
||||||
in
|
in
|
||||||
"${pkgs.restic}/bin/restic backup${one-file-system}${excludes} ${paths}"
|
"${package}/bin/restic backup${one-file-system}${excludes} ${paths}"
|
||||||
)
|
)
|
||||||
cfg.backups
|
cfg.backups
|
||||||
);
|
);
|
||||||
|
@ -280,7 +324,7 @@
|
||||||
|
|
||||||
if [ "$config" != "true" ]
|
if [ "$config" != "true" ]
|
||||||
then
|
then
|
||||||
${pkgs.restic}/bin/restic init
|
${package}/bin/restic init
|
||||||
fi
|
fi
|
||||||
'';
|
'';
|
||||||
|
|
||||||
|
@ -293,7 +337,7 @@
|
||||||
config=$(${pkgs.rclone}/bin/rclone --config /etc/restic/rclone lsjson "azure:${bucket}/config" | ${pkgs.jq}/bin/jq -r '. | length | . > 0')
|
config=$(${pkgs.rclone}/bin/rclone --config /etc/restic/rclone lsjson "azure:${bucket}/config" | ${pkgs.jq}/bin/jq -r '. | length | . > 0')
|
||||||
if [ "$config" != "true" ]
|
if [ "$config" != "true" ]
|
||||||
then
|
then
|
||||||
${pkgs.restic}/bin/restic init
|
${package}/bin/restic init
|
||||||
fi
|
fi
|
||||||
'';
|
'';
|
||||||
}.${cfg.storage};
|
}.${cfg.storage};
|
||||||
|
@ -312,9 +356,9 @@
|
||||||
|
|
||||||
${backupCommands}
|
${backupCommands}
|
||||||
|
|
||||||
${pkgs.restic}/bin/restic forget --prune --keep-daily 14
|
${package}/bin/restic forget --prune --keep-daily 14
|
||||||
${pkgs.restic}/bin/restic check
|
${package}/bin/restic check
|
||||||
${pkgs.restic}/bin/restic cache --cleanup
|
${package}/bin/restic cache --cleanup
|
||||||
|
|
||||||
${hcStop}
|
${hcStop}
|
||||||
'';
|
'';
|
||||||
|
@ -330,4 +374,5 @@
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue