1
Fork 0

Set up forgejo ssh

This commit is contained in:
prescientmoon 2024-09-11 16:30:19 +02:00
parent 861f2e81e2
commit a94ba0499d
Signed by: prescientmoon
SSH key fingerprint: SHA256:WFp/cO76nbarETAoQcQXuV+0h7XJsEsOCI0UsyPIy6U
4 changed files with 75 additions and 43 deletions

View file

@ -1,5 +1,9 @@
{ config, ... }: { pkgs, lib, ... }:
{ {
programs.ssh.enable = true; programs.ssh.enable = true;
satellite.persistence.at.state.apps.ssh.directories = [ ".ssh" ]; satellite.persistence.at.state.apps.ssh.directories = [ ".ssh" ];
# This allows me to push/pull to my forgejo server via SSH.
# See the docs for more details: https://developers.cloudflare.com/cloudflare-one/tutorials/gitlab/#configuring-ssh
programs.ssh.matchBlocks."ssh.git.moonythm.dev".proxyCommand = "${lib.getExe pkgs.cloudflared} access ssh --hostname %h";
} }

View file

@ -24,5 +24,6 @@
jupyterhub = 8420; jupyterhub = 8420;
guacamole = 8421; guacamole = 8421;
syncthing = 8422; syncthing = 8422;
forgejo-ssh = 8423;
}; };
} }

View file

@ -7,6 +7,10 @@
}; };
satellite.cloudflared.at.git.port = config.satellite.ports.forgejo; satellite.cloudflared.at.git.port = config.satellite.ports.forgejo;
satellite.cloudflared.at."ssh.git" = {
protocol = "ssh";
port = config.satellite.ports.forgejo-ssh;
};
services.forgejo = { services.forgejo = {
enable = true; enable = true;
@ -29,6 +33,8 @@
HTTP_PORT = config.satellite.cloudflared.at.git.port; HTTP_PORT = config.satellite.cloudflared.at.git.port;
ROOT_URL = config.satellite.cloudflared.at.git.url; ROOT_URL = config.satellite.cloudflared.at.git.url;
LANDING_PAGE = "prescientmoon"; # Make my profile the landing page LANDING_PAGE = "prescientmoon"; # Make my profile the landing page
SSH_DOMAIN = config.satellite.cloudflared.at."ssh.git".host;
SSH_PORT = config.satellite.ports.forgejo-ssh;
}; };
cron.ENABLED = true; cron.ENABLED = true;
@ -45,9 +51,7 @@
repository = { repository = {
DISABLE_STARS = true; DISABLE_STARS = true;
DISABLED_REPO_UNITS = ""; DISABLED_REPO_UNITS = "";
DEFAULT_REPO_UNITS = lib.strings.concatStringsSep "," [ DEFAULT_REPO_UNITS = lib.strings.concatStringsSep "," [ "repo.code" ];
"repo.code"
];
}; };
}; };
}; };

View file

@ -1,5 +1,6 @@
{ config, lib, ... }: { config, lib, ... }:
let cfg = config.satellite.cloudflared; let
cfg = config.satellite.cloudflared;
in in
{ {
options.satellite.cloudflared = { options.satellite.cloudflared = {
@ -17,7 +18,10 @@ in
at = lib.mkOption { at = lib.mkOption {
description = "List of hosts to set up ingress rules for"; description = "List of hosts to set up ingress rules for";
default = { }; default = { };
type = lib.types.attrsOf (lib.types.submodule ({ name, config, ... }: { type = lib.types.attrsOf (
lib.types.submodule (
{ name, config, ... }:
{
options = { options = {
subdomain = lib.mkOption { subdomain = lib.mkOption {
description = '' description = ''
@ -39,6 +43,12 @@ in
default = "${config.subdomain}.${cfg.domain}"; default = "${config.subdomain}.${cfg.domain}";
}; };
protocol = lib.mkOption {
description = "The protocol to redirect traffic through";
type = lib.types.str;
default = "http";
};
url = lib.mkOption { url = lib.mkOption {
description = "External https url used to access this host"; description = "External https url used to access this host";
type = lib.types.str; type = lib.types.str;
@ -46,23 +56,36 @@ in
}; };
config.url = "https://${config.host}"; config.url = "https://${config.host}";
})); }
)
);
}; };
}; };
config.services.cloudflared.tunnels.${cfg.tunnel}.ingress = lib.attrsets.mapAttrs' config.services.cloudflared.tunnels.${cfg.tunnel}.ingress = lib.attrsets.mapAttrs' (
(_: { port, host, ... }: { _:
{
port,
host,
protocol,
...
}:
{
name = host; name = host;
value = "http://localhost:${toString port}"; value = "${protocol}://localhost:${toString port}";
}) }
cfg.at; ) cfg.at;
config.satellite.dns.records = config.satellite.dns.records =
let mkDnsRecord = { subdomain, ... }: { let
mkDnsRecord =
{ subdomain, ... }:
{
type = "CNAME"; type = "CNAME";
at = subdomain; at = subdomain;
zone = cfg.domain; zone = cfg.domain;
value = "${cfg.tunnel}.cfargotunnel.com."; value = "${cfg.tunnel}.cfargotunnel.com.";
}; };
in lib.attrsets.mapAttrsToList (_: mkDnsRecord) cfg.at; in
lib.attrsets.mapAttrsToList (_: mkDnsRecord) cfg.at;
} }