make tailscale auth service be defined just once

This commit is contained in:
Cyryl Płotnicki 2022-08-19 18:51:44 +01:00
parent cec7e544c2
commit 4b83cae3ba
16 changed files with 101 additions and 217 deletions

View file

@ -2,9 +2,7 @@
imports = [ imports = [
./bolty-boot.nix ./bolty-boot.nix
./real-hardware.nix ./real-hardware.nix
./tailscale-bolty.nix
../../server-security.nix ../../server-security.nix
../../tailscale.nix
../cli.nix ../cli.nix
./matrix-server.nix ./matrix-server.nix
./nextcloud.nix ./nextcloud.nix

View file

@ -1,31 +0,0 @@
{ config, pkgs, inputs, lib, ... }:
let
inherit (inputs.nixpkgs-nixos-unstable.legacyPackages."x86_64-linux") tailscale;
in {
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 = ''
# wait for tailscaled to settle
sleep 2
# check if we are already authenticated to tailscale
status="$(${tailscale}/bin/tailscale status -json | ${pkgs.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-kmZDQd4CNTRL-Ezwsqwk6xnVjLyLTGS1N7
'';
};
}

View file

@ -4,7 +4,6 @@
imports = [ imports = [
inputs.nixos-hardware.nixosModules.lenovo-thinkpad-t480 inputs.nixos-hardware.nixosModules.lenovo-thinkpad-t480
./hardware-configuration.nix ./hardware-configuration.nix
./tailscale-foureighty.nix
./thermal.nix ./thermal.nix
../../backups.nix ../../backups.nix
../../boot.nix ../../boot.nix
@ -15,7 +14,6 @@
../../i3 ../../i3
../../libvirt.nix ../../libvirt.nix
../../mercurial ../../mercurial
../../tailscale.nix
]; ];
fileSystems."/" = { options = [ "compress=zstd" ]; }; fileSystems."/" = { options = [ "compress=zstd" ]; };

View file

@ -1,32 +0,0 @@
{ config, pkgs, inputs, lib, ... }:
let
inherit (inputs.nixpkgs-nixos-unstable.legacyPackages."x86_64-linux")
tailscale;
in {
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 = ''
# wait for tailscaled to settle
sleep 2
# check if we are already authenticated to tailscale
status="$(${tailscale}/bin/tailscale status -json | ${pkgs.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-kaL3of6CNTRL-SkvotNvHLZSzmX3oob7ot
'';
};
}

View file

@ -3,7 +3,6 @@
imports = [ imports = [
./hardware-configuration.nix ./hardware-configuration.nix
./tailscale-skinnyv.nix
../../boot.nix ../../boot.nix
../../common.nix ../../common.nix
../../backups.nix ../../backups.nix
@ -13,7 +12,6 @@
../../gui ../../gui
../../i3 ../../i3
../../mercurial ../../mercurial
../../tailscale.nix
]; ];
boot.kernelPackages = pkgs.linuxPackages_latest; boot.kernelPackages = pkgs.linuxPackages_latest;

View file

@ -1,32 +0,0 @@
{ config, pkgs, inputs, lib, ... }:
let
inherit (inputs.nixpkgs-nixos-unstable.legacyPackages."x86_64-linux")
tailscale;
in {
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 = ''
# wait for tailscaled to settle
sleep 2
# check if we are already authenticated to tailscale
status="$(${tailscale}/bin/tailscale status -json | ${pkgs.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-kxGKSM5CNTRL-bMbXerV97q5LrVPUrHWjv
'';
};
}

View file

@ -3,7 +3,6 @@
imports = [ imports = [
./hardware-configuration.nix ./hardware-configuration.nix
./tailscale-thinky.nix
../../backups.nix ../../backups.nix
../../boot.nix ../../boot.nix
../../common.nix ../../common.nix
@ -13,7 +12,6 @@
../../gui ../../gui
../../i3 ../../i3
../../mercurial ../../mercurial
../../tailscale.nix
]; ];
time.timeZone = "Europe/Warsaw"; time.timeZone = "Europe/Warsaw";

View file

