No description
- Nix 100%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
| nix | ||
| .envrc | ||
| .gitignore | ||
| flake.lock | ||
| flake.nix | ||
| README.md | ||
services-flake-caddy
A services-flake add-on providing a Caddy service for local HTTPS reverse proxies.
Remote: https://forgejo.920301.xyz/dan/services-flake-caddy.git
Usage
Add the flake as an input and import its process-compose module alongside services-flake:
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-parts.url = "github:hercules-ci/flake-parts";
systems.url = "github:nix-systems/default";
process-compose-flake.url = "github:Platonic-Systems/process-compose-flake";
services-flake.url = "github:juspay/services-flake";
services-flake-caddy.url = "git+https://forgejo.920301.xyz/dan/services-flake-caddy.git";
};
outputs = inputs:
inputs.flake-parts.lib.mkFlake { inherit inputs; } {
systems = import inputs.systems;
imports = [ inputs.process-compose-flake.flakeModule ];
perSystem = { pkgs, ... }: {
process-compose.default = {
imports = [
inputs.services-flake.processComposeModules.default
inputs.services-flake-caddy.processComposeModules.default
];
services.caddy.caddy1 = {
enable = true;
projectName = "demo";
routes = {
authelia.upstream = "127.0.0.1:9091";
api.upstream = "127.0.0.1:8080";
};
};
services.authelia.authelia1.enable = true;
};
};
};
}
Then run:
nix run .#default
authelia is available at https://authelia.demo.localhost and api at https://api.demo.localhost.
Options
services.caddy.<name>.enable— enable the service.projectName— used for generated hostnames (defaultdev).httpPort/httpsPort— default80/443.routes.<route>.host— hostname (default<route>.<projectName>.localhost).routes.<route>.upstream— upstreamhost:port.routes.<route>.extraConfig— extra Caddyfile directives for the host.extraGlobalConfig/extraConfig— escape hatches for the Caddyfile.trust.enable— install Caddy's local CA into trust stores (defaulttrue).trust.useSudo— usesudoforcaddy truston Linux (defaulttrueon Linux).
Certificate trust
Caddy uses its internal CA. On first run it generates a root certificate under
dataDir/caddy/pki/authorities/local/root.crt.
- macOS: Caddy installs it into the system Keychain automatically.
- Linux: the
caddy-trustprocess runssudo caddy trust ...; passwordless sudo may be required. - NixOS: add the generated root certificate to
security.pki.certificateFiles(see the NixOS note below). - WSL: copy the root certificate to the Windows host and import it into the Windows certificate store (see the WSL note below).
NixOS
Because the NixOS trust store is built at evaluation time, reference the generated certificate path and rebuild after the first Caddy run:
security.pki.certificateFiles = [
"/path/to/your/project/data/caddy1/caddy/pki/authorities/local/root.crt"
];
WSL
Copy root.crt to a Windows-accessible path and import it, for example with PowerShell run as administrator:
Import-Certificate -FilePath C:\path\to\root.crt -CertStoreLocation Cert:\LocalMachine\Root
Notes
- Binding ports
80/443may require elevated privileges on some systems. - Automatic service discovery from process-compose is not implemented yet; routes are declared manually. EOF echo written