nixos-dotfiles

nixos-dotfiles

https://git.tonybtw.com/nixos-dotfiles.git git://git.tonybtw.com/nixos-dotfiles.git
932 bytes raw
1
{pkgs, ...}: let
2
  deploy_hook = pkgs.writeShellScript "post-receive-deploy" ''
3
    REPO=$(basename $(pwd) .git)
4
    SITE=/www/sites/$REPO
5
6
    if [ -d "$SITE" ]; then
7
        GIT_WORK_TREE=$SITE git checkout -f
8
        echo "deployed $REPO → $SITE"
9
    else
10
        echo "no deploy target for $REPO (no $SITE directory)"
11
    fi
12
  '';
13
in {
14
  systemd.tmpfiles.rules = [
15
    "d /www/sites 0755 root root -"
16
    "L+ /srv/git/.deploy-hook - - - - ${deploy_hook}"
17
  ];
18
19
  environment.systemPackages = [
20
    (pkgs.writeShellScriptBin "git-enable-deploy" ''
21
      if [ -z "$1" ]; then
22
        echo "usage: git-enable-deploy <repo.git>"
23
        exit 1
24
      fi
25
      REPO="/srv/git/$1"
26
      if [ ! -d "$REPO" ]; then
27
        echo "repo not found: $REPO"
28
        exit 1
29
      fi
30
      ln -sf /srv/git/.deploy-hook "$REPO/hooks/post-receive"
31
      chmod +x "$REPO/hooks/post-receive"
32
      echo "enabled deploy hook for $1"
33
    '')
34
  ];
35
}