mirror of
https://github.com/tailscale/tailscale.git
synced 2026-05-05 12:16:44 +02:00
This file was never truly necessary and has never actually been used in the history of Tailscale's open source releases. A Brief History of AUTHORS files --- The AUTHORS file was a pattern developed at Google, originally for Chromium, then adopted by Go and a bunch of other projects. The problem was that Chromium originally had a copyright line only recognizing Google as the copyright holder. Because Google (and most open source projects) do not require copyright assignemnt for contributions, each contributor maintains their copyright. Some large corporate contributors then tried to add their own name to the copyright line in the LICENSE file or in file headers. This quickly becomes unwieldy, and puts a tremendous burden on anyone building on top of Chromium, since the license requires that they keep all copyright lines intact. The compromise was to create an AUTHORS file that would list all of the copyright holders. The LICENSE file and source file headers would then include that list by reference, listing the copyright holder as "The Chromium Authors". This also become cumbersome to simply keep the file up to date with a high rate of new contributors. Plus it's not always obvious who the copyright holder is. Sometimes it is the individual making the contribution, but many times it may be their employer. There is no way for the proejct maintainer to know. Eventually, Google changed their policy to no longer recommend trying to keep the AUTHORS file up to date proactively, and instead to only add to it when requested: https://opensource.google/docs/releasing/authors. They are also clear that: > Adding contributors to the AUTHORS file is entirely within the > project's discretion and has no implications for copyright ownership. It was primarily added to appease a small number of large contributors that insisted that they be recognized as copyright holders (which was entirely their right to do). But it's not truly necessary, and not even the most accurate way of identifying contributors and/or copyright holders. In practice, we've never added anyone to our AUTHORS file. It only lists Tailscale, so it's not really serving any purpose. It also causes confusion because Tailscalars put the "Tailscale Inc & AUTHORS" header in other open source repos which don't actually have an AUTHORS file, so it's ambiguous what that means. Instead, we just acknowledge that the contributors to Tailscale (whoever they are) are copyright holders for their individual contributions. We also have the benefit of using the DCO (developercertificate.org) which provides some additional certification of their right to make the contribution. The source file changes were purely mechanical with: git ls-files | xargs sed -i -e 's/\(Tailscale Inc &\) AUTHORS/\1 contributors/g' Updates #cleanup Change-Id: Ia101a4a3005adb9118051b3416f5a64a4a45987d Signed-off-by: Will Norris <will@tailscale.com>
235 lines
7.1 KiB
Go
235 lines
7.1 KiB
Go
// Copyright (c) Tailscale Inc & contributors
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
//go:build !windows && !plan9
|
|
|
|
package vms
|
|
|
|
import (
|
|
"flag"
|
|
"fmt"
|
|
"os"
|
|
"os/exec"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
"text/template"
|
|
|
|
"tailscale.com/types/logger"
|
|
)
|
|
|
|
var (
|
|
verboseNixOutput = flag.Bool("verbose-nix-output", false, "if set, use verbose nix output (lots of noise)")
|
|
)
|
|
|
|
/*
|
|
NOTE(Xe): Okay, so, at a high level testing NixOS is a lot different than
|
|
other distros due to NixOS' determinism. Normally NixOS wants packages to
|
|
be defined in either an overlay, a custom packageOverrides or even
|
|
yolo-inline as a part of the system configuration. This is going to have
|
|
us take a different approach compared to other distributions. The overall
|
|
plan here is as following:
|
|
|
|
1. make the binaries as normal
|
|
2. template in their paths as raw strings to the nixos system module
|
|
3. run `nixos-generators -f qcow -o $CACHE_DIR/tailscale/nixos/version -c generated-config.nix`
|
|
4. pass that to the steps that make the virtual machine
|
|
|
|
It doesn't really make sense for us to use a premade virtual machine image
|
|
for this as that will make it harder to deterministically create the image.
|
|
*/
|
|
|
|
const nixosConfigTemplate = `
|
|
# NOTE(Xe): This template is going to be heavily commented.
|
|
|
|
# All NixOS modules are functions. Here is the function prelude for this NixOS
|
|
# module that defines the system. It is a function that takes in an attribute
|
|
# set (effectively a map[string]nix.Value) and destructures it to some variables:
|
|
{
|
|
# other NixOS settings as defined in other modules
|
|
config,
|
|
|
|
# nixpkgs, which is basically the standard library of NixOS
|
|
pkgs,
|
|
|
|
# the path to some system-scoped NixOS modules that aren't imported by default
|
|
modulesPath,
|
|
|
|
# the rest of the arguments don't matter
|
|
...
|
|
}:
|
|
|
|
# Nix's syntax was inspired by Haskell and other functional languages, so the
|
|
# let .. in pattern is used to create scoped variables:
|
|
let
|
|
# Define the package (derivation) for Tailscale based on the binaries we
|
|
# just built for this test:
|
|
testTailscale = pkgs.stdenv.mkDerivation {
|
|
# The name of the package. This usually includes a version however it
|
|
# doesn't matter here.
|
|
name = "tailscale-test";
|
|
|
|
# The path on disk to the "source code" of the package, in this case it is
|
|
# the path to the binaries that are built. This needs to be the raw
|
|
# unquoted slash-separated path, not a string containing the path because Nix
|
|
# has a special path type.
|
|
src = {{.BinPath}};
|
|
|
|
# We only need to worry about the install phase because we've already
|
|
# built the binaries.
|
|
phases = "installPhase";
|
|
|
|
# We need to wrap tailscaled such that it has iptables in its $PATH.
|
|
nativeBuildInputs = [ pkgs.makeWrapper ];
|
|
|
|
# The install instructions for this package ('' ''defines a multi-line string).
|
|
# The with statement lets us bring in values into scope as if they were
|
|
# defined in the current scope.
|
|
installPhase = with pkgs; ''
|
|
# This is bash.
|
|
|
|
# Make the output folders for the package (systemd unit and binary folders).
|
|
mkdir -p $out/bin
|
|
|
|
# Install tailscale{,d}
|
|
cp $src/tailscale $out/bin/tailscale
|
|
cp $src/tailscaled $out/bin/tailscaled
|
|
|
|
# Wrap tailscaled with the ip and iptables commands.
|
|
wrapProgram $out/bin/tailscaled --prefix PATH : ${
|
|
lib.makeBinPath [ iproute2 iptables ]
|
|
}
|
|
|
|
# Install systemd unit.
|
|
cp $src/systemd/tailscaled.service .
|
|
sed -i -e "s#/usr/sbin#$out/bin#" -e "/^EnvironmentFile/d" ./tailscaled.service
|
|
install -D -m0444 -t $out/lib/systemd/system ./tailscaled.service
|
|
'';
|
|
};
|
|
in {
|
|
# This is a QEMU VM. This module has a lot of common qemu VM settings so you
|
|
# don't have to set them manually.
|
|
imports = [ (modulesPath + "/profiles/qemu-guest.nix") ];
|
|
|
|
# We need virtio support to boot.
|
|
boot.initrd.availableKernelModules =
|
|
[ "ata_piix" "uhci_hcd" "virtio_pci" "sr_mod" "virtio_blk" ];
|
|
boot.initrd.kernelModules = [ ];
|
|
boot.kernelModules = [ ];
|
|
boot.extraModulePackages = [ ];
|
|
|
|
# Curl is needed for one of the steps in cloud-final
|
|
systemd.services.cloud-final.path = with pkgs; [ curl ];
|
|
|
|
# Curl is needed for one of the integration tests
|
|
environment.systemPackages = with pkgs; [ curl nix bash squid openssl daemonize ];
|
|
|
|
# yolo, this vm can sudo freely.
|
|
security.sudo.wheelNeedsPassword = false;
|
|
|
|
# nix considers squid insecure, but this is fine for a test.
|
|
nixpkgs.config.permittedInsecurePackages = [ "squid-7.0.1" ];
|
|
|
|
# Enable cloud-init so we can set VM hostnames and the like the same as other
|
|
# distros. This will also take care of SSH keys. It's pretty handy.
|
|
services.cloud-init = {
|
|
enable = true;
|
|
ext4.enable = true;
|
|
};
|
|
|
|
# We want sshd running.
|
|
services.openssh.enable = true;
|
|
|
|
# Tailscale settings:
|
|
services.tailscale = {
|
|
# We want Tailscale to start at boot.
|
|
enable = true;
|
|
|
|
# Use the Tailscale package we just assembled.
|
|
package = testTailscale;
|
|
};
|
|
|
|
# Override TS_LOG_TARGET to our private logcatcher.
|
|
systemd.services.tailscaled.environment."TS_LOG_TARGET" = "{{.LogTarget}}";
|
|
}`
|
|
|
|
func (h *Harness) copyUnit(t *testing.T) {
|
|
t.Helper()
|
|
|
|
data, err := os.ReadFile("../../../cmd/tailscaled/tailscaled.service")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
os.MkdirAll(filepath.Join(h.binaryDir, "systemd"), 0755)
|
|
err = os.WriteFile(filepath.Join(h.binaryDir, "systemd", "tailscaled.service"), data, 0666)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
|
|
func (h *Harness) makeNixOSImage(t *testing.T, d Distro, cdir string) string {
|
|
if d.Name == "nixos-unstable" {
|
|
t.Skip("https://github.com/NixOS/nixpkgs/issues/131098")
|
|
}
|
|
|
|
h.copyUnit(t)
|
|
dir := t.TempDir()
|
|
fname := filepath.Join(dir, d.Name+".nix")
|
|
fout, err := os.Create(fname)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
tmpl := template.Must(template.New("base.nix").Parse(nixosConfigTemplate))
|
|
err = tmpl.Execute(fout, struct {
|
|
BinPath string
|
|
LogTarget string
|
|
}{
|
|
BinPath: h.binaryDir,
|
|
LogTarget: h.loginServerURL,
|
|
})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
err = fout.Close()
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
outpath := filepath.Join(cdir, "nixos")
|
|
os.MkdirAll(outpath, 0755)
|
|
|
|
t.Cleanup(func() {
|
|
os.RemoveAll(filepath.Join(outpath, d.Name)) // makes the disk image a candidate for GC
|
|
})
|
|
|
|
cmd := exec.Command("nixos-generate", "-f", "qcow", "-o", filepath.Join(outpath, d.Name), "-c", fname)
|
|
if *verboseNixOutput {
|
|
cmd.Stdout = logger.FuncWriter(t.Logf)
|
|
cmd.Stderr = logger.FuncWriter(t.Logf)
|
|
} else {
|
|
fname := fmt.Sprintf("nix-build-%s-%s", os.Getenv("GITHUB_RUN_NUMBER"), strings.Replace(t.Name(), "/", "-", -1))
|
|
t.Logf("writing nix logs to %s", fname)
|
|
fout, err := os.Create(fname)
|
|
if err != nil {
|
|
t.Fatalf("can't make log file for nix build: %v", err)
|
|
}
|
|
cmd.Stdout = fout
|
|
cmd.Stderr = fout
|
|
defer fout.Close()
|
|
}
|
|
cmd.Env = append(os.Environ(), "NIX_PATH=nixpkgs="+d.URL)
|
|
cmd.Dir = outpath
|
|
t.Logf("running %s %#v", "nixos-generate", cmd.Args)
|
|
if err := cmd.Run(); err != nil {
|
|
t.Fatalf("error while making NixOS image for %s: %v", d.Name, err)
|
|
}
|
|
|
|
if !*verboseNixOutput {
|
|
t.Log("done")
|
|
}
|
|
|
|
return filepath.Join(outpath, d.Name, "nixos.qcow2")
|
|
}
|