diff options
author | Soispha <soispha@vhack.eu> | 2023-06-17 21:09:22 +0200 |
---|---|---|
committer | Soispha <soispha@vhack.eu> | 2023-06-17 22:03:27 +0200 |
commit | 357f78ed275661f7196ce315b1a276c1a4f3acc9 (patch) | |
tree | e45c7556691633de80aac933a2d82eb46af8d51d /system | |
parent | Merge branch 'keycloak' into develop (diff) | |
download | nixos-server-357f78ed275661f7196ce315b1a276c1a4f3acc9.tar.gz nixos-server-357f78ed275661f7196ce315b1a276c1a4f3acc9.zip |
Feat(system/services/git-sync): Add
Diffstat (limited to '')
-rw-r--r-- | system/services/default.nix | 1 | ||||
-rw-r--r-- | system/services/git-sync/default.nix | 104 |
2 files changed, 105 insertions, 0 deletions
diff --git a/system/services/default.nix b/system/services/default.nix index 99b8fb6..5c9b6bf 100644 --- a/system/services/default.nix +++ b/system/services/default.nix @@ -9,5 +9,6 @@ ./opensshd ./rust-motd ./fail2ban + ./git-sync ]; } diff --git a/system/services/git-sync/default.nix b/system/services/git-sync/default.nix new file mode 100644 index 0000000..776ca60 --- /dev/null +++ b/system/services/git-sync/default.nix @@ -0,0 +1,104 @@ +/* +Taken from: +https://github.com/nix-community/home-manager/blob/9ba7b3990eb1f4782ea3f5fe7ac4f3c88dd7a32c/modules/services/git-sync.nix +*/ +{ + config, + lib, + pkgs, + ... +}: let + cfg = config.services.git-sync; + + mkUnit = name: repo: { + Unit.Description = "Git Sync ${name}"; + + Install.WantedBy = ["default.target"]; + + Service = { + Environment = [ + "PATH=${lib.makeBinPath (with pkgs; [openssh git])}" + "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"; + }; + }; + + services = + lib.mapAttrs' (name: repo: { + name = "git-sync-${name}"; + value = mkUnit name repo; + }) + cfg.repositories; + + repositoryType = lib.types.submodule ({name, ...}: { + options = { + name = lib.mkOption { + internal = true; + default = name; + type = lib.types.str; + description = "The name that should be given to this unit."; + }; + + path = lib.mkOption { + type = lib.types.path; + description = "The path at which to sync the repository"; + }; + + uri = lib.mkOption { + type = lib.types.str; + example = "git+ssh://user@example.com:/~[user]/path/to/repo.git"; + description = '' + The URI of the remote to be synchronized. This is only used in the + event that the directory does not already exist. See + <link xlink:href="https://git-scm.com/docs/git-clone#_git_urls"/> + for the supported URIs. + ''; + }; + + interval = lib.mkOption { + type = lib.types.int; + default = 500; + description = '' + The interval, specified in seconds, at which the synchronization will + be triggered even without filesystem changes. + ''; + }; + }; + }); +in { + options = { + services.git-sync = { + enable = lib.mkEnableOption "git-sync services"; + + package = lib.mkOption { + type = lib.types.package; + default = pkgs.git-sync; + defaultText = lib.literalExpression "pkgs.git-sync"; + description = '' + Package containing the <command>git-sync</command> program. + ''; + }; + + repositories = lib.mkOption { + type = with lib.types; attrsOf repositoryType; + description = '' + The repositories that should be synchronized. + ''; + }; + }; + }; + + config = lib.mkIf cfg.enable { + assertions = [ + (lib.hm.assertions.assertPlatform "services.git-sync" pkgs + lib.platforms.linux) + ]; + + systemd.user.services = services; + }; +} |