git-sync: add darwin support

- On darwin, creates a launch agent to run git-sync on an interval and
  when the `path` changes.

- The `uri` option is not used on Darwin. The auto-creation of the
  local git directory from the `uri` is a feature of the
  git-sync-on-inotify [1] wrapper (which won't work on Darwin afaik)
  and not `git-sync` itself.

[1] https://github.com/simonthum/git-sync/blob/master/contrib/git-sync-on-inotify
This commit is contained in:
ryane 2023-07-20 21:10:17 -04:00 committed by Robert Helgesson
parent fb03fa5516
commit ab70a02363
No known key found for this signature in database
GPG Key ID: 36BDAA14C2797E89
5 changed files with 63 additions and 9 deletions

View File

@ -24,9 +24,21 @@ let
};
};
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;
services = mapAttrs' (name: repo: {
name = "git-sync-${name}";
value = mkUnit name repo;
value = mkService name repo;
}) cfg.repositories;
repositoryType = types.submodule ({ name, ... }: {
@ -51,6 +63,8 @@ let
event that the directory does not already exist. See
<https://git-scm.com/docs/git-clone#_git_urls>
for the supported URIs.
This option is not supported on Darwin.
'';
};
@ -66,7 +80,8 @@ let
});
in {
meta.maintainers = [ maintainers.imalison maintainers.cab404 ];
meta.maintainers =
[ maintainers.imalison maintainers.cab404 maintainers.ryane ];
options = {
services.git-sync = {
@ -90,12 +105,9 @@ in {
};
};
config = mkIf cfg.enable {
assertions = [
(lib.hm.assertions.assertPlatform "services.git-sync" pkgs
lib.platforms.linux)
];
config = mkIf cfg.enable (mkMerge [
(mkIf pkgs.stdenv.isLinux { systemd.user.services = services; })
(mkIf pkgs.stdenv.isDarwin { launchd.agents = services; })
]);
systemd.user.services = services;
};
}

View File

@ -147,6 +147,7 @@ import nmt {
./modules/xresources
] ++ lib.optionals isDarwin [
./modules/launchd
./modules/services/git-sync-darwin
./modules/services/imapnotify-darwin
./modules/targets-darwin
] ++ lib.optionals isLinux [

View File

@ -0,0 +1,18 @@
{ config, ... }:
{
services.git-sync = {
enable = true;
package = config.lib.test.mkStubPackage { outPath = "@git-sync@"; };
repositories.test = {
path = "/a/path";
uri = "git+ssh://user@example.com:/~user/path/to/repo.git";
};
};
nmt.script = ''
serviceFile=LaunchAgents/org.nix-community.home.git-sync-test.plist
assertFileExists "$serviceFile"
assertFileContent "$serviceFile" ${./expected-agent.plist}
'';
}

View File

@ -0,0 +1 @@
{ git-sync = ./basic.nix; }

View File

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>org.nix-community.home.git-sync-test</string>
<key>ProcessType</key>
<string>Background</string>
<key>ProgramArguments</key>
<array>
<string>@git-sync@/bin/git-sync</string>
</array>
<key>StartInterval</key>
<integer>500</integer>
<key>WatchPaths</key>
<array>
<string>/a/path</string>
</array>
<key>WorkingDirectory</key>
<string>/a/path</string>
</dict>
</plist>