diff --git a/modules/services/git-sync.nix b/modules/services/git-sync.nix index 770cec0f..a274da8f 100644 --- a/modules/services/git-sync.nix +++ b/modules/services/git-sync.nix @@ -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 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; - }; } diff --git a/tests/default.nix b/tests/default.nix index 97f4b4ef..e52d8d88 100644 --- a/tests/default.nix +++ b/tests/default.nix @@ -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 [ diff --git a/tests/modules/services/git-sync-darwin/basic.nix b/tests/modules/services/git-sync-darwin/basic.nix new file mode 100644 index 00000000..a50c1e04 --- /dev/null +++ b/tests/modules/services/git-sync-darwin/basic.nix @@ -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} + ''; +} diff --git a/tests/modules/services/git-sync-darwin/default.nix b/tests/modules/services/git-sync-darwin/default.nix new file mode 100644 index 00000000..0e9db79d --- /dev/null +++ b/tests/modules/services/git-sync-darwin/default.nix @@ -0,0 +1 @@ +{ git-sync = ./basic.nix; } diff --git a/tests/modules/services/git-sync-darwin/expected-agent.plist b/tests/modules/services/git-sync-darwin/expected-agent.plist new file mode 100644 index 00000000..2699a996 --- /dev/null +++ b/tests/modules/services/git-sync-darwin/expected-agent.plist @@ -0,0 +1,22 @@ + + + + + Label + org.nix-community.home.git-sync-test + ProcessType + Background + ProgramArguments + + @git-sync@/bin/git-sync + + StartInterval + 500 + WatchPaths + + /a/path + + WorkingDirectory + /a/path + + \ No newline at end of file