0xdsqr/posts/misc/about
Dave Dennis (@0xdsqr)
••
Cloudflare Tunnels CLI with Nix

Cloudflare Tunnels CLI with Nix

Author
·
November 3, 2025·3 min·NixWithMe
nixcloudflaretunnelshomelab
Loading post...

comments (0)

sign in to leave a comment

no comments yet. be the first to share your thoughts.

  • Installing cloudflared on NixOS
  • Using configuration.nix
  • Using Home Manager
  • Using Flake.nix
  • Command Line Installation
  • CLI Commands

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

1
2
3
4
5
6
7
{ config, pkgs, ... }:

{
  environment.systemPackages = with pkgs; [
    cloudflared
  ];
}

Using Home Manager

1
2
3
4
5
6
7
{ config, pkgs, ... }:

{
  home.packages = with pkgs; [
    cloudflared
  ];
}

Using Flake.nix

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
{
  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

1
2
3
4
5
# 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:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# 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>