@ -1,31 +0,0 @@
{ config, pkgs, inputs, lib, ... }:
let
inherit (inputs.nixpkgs-nixos-unstable.legacyPackages."x86_64-linux") tailscale;
in {
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 = ''
# wait for tailscaled to settle
sleep 2
# check if we are already authenticated to tailscale
status="$(${tailscale}/bin/tailscale status -json | ${pkgs.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-d046113d18dc78d71fd82afb
'';
};
}

View file

@ -3,11 +3,9 @@
imports = [ imports = [
./vpsfree1-vpsadminos.nix ./vpsfree1-vpsadminos.nix
./tailscale-vpsfree1.nix
../cli.nix ../cli.nix
../../server-security.nix ../../server-security.nix
../../server-common.nix ../../server-common.nix
../../tailscale.nix
./foundryvtt.nix ./foundryvtt.nix
./cryptpad.nix ./cryptpad.nix
./syncthing-relay.nix ./syncthing-relay.nix

View file

@ -1,31 +0,0 @@
{ config, pkgs, inputs, lib, ... }:
let
inherit (inputs.nixpkgs-nixos-unstable.legacyPackages."x86_64-linux") tailscale;
in {
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 = ''
# wait for tailscaled to settle
sleep 2
# check if we are already authenticated to tailscale
status="$(${tailscale}/bin/tailscale status -json | ${pkgs.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-ketJA57CNTRL-d8cMQZK6jjgtSDgXiarET1
'';
};
}

View file

@ -3,7 +3,6 @@
imports = [ imports = [
./vultr-boot.nix ./vultr-boot.nix
./tailscale-vultr1.nix
./folding.nix ./folding.nix
./matrix-front.nix ./matrix-front.nix
./../nginx.nix ./../nginx.nix
@ -12,7 +11,6 @@
../cli.nix ../cli.nix
../../server-security.nix ../../server-security.nix
../../server-common.nix ../../server-common.nix
../../tailscale.nix
]; ];
systemd.extraConfig = '' systemd.extraConfig = ''

View file

@ -1,32 +0,0 @@
{ config, pkgs, inputs, lib, ... }:
let
inherit (inputs.nixpkgs-nixos-unstable.legacyPackages."x86_64-linux")
tailscale;
in {
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 = ''
# wait for tailscaled to settle
sleep 2
# check if we are already authenticated to tailscale
status="$(${tailscale}/bin/tailscale status -json | ${pkgs.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-kmTDw84CNTRL-WH1VhCX2XkFBZr84FfNm9Y
'';
};
}

View file

