From 298facd6d2db8dd2f6af5eb1c4b6dff1a977576c Mon Sep 17 00:00:00 2001 From: Aaron Bieber Date: Mon, 17 Apr 2023 10:43:10 -0600 Subject: [PATCH] h,europa: wrap restic bin more intelligently --- bins/restic.nix | 16 ++++++++++++---- hosts/europa/default.nix | 7 +++++++ hosts/h/default.nix | 7 +++++-- 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/bins/restic.nix b/bins/restic.nix index fa291bc..31be444 100644 --- a/bins/restic.nix +++ b/bins/restic.nix @@ -1,9 +1,17 @@ -{ pkgs }: +{ lib, pkgs, config, ... }: -let resticBin = "${pkgs.restic}/bin/restic"; +assert (builtins.length + (lib.mapAttrsToList (a: _: a) config.services.restic.backups)) <= 1; + +let + resticBin = "${pkgs.restic}/bin/restic"; + cfg = config.services.restic.backups; + bkp = lib.mapAttrs' (_: lib.nameValuePair "default") cfg; in '' #!/usr/bin/env sh - export $(cat /run/secrets/restic_env_file) - ${resticBin} --password-file /run/secrets/restic_password_file $@ + set -e + + export $(cat ${bkp.default.environmentFile}) + ${resticBin} -r ${bkp.default.repository} --password-file ${bkp.default.passwordFile} $@ '' diff --git a/hosts/europa/default.nix b/hosts/europa/default.nix index 5882330..82e124a 100644 --- a/hosts/europa/default.nix +++ b/hosts/europa/default.nix @@ -1,5 +1,10 @@ { config, pkgs, lib, xinlib, ... }: let + restic = pkgs.writeScriptBin "restic" (import ../../bins/restic.nix { + inherit pkgs; + inherit lib; + inherit config; + }); myEmacs = pkgs.callPackage ../../configs/emacs.nix { }; peerixUser = if builtins.hasAttr "peerix" config.users.users then config.users.users.peerix.name @@ -294,6 +299,8 @@ in { }) (callPackage ../../pkgs/gokrazy.nix { }) (callPackage ../../pkgs/zutty.nix { }) + + restic ]; # for Pharo diff --git a/hosts/h/default.nix b/hosts/h/default.nix index 2c60db7..cd64b74 100644 --- a/hosts/h/default.nix +++ b/hosts/h/default.nix @@ -1,8 +1,11 @@ { config, pkgs, isUnstable, ... }: with pkgs; let - restic = pkgs.writeScriptBin "restic" - (import ../../bins/restic.nix { inherit pkgs; }); + restic = pkgs.writeScriptBin "restic" (import ../../bins/restic.nix { + inherit pkgs; + inherit lib; + inherit config; + }); gqrss = callPackage ../../pkgs/gqrss.nix { inherit isUnstable; }; icbirc = callPackage ../../pkgs/icbirc.nix { inherit isUnstable; }; mcchunkie = callPackage ../../pkgs/mcchunkie.nix { inherit isUnstable; };