-
-
Notifications
You must be signed in to change notification settings - Fork 13.8k
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
Add gitwatch module #337273
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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"; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 [ | ||
git | ||
inotify-tools | ||
openssh | ||
] | ||
} | ||
'' |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?