@ -1,5 +1,6 @@
{ config, pkgs, ... }: { { config, pkgs, ... }: {
console.keyMap = "pl"; console.keyMap = "pl";
imports = [ ./tailscale ];
services = { services = {
udev.packages = [ pkgs.android-udev-rules ]; udev.packages = [ pkgs.android-udev-rules ];
ratbagd.enable = true; ratbagd.enable = true;

View file

@ -1,16 +0,0 @@
{ config, pkgs, inputs, ... }:
let
inherit (inputs.nixpkgs-nixos-unstable.legacyPackages."x86_64-linux") tailscale;
in {
environment.systemPackages = [ tailscale ];
services.tailscale = {
enable = true;
package = tailscale;
};
networking.firewall = {
trustedInterfaces = [ "tailscale0" ];
allowedUDPPorts = [ config.services.tailscale.port ];
};
}

View file

@ -0,0 +1,43 @@
{ config, pkgs, inputs, ... }:
let
inherit (inputs.nixpkgs-nixos-unstable.legacyPackages."x86_64-linux")
tailscale;
in {
environment.systemPackages = [ tailscale ];
services.tailscale = {
enable = true;
package = tailscale;
};
networking.firewall = {
trustedInterfaces = [ "tailscale0" ];
allowedUDPPorts = [ config.services.tailscale.port ];
};
sops.secrets."tailscale-key-${config.networking.hostName}" = {
mode = "0440";
owner = config.users.users.cyryl.name;
group = config.users.users.cyryl.group;
sopsFile = ./keys.sops.yaml;
};
systemd.services.tailscale-auth = {
description = "Auth with tailscale";
after = [ "network-pre.target" "tailscale.service" ];
wants = [ "network-pre.target" "tailscale.service" ];
wantedBy = [ "multi-user.target" ];
serviceConfig.Type = "oneshot";
script = ''
sleep 2
status="$(${tailscale}/bin/tailscale status -json | ${pkgs.jq}/bin/jq -r .BackendState)"
if [ $status = "Running" ]; then # if so, then do nothing
exit 0
fi
${tailscale}/bin/tailscale up -authkey `cat /run/secrets/tailscale-key-${config.networking.hostName}`
'';
};
}

View file

@ -0,0 +1,57 @@
tailscale-key-foureighty: ENC[AES256_GCM,data:9Yc2Bwf+WvFbz0L1UxEvFszXsfzsubDbiRbELMHUkRS8x4FJqZeGTw==,iv:sT5gbrlM3Id/XMD9S5v4tsohoRJpY3gyFVzKNQSYOYg=,tag:26+nM805hVZxYRnCtWisFg==,type:str]
sops:
kms: []
gcp_kms: []
azure_kv: []
hc_vault: []
age:
- recipient: age1qpxvqf2254vynw7aah2pyd8tm0lqtfqr9maguewdj3uqjp8smqvssjp43n
enc: |
-----BEGIN AGE ENCRYPTED FILE-----
YWdlLWVuY3J5cHRpb24ub3JnL3YxCi0+IFgyNTUxOSBheGtxVUdCb3hyL0J5dktV
cytQaEx1SVJ4dlF5WmU0WXBxaERzSHJvRm1NCmxObWJyZ01tdUFCbGVtdUN5ZU9J
eUhkNERSZVVGWmlDSkIvelZmQWNKTXMKLS0tIEVldGRTK1A2dnpIN2pnTnhpQjBO
SUFFUnV6ZnZsSzE2MHRyWnJuSGtYMk0KkTCNAcfoh3yOHNsB7yEZujWxMvt8jvwW
A1x8ne6EDEqAOi9qpC7GqY8g7jQ+wEktdVseKZORs52eEZOLTEAH/Q==
-----END AGE ENCRYPTED FILE-----
- recipient: age1s3z2rfske90kt93a3z7twp6kew6mqd08sgunupym0gpmuh8ezqqscdrv7m
enc: |
-----BEGIN AGE ENCRYPTED FILE-----
YWdlLWVuY3J5cHRpb24ub3JnL3YxCi0+IFgyNTUxOSBQdXAwMmRYUFhhQzgwY2pz
cmtJNWVIMjJjb3lML2k3NCtPUWlaQTdmYUJvCitFeEUvTmV3UndjMEp2dHY0QXdC
S0lKWSswTE1nNU9DSkc1SUNtN2xPZlUKLS0tIGpHdllZdkNJY1lKSWdkaG9PYTI3
aVJ3SWhZV0h0WGs5T1ZxNTA1TDVLNm8K1ikCGLZ2ldqGndKSv96N89sP+ZAP6DRS
ryfrDLiSAtnP3TkBf4AjYyzSGqoLio24PdCMmrMK1kJB9j1HdWz60g==
-----END AGE ENCRYPTED FILE-----
- recipient: age1p76577kkfttxxj8ckwwkhyhhz7qq2d7qf2lenyaa0g3v2gd3eecqhhf9jn
enc: |
-----BEGIN AGE ENCRYPTED FILE-----
YWdlLWVuY3J5cHRpb24ub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FB1L0F5eE9CUXBMWXMK5Eqhb43xV4Itt+FIQeGn0iJP/a43Fk+9
d8r9mvv7ZKRCWPjJCkJnX+5r1nBKzcLqa/tCPNqT+pXDfAy6gJVtcQ==
-----END AGE ENCRYPTED FILE-----
lastmodified: "2022-08-19T17:37:35Z"
mac: ENC[AES256_GCM,data:qnyVQpFRiLoAwFt9Ph0PHvUqWhPmqoysHXwWIZXVYUoOX3fgVEQJBk5hdenqZh7hYV7++uW3wl7c5w5XaBvM3fzFhwocy+qP4NpcVv9yP9XMNPbPAehJTSJ6SgYU0pkCl5m675cuCt4Ify+iITN2b4s4Luyn/IwnMNXQTF7FUZs=,iv:w+fr5j4l0T+hKbTTM8KR9HbhuIk3xvfv15O/xrabiAE=,tag:2MFDkmOOkt1h5K/yOXxxAg==,type:str]
pgp: []
unencrypted_suffix: _unencrypted
version: 3.7.3