added resticprofile flake-part
This commit is contained in:
84
modules/home-manager/programs/resticprofile.nix
Normal file
84
modules/home-manager/programs/resticprofile.nix
Normal file
@@ -0,0 +1,84 @@
|
||||
{ inputs, ... }:
|
||||
{
|
||||
perSystem = { pkgs, ... }:
|
||||
let
|
||||
resticprofilePkg = pkgs.buildGoModule rec {
|
||||
pname = "resticprofile";
|
||||
version = "0.32.0";
|
||||
src = pkgs.fetchFromGitHub {
|
||||
owner = "creativeprojects";
|
||||
repo = "resticprofile";
|
||||
rev = "v${version}";
|
||||
sha256 = "sha256-fmYsoGYppNgbtoX18aF5UHBG9ieYorBJ9JZkwrR+UBI=";
|
||||
};
|
||||
vendorHash = "sha256-/GVWjOvkYe7xMRjANKIKV6FSU0F5VY1ZP/ppgAJyhvw=";
|
||||
goPackagePath = "github.com/creativeprojects/resticprofile";
|
||||
doCheck = false;
|
||||
meta = with pkgs.lib; {
|
||||
description = "Configuration profiles manager and scheduler for restic backup";
|
||||
homepage = "https://creativeprojects.github.io/resticprofile/";
|
||||
license = licenses.gpl3Only;
|
||||
maintainers = [ ];
|
||||
};
|
||||
};
|
||||
in {
|
||||
packages = {
|
||||
resticprofile = resticprofilePkg;
|
||||
default = resticprofilePkg;
|
||||
};
|
||||
};
|
||||
|
||||
flake.homeModules.resticprofile = { config, lib, pkgs, ... }:
|
||||
let
|
||||
cfg = config.programs.resticprofile;
|
||||
yamlFormat = pkgs.formats.yaml { };
|
||||
baseProfile = import ../../../resticprofile/base.nix { inherit lib config; };
|
||||
profiles = lib.recursiveUpdate baseProfile cfg.profiles;
|
||||
in {
|
||||
options.programs.resticprofile = {
|
||||
enable = lib.mkEnableOption "Enable resticprofile (Restic backup profile manager)";
|
||||
package = lib.mkPackageOption pkgs "resticprofile" { };
|
||||
profiles = lib.mkOption {
|
||||
type = lib.types.attrsOf yamlFormat.type;
|
||||
default = { };
|
||||
description = ''
|
||||
Additional resticprofile configuration merged on top of the base profile.
|
||||
Each attribute becomes a profile entry in
|
||||
`$XDG_CONFIG_HOME/resticprofile/profiles.yaml`.
|
||||
'';
|
||||
};
|
||||
};
|
||||
|
||||
config = lib.mkIf cfg.enable (
|
||||
let
|
||||
resticprofilePackage = lib.mkDefault
|
||||
inputs.self.packages.${pkgs.system}.resticprofile;
|
||||
resticprofileBin = lib.getExe cfg.package;
|
||||
rpScript = pkgs.writeShellScriptBin "rp" ''
|
||||
set -e
|
||||
sudo ${resticprofileBin} --config "${config.xdg.configHome}/resticprofile/profiles.yaml" $@
|
||||
'';
|
||||
rpbackupScript = pkgs.writeShellScriptBin "rp-backup" ''
|
||||
${lib.getExe rpScript} run-schedule backup@default
|
||||
'';
|
||||
in {
|
||||
programs.resticprofile.package = resticprofilePackage;
|
||||
home.packages = [
|
||||
cfg.package
|
||||
rpScript
|
||||
rpbackupScript
|
||||
(pkgs.writeShellScriptBin "rps" ''
|
||||
set -e
|
||||
${lib.getExe rpScript} unschedule --all
|
||||
${lib.getExe rpScript} schedule --all
|
||||
'')
|
||||
(pkgs.writeShellScriptBin "rp-test" "${lib.getExe rpbackupScript} --dry-run")
|
||||
];
|
||||
xdg.configFile."resticprofile/profiles.yaml".source = yamlFormat.generate "profiles" {
|
||||
version = "2";
|
||||
profiles = profiles;
|
||||
};
|
||||
}
|
||||
);
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user