Run ngrok as a service on your NixOS machine
When using configuration.nix
you can include ngrok service as follows:
{ pkgs, config, ... }:
let
ngrok = builtins.fetchGit {
url = "https://github.com/ngrok/ngrok-nix";
rev = "c56189898f263153a2a16775ea2b871084a4efb0";
};
in
{
nixpkgs.config.allowUnfree = true;
imports = [
"${ngrok}/nixos.nix"
];
services.ngrok = {
enable = true;
extraConfig = { };
extraConfigFiles = [
# reference to files containing `authtoken` and `api_key` secrets
# ngrok will merge these, together with `extraConfig`
];
tunnels = {
# ...
};
};
}
With flakes, things are even easier:
{
inputs = {
ngrok.url = "github:ngrok/ngrok-nix";
};
outputs = { self, ngrok, ... }@inputs: {
nixosConfigurations."<YOUR_HOSTNAME>" = nixpkgs.lib.nixosSystem {
system = "x86_64-linux";
modules = [
ngrok.nixosModules.ngrok
({ pkgs, ... }: {
nixpkgs.config.allowUnfree = true;
services.ngrok = {
enable = true;
extraConfig = { };
extraConfigFiles = [
# reference to files containing `authtoken` and `api_key` secrets
# ngrok will merge these, together with `extraConfig`
];
tunnels = {
# ...
};
};
})
];
};
};
}