Unverified Commit 9d94b98e authored by Finn Landweber's avatar Finn Landweber
Browse files

nixos/borgmatic: refactor

added configuration check at built time
added borgmatic.enableConfigCheck whether or not it'll be executed.
parent a71502af
Loading
Loading
Loading
Loading
+31 −18
Original line number Diff line number Diff line
@@ -76,9 +76,25 @@ in
      default = { };
      type = types.attrsOf cfgType;
    };

    enableConfigCheck = mkEnableOption (lib.mdDoc "checking all configurations during build time") // { default = true; };
  };

  config = mkIf cfg.enable {
  config =
    let
      configFiles =
        (optionalAttrs (cfg.settings != null) { "borgmatic/config.yaml".source = cfgfile; }) //
        mapAttrs'
          (name: value: nameValuePair
            "borgmatic.d/${name}.yaml"
            { source = settingsFormat.generate "${name}.yaml" value; })
          cfg.configurations;
      borgmaticCheck = name: f: pkgs.runCommandCC "${name} validation" { } ''
            ${pkgs.borgmatic}/bin/borgmatic -c ${f.source} config validate
            touch $out
          '';
    in
      mkIf cfg.enable {

        warnings = []
          ++ optional (cfg.settings != null && cfg.settings ? location)
@@ -89,16 +105,13 @@ in

        environment.systemPackages = [ pkgs.borgmatic ];

    environment.etc = (optionalAttrs (cfg.settings != null) { "borgmatic/config.yaml".source = cfgfile; }) //
      mapAttrs'
        (name: value: nameValuePair
          "borgmatic.d/${name}.yaml"
          { source = settingsFormat.generate "${name}.yaml" value; })
        cfg.configurations;
        environment.etc = configFiles;

        systemd.packages = [ pkgs.borgmatic ];

        # Workaround: https://github.com/NixOS/nixpkgs/issues/81138
        systemd.timers.borgmatic.wantedBy = [ "timers.target" ];

        system.checks = mkIf cfg.enableConfigCheck (mapAttrsToList borgmaticCheck configFiles);
      };
}