Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
Signed-off-by: Xe Iaso <[email protected]>
  • Loading branch information
Xe Iaso committed Apr 11, 2023
0 parents commit 29092f7
Show file tree
Hide file tree
Showing 27 changed files with 191 additions and 0 deletions.
1 change: 1 addition & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
use flake
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.direnv
3 changes: 3 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM scratch

COPY root/ /
28 changes: 28 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
BSD 3-Clause License

Copyright (c) 2023, Tailscale Community

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

3. Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
41 changes: 41 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
description = "Flake utils demo";

inputs.flake-utils.url = "github:numtide/flake-utils";

outputs = { self, nixpkgs, flake-utils }:
flake-utils.lib.eachDefaultSystem (system:
let pkgs = nixpkgs.legacyPackages.${system}; in
{
devShells.default = pkgs.mkShell {
buildInputs = with pkgs; [ dive tree go_1_20 go-tools gotools gopls ];
};
}
);
}
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/with-contenv bash

set -euo pipefail

dir="$(mktemp -d)"
pushd .
cd "${dir}"

tarball="$(curl 'https://pkgs.tailscale.com/stable/?mode=json' | jq -r .Tarballs.amd64)"
version="$(echo ${tarball} | cut -d_ -f2)"

curl "https://pkgs.tailscale.com/stable/${tarball}" -o tailscale.tgz

tar xzf tailscale.tgz

cp -vrf "tailscale_${version}_amd64"/tailscale /usr/bin/tailscale
cp -vrf "tailscale_${version}_amd64"/tailscaled /usr/sbin/tailscaled

popd
rm -rf "${dir}"
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
oneshot
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/etc/s6-overlay/s6-rc.d/init-mod-universal-tailscale-postinstall/run
Empty file.
15 changes: 15 additions & 0 deletions root/etc/s6-overlay/s6-rc.d/init-mod-universal-tailscale/run
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/with-contenv bash

## Ubuntu
if [ -f /usr/bin/apt ]; then
echo "\
jq \
iptables" >> /mod-repo-packages-to-install.list

fi
# Alpine
if [ -f /sbin/apk ]; then
echo "\
jq \
iptables" >> /mod-repo-packages-to-install.list
fi
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
oneshot
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/etc/s6-overlay/s6-rc.d/init-mod-universal-tailscale/run
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
39 changes: 39 additions & 0 deletions root/etc/s6-overlay/s6-rc.d/svc-tailscale-up/run
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/usr/bin/with-contenv bash

FLAGS=""

# configure `tailscale up`
if ! [ -v TAILSCALE_AUTHKEY ]; then
echo '[!] TAILSCALE_AUTHKEY is not defined, this will print a login URL to the screen'
else
FLAGS="${FLAGS} --authkey=${TAILSCALE_AUTHKEY}"
fi

if [ -v TAILSCALE_HOSTNAME ]; then
FLAGS="${FLAGS} --hostname=${TAILSCALE_HOSTNAME}"
fi

if [ -v TAILSCALE_USE_SSH ]; then
FLAGS="${FLAGS} --ssh=${TAILSCALE_USE_SSH}"
fi

if [ -v TAILSCALE_BE_EXIT_NODE ]; then
echo '[!] acting as an exit node, you may need to approve this in the admin console'
FLAGS="${FLAGS} --advertise-exit-node=${TS_BE_EXIT_NODE}"
fi

tailscale up $FLAGS

# configure serve
if [ -v TAILSCALE_SERVE_PORT ] && [ -v TAILSCALE_SERVE_MODE ]; then
tailscale serve "${TAILSCALE_SERVE_MODE}":443 / http://localhost:"${TAILSCALE_SERVE_PORT}"
fi

# configure funnel
if [ -v TAILSCALE_FUNNEL ]; then
tailscale funnel 443 on
fi




1 change: 1 addition & 0 deletions root/etc/s6-overlay/s6-rc.d/svc-tailscale-up/type
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
oneshot
1 change: 1 addition & 0 deletions root/etc/s6-overlay/s6-rc.d/svc-tailscale-up/up
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/etc/s6-overlay/s6-rc.d/svc-tailscale-up/run
Empty file.
20 changes: 20 additions & 0 deletions root/etc/s6-overlay/s6-rc.d/svc-tailscale/run
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/with-contenv bash

FLAGS=""

if ! [ -e /dev/net/tun ]; then
FLAGS="$flags --tun=userspace-networking"
fi

if [ -v TAILSCALE_STATE_DIR ]; then
FLAGS="$FLAGS --statedir=${TAILSCALE_STATE_DIR}"
else
echo '[!] TAILSCALE_STATE_DIR is not set, this node will be ephemeral.'
FLAGS="$FLAGS --state=mem:"
fi

if ! [ -v TAILSCALE_TAILSCALED_LOG ]; then
tailscaled $FLAGS 2>&1 > /dev/null
else
tailscaled $FLAGS
fi
1 change: 1 addition & 0 deletions root/etc/s6-overlay/s6-rc.d/svc-tailscale/type
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
longrun
1 change: 1 addition & 0 deletions root/etc/s6-overlay/s6-rc.d/svc-tailscale/up
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/etc/s6-overlay/s6-rc.d/svc-tailscale-up/run

0 comments on commit 29092f7

Please sign in to comment.