2021-07-15 03:20:28 +02:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
cfg = config.services.git-sync;
|
|
|
|
|
|
|
|
mkUnit = name: repo: {
|
|
|
|
Unit.Description = "Git Sync ${name}";
|
|
|
|
|
|
|
|
Install.WantedBy = [ "default.target" ];
|
|
|
|
|
|
|
|
Service = {
|
|
|
|
Environment = [
|
2023-11-23 19:42:13 +01:00
|
|
|
"PATH=${
|
|
|
|
lib.makeBinPath (with pkgs; [ openssh git ] ++ repo.extraPackages)
|
|
|
|
}"
|
2021-07-15 03:20:28 +02:00
|
|
|
"GIT_SYNC_DIRECTORY=${repo.path}"
|
|
|
|
"GIT_SYNC_COMMAND=${cfg.package}/bin/git-sync"
|
|
|
|
"GIT_SYNC_REPOSITORY=${repo.uri}"
|
|
|
|
"GIT_SYNC_INTERVAL=${toString repo.interval}"
|
|
|
|
];
|
|
|
|
ExecStart = "${cfg.package}/bin/git-sync-on-inotify";
|
|
|
|
Restart = "on-abort";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2023-07-21 03:10:17 +02:00
|
|
|
mkAgent = name: repo: {
|
|
|
|
enable = true;
|
|
|
|
config = {
|
|
|
|
StartInterval = repo.interval;
|
|
|
|
ProcessType = "Background";
|
|
|
|
WorkingDirectory = "${repo.path}";
|
|
|
|
WatchPaths = [ "${repo.path}" ];
|
|
|
|
ProgramArguments = [ "${cfg.package}/bin/git-sync" ];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
mkService = if pkgs.stdenv.isLinux then mkUnit else mkAgent;
|
2021-07-15 03:20:28 +02:00
|
|
|
services = mapAttrs' (name: repo: {
|
|
|
|
name = "git-sync-${name}";
|
2023-07-21 03:10:17 +02:00
|
|
|
value = mkService name repo;
|
2021-07-15 03:20:28 +02:00
|
|
|
}) cfg.repositories;
|
|
|
|
|
|
|
|
repositoryType = types.submodule ({ name, ... }: {
|
|
|
|
options = {
|
|
|
|
name = mkOption {
|
|
|
|
internal = true;
|
|
|
|
default = name;
|
|
|
|
type = types.str;
|
2023-07-02 01:45:18 +02:00
|
|
|
description = "The name that should be given to this unit.";
|
2021-07-15 03:20:28 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
path = mkOption {
|
|
|
|
type = types.path;
|
2023-07-02 01:45:18 +02:00
|
|
|
description = "The path at which to sync the repository";
|
2021-07-15 03:20:28 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
uri = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
example = "git+ssh://user@example.com:/~[user]/path/to/repo.git";
|
2023-07-02 01:45:18 +02:00
|
|
|
description = ''
|
2021-07-15 03:20:28 +02:00
|
|
|
The URI of the remote to be synchronized. This is only used in the
|
|
|
|
event that the directory does not already exist. See
|
2023-07-01 01:30:13 +02:00
|
|
|
<https://git-scm.com/docs/git-clone#_git_urls>
|
2021-07-15 03:20:28 +02:00
|
|
|
for the supported URIs.
|
2023-07-21 03:10:17 +02:00
|
|
|
|
|
|
|
This option is not supported on Darwin.
|
2021-07-15 03:20:28 +02:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
interval = mkOption {
|
|
|
|
type = types.int;
|
|
|
|
default = 500;
|
2023-07-02 01:45:18 +02:00
|
|
|
description = ''
|
2021-07-15 03:20:28 +02:00
|
|
|
The interval, specified in seconds, at which the synchronization will
|
|
|
|
be triggered even without filesystem changes.
|
|
|
|
'';
|
|
|
|
};
|
2023-11-23 19:42:13 +01:00
|
|
|
|
|
|
|
extraPackages = mkOption {
|
|
|
|
type = with types; listOf package;
|
|
|
|
default = [ ];
|
|
|
|
example = literalExpression "with pkgs; [ git-crypt ]";
|
|
|
|
description = ''
|
|
|
|
Extra packages available to git-sync.
|
|
|
|
'';
|
|
|
|
};
|
2021-07-15 03:20:28 +02:00
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
in {
|
2023-07-21 03:10:17 +02:00
|
|
|
meta.maintainers =
|
|
|
|
[ maintainers.imalison maintainers.cab404 maintainers.ryane ];
|
2021-07-15 03:20:28 +02:00
|
|
|
|
|
|
|
options = {
|
|
|
|
services.git-sync = {
|
2023-07-02 01:45:18 +02:00
|
|
|
enable = mkEnableOption "git-sync services";
|
2021-07-15 03:20:28 +02:00
|
|
|
|
|
|
|
package = mkOption {
|
|
|
|
type = types.package;
|
|
|
|
default = pkgs.git-sync;
|
2021-10-09 11:14:08 +02:00
|
|
|
defaultText = literalExpression "pkgs.git-sync";
|
2023-07-02 01:45:18 +02:00
|
|
|
description = ''
|
2023-07-01 01:30:13 +02:00
|
|
|
Package containing the {command}`git-sync` program.
|
2021-07-15 03:20:28 +02:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
repositories = mkOption {
|
|
|
|
type = with types; attrsOf repositoryType;
|
2023-07-02 01:45:18 +02:00
|
|
|
description = ''
|
2021-07-15 03:20:28 +02:00
|
|
|
The repositories that should be synchronized.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2023-07-21 03:10:17 +02:00
|
|
|
config = mkIf cfg.enable (mkMerge [
|
|
|
|
(mkIf pkgs.stdenv.isLinux { systemd.user.services = services; })
|
|
|
|
(mkIf pkgs.stdenv.isDarwin { launchd.agents = services; })
|
|
|
|
]);
|
2021-07-15 03:20:28 +02:00
|
|
|
|
|
|
|
}
|