1
0
Fork 0
nixos-config/nixos/roles/git.nix

58 lines
2 KiB
Nix
Raw Normal View History

2019-07-31 09:16:47 +00:00
{ config, pkgs, lib, ... }:
let
me = config.m-0.private.me;
2019-08-02 03:20:43 +00:00
update-command = [
"${pkgs.systemd}/bin/systemctl"
2019-08-02 14:51:37 +00:00
"restart"
2020-06-26 16:07:47 +00:00
"test-config.service"
2019-08-02 03:20:43 +00:00
"--no-block"
];
2021-05-18 14:33:28 +00:00
post-update = pkgs.writeHaskellScript
{
name = "post-update";
bins = [ pkgs.git pkgs.laminar ];
imports = [
"System.Environment (lookupEnv)"
"System.Directory (withCurrentDirectory)"
];
} ''
2019-08-02 18:41:58 +00:00
checkout :: String -> IO FilePath
2020-01-19 18:34:36 +00:00
checkout path = do
2020-05-16 16:03:34 +00:00
(decodeUtf8 -> repoDir) <- mktemp "-d" |> captureTrim
git "clone" path repoDir
2020-05-16 16:06:48 +00:00
pure repoDir
2019-08-02 18:41:58 +00:00
2019-07-31 09:16:47 +00:00
main = do
2021-01-03 22:29:52 +00:00
jobMay <- lookupEnv "GL_OPTION_CI_JOB"
whenJust jobMay $ \job -> do
2021-01-07 04:39:50 +00:00
args <- toString . Text.intercalate " " . fmap toText <$> getArgs
2021-01-12 07:21:45 +00:00
setEnv "LAMINAR_REASON" [i|Build triggered by push to branch #{args}|]
2021-01-07 04:39:50 +00:00
jobName <- decodeUtf8 <$> (laminarc ["queue", job, [i|BRANCH=#{args}|]] |> captureTrim)
2021-01-05 04:12:48 +00:00
say [i|Queued job #{jobName}.\nSee https://ci.maralorn.de/jobs/#{Text.replace ":" "/" jobName}|]
2021-01-07 05:18:30 +00:00
mirrorMay <- lookupEnv "GL_OPTION_MIRROR"
whenJust mirrorMay $ \mirror -> do
say [i|Force pushing all branches to #{mirror}|]
git "push" "--all" "-f" mirror
2020-05-16 16:03:34 +00:00
deployMay <- lookupEnv "GL_OPTION_WEB_DEPLOY"
whenJust deployMay $ \deploy -> do
2020-05-27 15:16:01 +00:00
(maybe [] (\x -> ["-A", x]) -> target) <- lookupEnv "GL_OPTION_WEB_DEPLOY_NIX_TARGET"
2020-01-19 18:34:36 +00:00
(decodeUtf8 -> path) <- pwd |> captureTrim
2020-05-30 16:08:54 +00:00
say [i|Building default.nix #{show target} to /var/www/#{deploy}|]
2020-05-16 16:08:50 +00:00
bracket (checkout path) (rm "-rf") $ \repoDir -> withCurrentDirectory repoDir $ nix_build "-o" ([i|/var/www/#{deploy}|] :: String) target
2020-05-16 13:59:02 +00:00
say "Done"
2019-07-31 09:16:47 +00:00
'';
2021-05-18 14:33:28 +00:00
in
{
systemd.tmpfiles.rules =
let cfg = config.services.gitolite;
in
lib.mkAfter
[ "z ${cfg.dataDir}/.ssh/id_ed25519 0600 ${cfg.user} ${cfg.group} - -" ];
2019-07-31 21:56:52 +00:00
services.gitolite = {
enable = true;
user = "git";
2021-01-07 05:18:30 +00:00
adminPubkey = builtins.elemAt (pkgs.privateValue [ "" ] "ssh-keys") 0;
2019-07-31 21:56:52 +00:00
commonHooks = [ "${post-update}/bin/post-update" ];
};
2019-07-31 09:16:47 +00:00
}