default.nix (3433B)
1 { 2 config, 3 pkgs, 4 inputs, 5 ... 6 }: 7 let 8 mainServer = ../main-server; 9 10 rootDomain = import "${mainServer}/domain.nix"; 11 gitDomain = "git.${rootDomain}"; 12 13 scripts = import ./scripts.nix { inherit config pkgs inputs; }; 14 15 stagit = { 16 destDir = config.modules.quark.directory; 17 reposDir = config.modules.git.directory; 18 }; 19 in 20 { 21 imports = [ 22 ./disk-config.nix 23 ]; 24 25 modules = { 26 bind = { 27 enable = true; 28 domain = rootDomain; 29 records = import "${mainServer}/dns.nix" rootDomain; 30 }; 31 quark = { 32 enable = true; 33 user = "git"; 34 preStart = { 35 scripts = 36 let 37 stagitCreate = scripts.stagitCreate { 38 inherit (stagit) destDir reposDir; 39 httpBaseUrl = "https://${gitDomain}"; 40 }; 41 42 stagitCreateAndChown = 43 let 44 script = pkgs.writeShellScriptBin "stagit-create-and-chown" '' 45 ${stagitCreate} 46 ${pkgs.sbase}/bin/chown -R git:git ${stagit.destDir} 47 ${pkgs.sbase}/bin/chmod -R u+rw ${stagit.destDir} 48 ''; 49 in 50 "${script}/bin/stagit-create-and-chown"; 51 52 copyRepositories = pkgs.writeShellScript "copy-repositories" '' 53 ${pkgs.sbase}/bin/cp -R \ 54 ${config.modules.git.directory}/* \ 55 ${config.modules.quark.directory} 56 ''; 57 in 58 [ 59 stagitCreateAndChown 60 copyRepositories 61 ]; 62 }; 63 acme = { 64 enable = true; 65 email = "admin@${rootDomain}"; 66 domain = gitDomain; 67 }; 68 tls = { 69 enable = true; 70 pemFiles = 71 let 72 inherit (config.modules.quark.acme) directory; 73 in 74 [ 75 "${directory}/${gitDomain}/fullchain.pem" 76 "${directory}/${gitDomain}/privkey.pem" 77 ]; 78 }; 79 }; 80 git = { 81 enable = true; 82 repositories = 83 { 84 flake = { 85 description = "Francesco Saccone's Nix flake."; 86 }; 87 hermes = { 88 description = "HTTP GET/HEAD-only web server for static content."; 89 }; 90 password-store = { 91 description = "Francesco Saccone's password store."; 92 }; 93 site = { 94 description = "Francesco Saccone's site content."; 95 }; 96 } 97 |> builtins.mapAttrs ( 98 name: 99 { description }: 100 { 101 additionalFiles = { 102 inherit description; 103 owner = "Francesco Saccone"; 104 url = "https://${gitDomain}/${name}"; 105 }; 106 hooks.postReceive = 107 builtins.concatStringsSep "\n" [ 108 (scripts.stagitPostReceive { 109 inherit (stagit) destDir reposDir; 110 inherit name; 111 httpBaseUrl = "https://${gitDomain}"; 112 }) 113 "git update-server-info" # Dumb HTTP protocol 114 ] 115 |> pkgs.writeShellScript "post-receive"; 116 } 117 ); 118 daemon = { 119 enable = true; 120 }; 121 }; 122 openssh.listen = { 123 enable = true; 124 port = 22; 125 authorizedKeyFiles = rec { 126 root = [ 127 "${mainServer}/ssh/francescosaccone.pub" 128 ]; 129 git = root; 130 }; 131 }; 132 }; 133 134 networking.domain = gitDomain; 135 }