I was playing around setting up Cloudflare tunnels on my homelab. These are some random things I learned.
Installing cloudflared on NixOS
There are several ways to install the Cloudflare Tunnel CLI tool on NixOS:
Using configuration.nix
1234567
{ config, pkgs, ... }:
{
environment.systemPackages = with pkgs; [
cloudflared
];
}
Using Home Manager
1234567
{ config, pkgs, ... }:
{
home.packages = with pkgs; [
cloudflared
];
}
Using Flake.nix
123456789101112131415161718
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
# Other inputs...
};
outputs = { self, nixpkgs, ... }: {
nixosConfigurations.myhost = nixpkgs.lib.nixosSystem {
# ...
modules = [
# ...
({ config, pkgs, ... }: {
environment.systemPackages = [ pkgs.cloudflared ];
})
];
};
};
}
Command Line Installation
12345
# Using nix-env
nix-env -iA nixos.cloudflared
# Using nix profile (flakes)
nix profile install nixpkgs#cloudflared
CLI Commands
These commands will get you started with managing Cloudflare tunnels:
1234567891011121314151617181920
# Login to Cloudflare
cloudflared tunnel login
# Create a new tunnel
cloudflared tunnel create <tunnel-name>
# List existing tunnels
cloudflared tunnel list
# Delete a tunnel
cloudflared tunnel delete <tunnel-id>
# Route traffic to your tunnel
cloudflared tunnel route dns <tunnel-name> <hostname>
# Run a tunnel locally
cloudflared tunnel run <tunnel-name>
# Configure a tunnel with a config file
cloudflared tunnel --config config.yml run <tunnel-name>

