Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add gitwatch module #337273

Merged
merged 3 commits into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions maintainers/maintainer-list.nix
Original file line number Diff line number Diff line change
Expand Up @@ -18978,6 +18978,12 @@
githubId = 67710369;
keys = [ { fingerprint = "EA88 EA07 26E9 6CBF 6365 3966 163B 16EE 76ED 24CE"; } ];
};
shved = {
name = "Yury Shvedov";
email = "[email protected]";
github = "ein-shved";
githubId = 3513222;
};
shyim = {
email = "[email protected]";
github = "shyim";
Expand Down
87 changes: 87 additions & 0 deletions nixos/modules/services/monitoring/gitwatch.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
{
lib,
pkgs,
config,
...
}:
let
mkSystemdService =
name: cfg:
lib.nameValuePair "gitwatch-${name}" (
let
getvar = flag: var: lib.optionalString (cfg."${var}" != null) "${flag} ${cfg."${var}"}";
branch = getvar "-b" "branch";
remote = getvar "-r" "remote";
in
rec {
inherit (cfg) enable;
after = [ "network-online.target" ];
wants = after;
wantedBy = [ "multi-user.target" ];
description = "gitwatch for ${name}";
path = with pkgs; [
gitwatch
git
openssh
];
script = ''
if [ -n "${cfg.remote}" ] && ! [ -d "${cfg.path}" ]; then
git clone ${branch} "${cfg.remote}" "${cfg.path}"
fi
gitwatch ${remote} ${branch} ${cfg.path}
'';
serviceConfig.User = cfg.user;
}
);
in
{
options.services.gitwatch = lib.mkOption {
description = ''
A set of git repositories to watch for. See
[gitwatch](https://github.com/gitwatch/gitwatch) for more.
'';
default = { };
example = {
my-repo = {
enable = true;
user = "user";
path = "/home/user/watched-project";
remote = "[email protected]:me/my-project.git";
};
disabled-repo = {
enable = false;
user = "user";
path = "/home/user/disabled-project";
remote = "[email protected]:me/my-old-project.git";
branch = "autobranch";
};
};
type =
with lib.types;
attrsOf (submodule {
options = {
enable = lib.mkEnableOption "watching for repo";
path = lib.mkOption {
description = "The path to repo in local machine";
type = str;
};
user = lib.mkOption {
description = "The name of services's user";
type = str;
default = "root";
};
remote = lib.mkOption {
description = "Optional url of remote repository";
type = nullOr str;
default = null;
};
branch = lib.mkOption {
description = "Optional branch in remote repository";
type = nullOr str;
default = null;
};
};
});
};
config.systemd.services = lib.mapAttrs' mkSystemdService config.services.gitwatch;
}
49 changes: 49 additions & 0 deletions pkgs/by-name/gi/gitwatch/package.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{
runCommand,
lib,
makeWrapper,
fetchFromGitHub,

git,
openssh,
inotify-tools,
}:
runCommand "gitwatch"
rec {
version = "0.2";
src = fetchFromGitHub {
owner = "gitwatch";
repo = "gitwatch";
rev = "v${version}";
hash = "sha256-KuWD2FAMi2vZ/7e4fIg97DGuAPEV9b9iOuF8NIGFVpE=";
};
nativeBuildInputs = [ makeWrapper ];

meta = {
description = "Watch a filesystem and automatically stage changes to a git.";
mainProgram = "gitwatch";
longDescription = ''
A bash script to watch a file or folder and commit changes to a git repo.
'';
homepage = "https://github.com/gitwatch/gitwatch";
changelog = "https://github.com/gitwatch/gitwatch/releases/tag/v${version}";
license = lib.licenses.gpl3Only;
maintainers = with lib.maintainers; [ shved ];
};
}
''
mkdir -p $out/bin
dest="$out/bin/gitwatch"
cp "$src/gitwatch.sh" $dest
chmod +x $dest
patchShebangs $dest

wrapProgram $dest \
--prefix PATH ';' ${
lib.makeBinPath [
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a minor nitpick, can the PATH be injected directly into the script rather than wrapping in an outer script?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please give me the link on how to do so?

git
inotify-tools
openssh
]
}
''