From 506976a97008899c229e68c75f15ba568c1a002b Mon Sep 17 00:00:00 2001 From: PopeRigby Date: Tue, 9 Jul 2024 20:19:19 -0700 Subject: [PATCH] ludusavi: create Ludusavi module --- modules/lib/maintainers.nix | 5 ++ modules/services/ludusavi.nix | 86 +++++++++++++++++++++++++++++++++++ 2 files changed, 91 insertions(+) create mode 100644 modules/services/ludusavi.nix diff --git a/modules/lib/maintainers.nix b/modules/lib/maintainers.nix index f1a818155..0ac190c14 100644 --- a/modules/lib/maintainers.nix +++ b/modules/lib/maintainers.nix @@ -551,6 +551,11 @@ github = "pedorich-n"; githubId = 15573098; }; + PopeRigby = { + name = "PopeRigby"; + github = "poperigby"; + githubId = 20866468; + }; liyangau = { name = "Li Yang"; email = "d@aufomm.com"; diff --git a/modules/services/ludusavi.nix b/modules/services/ludusavi.nix new file mode 100644 index 000000000..4d117e136 --- /dev/null +++ b/modules/services/ludusavi.nix @@ -0,0 +1,86 @@ +{ + config, + lib, + pkgs, + ... +}: + +let + cfg = config.services.ludusavi; + settingsFormat = pkgs.formats.yaml { }; + + configFile = + if cfg.configFile == null then + settingsFormat.generate "config.yaml" cfg.settings + else + cfg.configFile; +in +{ + meta.maintainers = [ lib.maintainers.PopeRigby ]; + + options.services.ludusavi = { + enable = lib.mkEnableOption "Ludusavi game backup tool"; + configFile = lib.mkOption { + type = with lib.types; nullOr path; + default = null; + description = '' + Path to a Ludusavi `config.yaml`. Mutually exclusive with the `settings` option. + See https://github.com/mtkennerly/ludusavi#configuration-file for available options. + ''; + }; + settings = lib.mkOption { + type = settingsFormat.type; + default = { + manifest.url = "https://raw.githubusercontent.com/mtkennerly/ludusavi-manifest/master/data/manifest.yaml"; + roots = [ ]; + backup.path = "~/.local/state/backups/ludusavi"; + restore.path = "~/.local/state/backups/ludusavi"; + }; + example = { + language = "en-US"; + theme = "light"; + roots = [ + { + path = "~/.local/share/Steam"; + store = "steam"; + } + ]; + backup.path = "~/.local/state/backups/ludusavi"; + restore.path = "~/.local/state/backups/ludusavi"; + }; + description = '' + Ludusavi configuration as an attribute set. See + https://github.com/mtkennerly/ludusavi#configuration-file + for available options. + ''; + }; + }; + + config = lib.mkIf cfg.enable { + assertions = [ + { + assertion = (cfg.settings != { }) != (cfg.configFile != null); + message = "The `settings` and `configFile` options are mutually exclusive."; + } + ]; + + systemd.user = { + services.ludusavi = { + Unit.Description = "Run a game save backup with Ludusavi"; + Service = { + Type = "oneshot"; + ExecStart = "${pkgs.ludusavi}/bin/ludusavi backup --force"; + }; + }; + timers.ludusavi = { + Unit.Description = "Run a game save backup with Ludusavi, daily"; + Timer.OnCalendar = "daily"; + Install.WantedBy = [ "timers.target" ]; + }; + }; + + xdg.configFile."ludusavi/config.yaml".source = configFile; + + home.packages = [ pkgs.ludusavi ]; + }; +}