tailscale on brix

This commit is contained in:
Cyryl Płotnicki 2021-06-12 15:07:38 +01:00
parent 5cda9a116c
commit dbb47dbcd9
4 changed files with 41 additions and 0 deletions

View file

@ -6,6 +6,8 @@
../../server-security.nix
../cli.nix
../vpn.nix
../../tailscale.nix
./tailscale-brix.nix
./restic-server.nix
./i2p.nix
./print-server.nix

View file

@ -0,0 +1,29 @@
{ config, pkgs, inputs, lib, ... }:
{
systemd.services.tailscale-autoconnect = {
description = "Automatic connection to Tailscale";
# make sure tailscale is running before trying to connect to tailscale
after = [ "network-pre.target" "tailscale.service" ];
wants = [ "network-pre.target" "tailscale.service" ];
wantedBy = [ "multi-user.target" ];
# set this service as a oneshot job
serviceConfig.Type = "oneshot";
# have the job run this shell script
script = with pkgs; ''
# wait for tailscaled to settle
sleep 2
# check if we are already authenticated to tailscale
status="$(${tailscale}/bin/tailscale status -json | ${jq}/bin/jq -r .BackendState)"
if [ $status = "Running" ]; then # if so, then do nothing
exit 0
fi
# otherwise authenticate with tailscale
${tailscale}/bin/tailscale up -authkey tskey-abb12c2c0f365cfda4f897c7
'';
};
}

View file

@ -7,6 +7,7 @@
security.virtualisation.flushL1DataCache = "always";
security.apparmor.enable = true;
services.haveged.enable = true;
networking.firewall.enable = true;
boot.kernelParams = [
"page_poison=1"
"page_alloc.shuffle=1"

9
nixos/tailscale.nix Normal file
View file

@ -0,0 +1,9 @@
{ config, pkgs, ... }:
{
environment.systemPackages = [ pkgs.tailscale ];
services.tailscale.enable = true;
networking.firewall = {
trustedInterfaces = [ "tailscale0" ];
allowedUDPPorts = [ config.services.tailscale.port ];
};
}