From c179b45ac19a18fb8e92ebb6c909d801a1f4ee2c Mon Sep 17 00:00:00 2001 From: tux Date: Fri, 18 Sep 2026 19:22:58 +0530 Subject: [PATCH] feat(services): add coder nixos module --- modules/hosts/arcturus/config.nix | 6 ++ modules/nixos/services/coder.nix | 95 +++++++++++++++++++++++++++++++ 2 files changed, 101 insertions(+) create mode 100644 modules/nixos/services/coder.nix diff --git a/modules/hosts/arcturus/config.nix b/modules/hosts/arcturus/config.nix index 2e2a2d7..696e65a 100644 --- a/modules/hosts/arcturus/config.nix +++ b/modules/hosts/arcturus/config.nix @@ -81,6 +81,12 @@ }; configurePangolin = true; }; + + coder = { + enable = true; + domain = "coder.lab.tux.rs"; + configurePangolin = true; + }; }; virtualisation = { diff --git a/modules/nixos/services/coder.nix b/modules/nixos/services/coder.nix new file mode 100644 index 0000000..4a67cca --- /dev/null +++ b/modules/nixos/services/coder.nix @@ -0,0 +1,95 @@ +{ + flake.modules.nixos.services = { + config, + lib, + options, + ... + }: + with lib; let + cfg = config.tnix.services.coder; + port = toString cfg.port; + in { + options.tnix.services.coder = { + enable = mkEnableOption "Coder"; + + host = mkOption { + type = types.str; + default = "127.0.0.1"; + description = "Host on which Coder listens"; + }; + + port = mkOption { + type = types.port; + default = 1116; + description = "Port on which Coder listens"; + }; + + environment = options.services.coder.environment; + + domain = mkOption { + type = types.str; + default = ""; + description = "Domain on which Coder is available"; + }; + + configureNginx = mkOption { + type = types.bool; + default = false; + description = "Whether to configure Nginx as a reverse proxy for Coder"; + }; + + configurePangolin = mkOption { + type = types.bool; + default = false; + description = "Whether to configure Pangolin as a reverse proxy for Coder"; + }; + }; + + config = mkIf cfg.enable { + users.users.coder.extraGroups = ["docker"]; + + services = { + coder = { + enable = true; + accessUrl = "https://${cfg.domain}"; + listenAddress = "${cfg.host}:${port}"; + environment = cfg.environment; + }; + + nginx.virtualHosts.${cfg.domain} = mkIf cfg.configureNginx { + forceSSL = acmeHost != ""; + useACMEHost = mkIf (acmeHost != "") acmeHost; + locations."/" = { + proxyPass = "http://${cfg.host}:${port}"; + proxyWebsockets = true; + }; + }; + + newt.blueprint.proxy-resources = mkIf cfg.configurePangolin { + gitea = { + auth = { + sso-enabled = false; + }; + full-domain = cfg.domain; + name = "coder"; + protocol = "http"; + targets = [ + { + hostname = "localhost"; + method = "http"; + port = cfg.port; + healthcheck = { + hostname = "localhost"; + port = cfg.port; + scheme = "http"; + method = "GET"; + path = "/"; + }; + } + ]; + }; + }; + }; + }; + }; +}