fork of whitequark.org/git-pages with mods for tangled

nix: add nixos module and vm to play around in

Signed-off-by: oppiliappan <me@oppi.li>

oppi.li b7dcdf1d dcf70dfd

verified
Changed files
+260 -1
nix
+1
.gitignore
··· 4 4 /data 5 5 /config*.toml* 6 6 /git-pages 7 + nixos.qcow2
+38 -1
flake.nix
··· 63 63 inherit git-pages; 64 64 default = git-pages; 65 65 }; 66 + 67 + apps.vm = 68 + let 69 + guestSystem = if pkgs.stdenv.hostPlatform.isAarch64 then "aarch64-linux" else "x86_64-linux"; 70 + in 71 + { 72 + type = "app"; 73 + program = 74 + (pkgs.writeShellApplication { 75 + name = "vm"; 76 + text = '' 77 + exec ${ 78 + pkgs.lib.getExe 79 + (import ./nix/vm.nix { 80 + inherit nixpkgs self; 81 + system = guestSystem; 82 + hostSystem = system; 83 + }).config.system.build.vm 84 + } 85 + ''; 86 + }) 87 + + /bin/vm; 88 + }; 66 89 } 67 - ); 90 + ) 91 + // { 92 + nixosModules.default = 93 + { 94 + lib, 95 + pkgs, 96 + ... 97 + }: 98 + { 99 + imports = [ ./nix/module.nix ]; 100 + services.git-pages.package = 101 + lib.mkDefault 102 + self.packages.${pkgs.stdenv.hostPlatform.system}.git-pages; 103 + }; 104 + }; 68 105 }
+127
nix/module.nix
··· 1 + { 2 + config, 3 + lib, 4 + pkgs, 5 + ... 6 + }: 7 + 8 + with lib; 9 + 10 + let 11 + cfg = config.services.git-pages; 12 + configFile = pkgs.writeText "git-pages-config.toml" cfg.configFile; 13 + in 14 + { 15 + options.services.git-pages = { 16 + enable = mkEnableOption "git-pages static site server"; 17 + 18 + package = mkOption { 19 + type = types.package; 20 + description = "The git-pages package to use."; 21 + }; 22 + 23 + user = mkOption { 24 + type = types.str; 25 + default = "git-pages"; 26 + description = "User under which git-pages runs."; 27 + }; 28 + 29 + group = mkOption { 30 + type = types.str; 31 + default = "git-pages"; 32 + description = "Group under which git-pages runs."; 33 + }; 34 + 35 + dataDir = mkOption { 36 + type = types.path; 37 + default = "/var/lib/git-pages"; 38 + description = "Directory where git-pages stores its data."; 39 + }; 40 + 41 + configFile = mkOption { 42 + type = types.lines; 43 + default = '' 44 + [server] 45 + pages = "tcp/:3000" 46 + caddy = "tcp/:3001" 47 + metrics = "tcp/:3002" 48 + 49 + [storage] 50 + type = "fs" 51 + 52 + [storage.fs] 53 + root = "${cfg.dataDir}/data" 54 + 55 + [limits] 56 + max-site-size = "128M" 57 + ''; 58 + }; 59 + 60 + openFirewall = mkOption { 61 + type = types.bool; 62 + default = false; 63 + description = "Whether to open the firewall for git-pages ports."; 64 + }; 65 + 66 + ports = { 67 + pages = mkOption { 68 + type = types.port; 69 + default = 3000; 70 + description = "Port for the main pages server."; 71 + }; 72 + 73 + caddy = mkOption { 74 + type = types.port; 75 + default = 3001; 76 + description = "Port for the Caddy integration endpoint."; 77 + }; 78 + 79 + metrics = mkOption { 80 + type = types.port; 81 + default = 3002; 82 + description = "Port for Prometheus metrics."; 83 + }; 84 + }; 85 + }; 86 + 87 + config = mkIf cfg.enable { 88 + users.users.${cfg.user} = { 89 + isSystemUser = true; 90 + group = cfg.group; 91 + home = cfg.dataDir; 92 + createHome = true; 93 + description = "git-pages service user"; 94 + }; 95 + 96 + users.groups.${cfg.group} = { }; 97 + 98 + systemd.services.git-pages = { 99 + description = "git-pages static site server"; 100 + after = [ "network.target" ]; 101 + wantedBy = [ "multi-user.target" ]; 102 + 103 + serviceConfig = { 104 + Type = "simple"; 105 + User = cfg.user; 106 + Group = cfg.group; 107 + WorkingDirectory = cfg.dataDir; 108 + ExecStart = "${cfg.package}/bin/git-pages -config ${configFile}"; 109 + Restart = "on-failure"; 110 + RestartSec = 5; 111 + }; 112 + }; 113 + 114 + systemd.tmpfiles.rules = [ 115 + "d '${cfg.dataDir}' 0750 ${cfg.user} ${cfg.group} - -" 116 + "d '${cfg.dataDir}/data' 0750 ${cfg.user} ${cfg.group} - -" 117 + ]; 118 + 119 + networking.firewall = mkIf cfg.openFirewall { 120 + allowedTCPPorts = with cfg.ports; [ 121 + pages 122 + caddy 123 + metrics 124 + ]; 125 + }; 126 + }; 127 + }
+94
nix/vm.nix
··· 1 + { 2 + nixpkgs, 3 + system, 4 + hostSystem, 5 + self, 6 + }: 7 + nixpkgs.lib.nixosSystem { 8 + inherit system; 9 + modules = [ 10 + self.nixosModules.default 11 + ( 12 + { 13 + lib, 14 + config, 15 + pkgs, 16 + ... 17 + }: 18 + { 19 + virtualisation.vmVariant.virtualisation = { 20 + host.pkgs = import nixpkgs { system = hostSystem; }; 21 + 22 + graphics = false; 23 + memorySize = 2048; 24 + diskSize = 10 * 1024; 25 + cores = 2; 26 + forwardPorts = [ 27 + # ssh 28 + { 29 + from = "host"; 30 + host.port = 2222; 31 + guest.port = 22; 32 + } 33 + # git-pages main server 34 + { 35 + from = "host"; 36 + host.port = 3000; 37 + guest.port = 3000; 38 + } 39 + # git-pages caddy integration 40 + { 41 + from = "host"; 42 + host.port = 3001; 43 + guest.port = 3001; 44 + } 45 + # git-pages metrics 46 + { 47 + from = "host"; 48 + host.port = 3002; 49 + guest.port = 3002; 50 + } 51 + ]; 52 + }; 53 + 54 + networking.firewall.enable = false; 55 + time.timeZone = "Europe/London"; 56 + services.getty.autologinUser = "root"; 57 + environment.systemPackages = with pkgs; [ 58 + curl 59 + vim 60 + git 61 + htop 62 + ]; 63 + 64 + services.git-pages = { 65 + enable = true; 66 + dataDir = "/var/lib/git-pages"; 67 + configFile = '' 68 + [server] 69 + pages = "tcp/0.0.0.0:3000" 70 + caddy = "tcp/0.0.0.0:3001" 71 + metrics = "tcp/0.0.0.0:3002" 72 + 73 + [storage] 74 + type = "fs" 75 + 76 + [storage.fs] 77 + root = "/var/lib/git-pages/data" 78 + 79 + # Example wildcard configuration for development 80 + [[wildcard]] 81 + domain = "*.localhost" 82 + clone-url = "https://github.com/{domain}.git" 83 + authorization = "" 84 + ''; 85 + }; 86 + 87 + users = { 88 + users.${config.services.git-pages.user}.uid = 777; 89 + groups.${config.services.git-pages.group}.gid = 777; 90 + }; 91 + } 92 + ) 93 + ]; 94 + }