fork/home-manager
git clone https://git.julia.blue/fork/home-manager
ab70a023
master
1{ config , lib , pkgs , ...} : 2 3with lib ; 4 5let 6 7cfg = config . services . git-sync ; 8 9mkUnit = name :repo :{ 10Unit . Description = "Git Sync ${ name } " ; 11 12Install . WantedBy = [ "default.target" ]; 13 14Service = { 15Environment = [ 16"PATH= ${ lib . makeBinPath ( with pkgs ; [ openssh git ])} " 17"GIT_SYNC_DIRECTORY= ${ repo . path } " 18"GIT_SYNC_COMMAND= ${ cfg . package } /bin/git-sync" 19"GIT_SYNC_REPOSITORY= ${ repo . uri } " 20"GIT_SYNC_INTERVAL= ${ toString repo . interval } " 21]; 22ExecStart = " ${ cfg . package } /bin/git-sync-on-inotify" ; 23Restart = "on-abort" ; 24}; 25}; 26 27mkAgent = name :repo :{ 28enable = true ; 29config = { 30StartInterval = repo . interval ; 31ProcessType = "Background" ; 32WorkingDirectory = " ${ repo . path } " ; 33WatchPaths = [ " ${ repo . path } " ]; 34ProgramArguments = [ " ${ cfg . package } /bin/git-sync" ]; 35}; 36}; 37 38mkService = if pkgs . stdenv . isLinux then mkUnit else mkAgent ; 39services = mapAttrs' ( name :repo :{ 40name = "git-sync- ${ name } " ; 41value = mkService name repo ; 42}) cfg . repositories ; 43 44repositoryType = types . submodule ({ name , ...} :{ 45options = { 46name = mkOption { 47internal = true ; 48default = name ; 49type = types . str ; 50description = "The name that should be given to this unit." ; 51}; 52 53path = mkOption { 54type = types . path ; 55description = "The path at which to sync the repository" ; 56}; 57 58uri = mkOption { 59type = types . str ; 60example = "git+ssh://user@example.com:/~[user]/path/to/repo.git" ; 61description = '' 62The URI of the remote to be synchronized. This is only used in the 63event that the directory does not already exist. See 64<https://git-scm.com/docs/git-clone#_git_urls> 65for the supported URIs. 66 67This option is not supported on Darwin. 68'' ; 69}; 70 71interval = mkOption { 72type = types . int ; 73default = 500 ; 74description = '' 75The interval, specified in seconds, at which the synchronization will 76be triggered even without filesystem changes. 77'' ; 78}; 79}; 80}); 81 82in { 83meta . maintainers = 84[ maintainers . imalison maintainers . cab404 maintainers . ryane ]; 85 86options = { 87services . git-sync = { 88enable = mkEnableOption "git-sync services" ; 89 90package = mkOption { 91type = types . package ; 92default = pkgs . git-sync ; 93defaultText = literalExpression "pkgs.git-sync" ; 94description = '' 95Package containing the {command}`git-sync` program. 96'' ; 97}; 98 99repositories = mkOption { 100type = with types ; attrsOf repositoryType ; 101description = '' 102The repositories that should be synchronized. 103'' ; 104}; 105}; 106}; 107 108config = mkIf cfg . enable ( mkMerge [ 109( mkIf pkgs . stdenv . isLinux { systemd . user . services = services ; }) 110( mkIf pkgs . stdenv . isDarwin { launchd . agents = services ; }) 111]); 112 113}