mirror of https://github.com/gitwatch/gitwatch
Add support for NixOS (#117)
You are able to use it as standalone package, or service either.pull/120/head
parent
45c629ce6b
commit
5d685af85d
@ -0,0 +1,19 @@
|
|||||||
|
{
|
||||||
|
description = "A bash script to watch a file or folder and commit changes to a git repo";
|
||||||
|
outputs = { self, nixpkgs, flake-utils }:
|
||||||
|
let
|
||||||
|
packages = flake-utils.lib.eachDefaultSystem (system:
|
||||||
|
let
|
||||||
|
pkgs = import nixpkgs {
|
||||||
|
inherit system;
|
||||||
|
};
|
||||||
|
in
|
||||||
|
{
|
||||||
|
packages = rec {
|
||||||
|
gitwatch = pkgs.callPackage ./gitwatch.sh { };
|
||||||
|
default = gitwatch;
|
||||||
|
};
|
||||||
|
});
|
||||||
|
in
|
||||||
|
packages // { modules = [ ./module.nix ]; };
|
||||||
|
}
|
@ -0,0 +1,19 @@
|
|||||||
|
{ runCommandNoCC
|
||||||
|
, lib
|
||||||
|
, makeWrapper
|
||||||
|
|
||||||
|
, git
|
||||||
|
, openssh
|
||||||
|
, inotify-tools
|
||||||
|
}: runCommandNoCC "gitwatch" {
|
||||||
|
nativeBuildInputs = [ makeWrapper ];
|
||||||
|
} ''
|
||||||
|
mkdir -p $out/bin
|
||||||
|
dest="$out/bin/gitwatch"
|
||||||
|
cp ${./gitwatch.sh} $dest
|
||||||
|
chmod +x $dest
|
||||||
|
patchShebangs $dest
|
||||||
|
|
||||||
|
wrapProgram $dest \
|
||||||
|
--prefix PATH ';' ${lib.makeBinPath [ git inotify-tools openssh ]}
|
||||||
|
''
|
@ -0,0 +1,84 @@
|
|||||||
|
{ lib, pkgs, config, ... }:
|
||||||
|
let
|
||||||
|
gitwatch = pkgs.callPackage ./gitwatch.nix { };
|
||||||
|
mkSystemdService = name: cfg: lib.nameValuePair
|
||||||
|
"gitwatch-${name}"
|
||||||
|
(
|
||||||
|
let
|
||||||
|
getvar = flag: var:
|
||||||
|
if cfg."${var}" != null
|
||||||
|
then "${flag} ${cfg."${var}"}"
|
||||||
|
else "";
|
||||||
|
branch = getvar "-b" "branch";
|
||||||
|
fetcher =
|
||||||
|
if cfg.remote == null
|
||||||
|
then "true"
|
||||||
|
else ''
|
||||||
|
'';
|
||||||
|
in
|
||||||
|
{
|
||||||
|
inherit (cfg) enable;
|
||||||
|
after = [ "network-online.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
|
||||||
|
${fetcher}
|
||||||
|
gitwatch ${getvar "-r" "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 = "git@github.com:me/my-project.git";
|
||||||
|
};
|
||||||
|
disabled-repo = {
|
||||||
|
enable = false;
|
||||||
|
user = "user";
|
||||||
|
path = "/home/user/disabled-project";
|
||||||
|
remote = "git@github.com: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;
|
||||||
|
}
|
Loading…
Reference in New Issue