1
0
Fork 0
mirror of https://github.com/nix-community/home-manager synced 2024-11-15 15:49:45 +01:00

git-sync: add module

This commit is contained in:
Ivan Malison 2021-07-14 19:20:28 -06:00 committed by Robert Helgesson
parent 763b1a1c55
commit ad0fc085c7
No known key found for this signature in database
GPG key ID: 36BDAA14C2797E89
7 changed files with 150 additions and 0 deletions

2
.github/CODEOWNERS vendored
View file

@ -238,6 +238,8 @@
/modules/services/fluidsynth.nix @Valodim
/modules/services/git-sync.nix @IvanMalison
/modules/services/gnome-keyring.nix @rycee
/modules/services/gpg-agent.nix @rycee

View file

@ -2172,6 +2172,14 @@ in
A new module is available: 'services.easyeffects'.
'';
}
{
time = "2021-08-16T21:59:02+00:00";
condition = hostPlatform.isLinux;
message = ''
A new module is available: 'services.git-sync'.
'';
}
];
};
}

View file

@ -163,6 +163,7 @@ let
./services/flameshot.nix
./services/fluidsynth.nix
./services/getmail.nix
./services/git-sync.nix
./services/gnome-keyring.nix
./services/gpg-agent.nix
./services/grobi.nix

View file

@ -0,0 +1,100 @@
{ 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 = [
"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 = mapAttrs' (name: repo: {
name = "git-sync-${name}";
value = mkUnit name repo;
}) cfg.repositories;
repositoryType = types.submodule ({ name, ... }: {
options = {
name = mkOption {
internal = true;
default = name;
type = types.str;
description = "The name that should be given to this unit.";
};
path = mkOption {
type = types.path;
description = "The path at which to sync the repository";
};
uri = mkOption {
type = 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 = mkOption {
type = types.int;
default = 500;
description = ''
The interval, specified in seconds, at which the synchronization will
be triggered even without filesystem changes.
'';
};
};
});
in {
meta.maintainers = [ maintainers.imalison ];
options = {
services.git-sync = {
enable = mkEnableOption "git-sync services";
package = mkOption {
type = types.package;
default = pkgs.git-sync;
defaultText = literalExample "pkgs.git-sync";
description = ''
Package containing the <command>git-sync</command> program.
'';
};
repositories = mkOption {
type = with types; attrsOf repositoryType;
description = ''
The repositories that should be synchronized.
'';
};
};
};
config = mkIf cfg.enable {
assertions = [
(lib.hm.assertions.assertPlatform "services.git-sync" pkgs
lib.platforms.linux)
];
systemd.user.services = services;
};
}

View file

@ -120,6 +120,7 @@ import nmt {
./modules/services/dropbox
./modules/services/emacs
./modules/services/fluidsynth
./modules/services/git-sync
./modules/services/kanshi
./modules/services/lieer
./modules/services/pantalaimon

View file

@ -0,0 +1,37 @@
{ config, pkgs, ... }:
{
config = {
services.git-sync = {
enable = true;
package = pkgs.writeScriptBin "dummy" "" // { outPath = "@git-sync@"; };
repositories.test = {
path = "/a/path";
uri = "git+ssh://user@example.com:/~user/path/to/repo.git";
};
};
nmt.script = ''
serviceFile=home-files/.config/systemd/user/git-sync-test.service
assertFileExists $serviceFile
assertFileContent $serviceFile ${
builtins.toFile "expected" ''
[Install]
WantedBy=default.target
[Service]
Environment=GIT_SYNC_DIRECTORY=/a/path
Environment=GIT_SYNC_COMMAND=@git-sync@/bin/git-sync
Environment=GIT_SYNC_REPOSITORY=git+ssh://user@example.com:/~user/path/to/repo.git
Environment=GIT_SYNC_INTERVAL=500
ExecStart=@git-sync@/bin/git-sync-on-inotify
Restart=on-abort
[Unit]
Description=Git Sync test
''
}
'';
};
}

View file

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