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:
parent
763b1a1c55
commit
ad0fc085c7
7 changed files with 150 additions and 0 deletions
2
.github/CODEOWNERS
vendored
2
.github/CODEOWNERS
vendored
|
@ -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
|
||||
|
|
|
@ -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'.
|
||||
'';
|
||||
}
|
||||
];
|
||||
};
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
100
modules/services/git-sync.nix
Normal file
100
modules/services/git-sync.nix
Normal 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;
|
||||
};
|
||||
}
|
|
@ -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
|
||||
|
|
37
tests/modules/services/git-sync/basic.nix
Normal file
37
tests/modules/services/git-sync/basic.nix
Normal 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
|
||||
''
|
||||
}
|
||||
'';
|
||||
};
|
||||
}
|
1
tests/modules/services/git-sync/default.nix
Normal file
1
tests/modules/services/git-sync/default.nix
Normal file
|
@ -0,0 +1 @@
|
|||
{ git-sync = ./basic.nix; }
|
Loading…
Reference in a new issue