Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add tests for nixos #27

Merged
merged 2 commits into from
Feb 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
with:
nix_path: nixpkgs=channel:nixos-unstable
github_access_token: ${{ secrets.GITHUB_TOKEN }}
- uses: DeterminateSystems/magic-nix-cache-action@main

Check warning on line 16 in .github/workflows/ci.yml

View workflow job for this annotation

GitHub Actions / Build

Magic Nix Cache is deprecated

Magic Nix Cache has been deprecated due to a change in the underlying GitHub APIs and will stop working on 1 February 2025. To continue caching Nix builds in GitHub Actions, use FlakeHub Cache instead. Replace... - uses: DeterminateSystems/magic-nix-cache-action@main ...with... - uses: DeterminateSystems/flakehub-cache-action@main For more details: https://dtr.mn/magic-nix-cache-eol

Check warning on line 16 in .github/workflows/ci.yml

View workflow job for this annotation

GitHub Actions / Test

Magic Nix Cache is deprecated

Magic Nix Cache has been deprecated due to a change in the underlying GitHub APIs and will stop working on 1 February 2025. To continue caching Nix builds in GitHub Actions, use FlakeHub Cache instead. Replace... - uses: DeterminateSystems/magic-nix-cache-action@main ...with... - uses: DeterminateSystems/flakehub-cache-action@main For more details: https://dtr.mn/magic-nix-cache-eol

Check warning on line 16 in .github/workflows/ci.yml

View workflow job for this annotation

GitHub Actions / Build nix packages

Magic Nix Cache is deprecated

Magic Nix Cache has been deprecated due to a change in the underlying GitHub APIs and will stop working on 1 February 2025. To continue caching Nix builds in GitHub Actions, use FlakeHub Cache instead. Replace... - uses: DeterminateSystems/magic-nix-cache-action@main ...with... - uses: DeterminateSystems/flakehub-cache-action@main For more details: https://dtr.mn/magic-nix-cache-eol

Check warning on line 16 in .github/workflows/ci.yml

View workflow job for this annotation

GitHub Actions / Build

Magic Nix Cache is deprecated

Magic Nix Cache has been deprecated due to a change in the underlying GitHub APIs and will stop working on 1 February 2025. To continue caching Nix builds in GitHub Actions, use FlakeHub Cache instead. Replace... - uses: DeterminateSystems/magic-nix-cache-action@main ...with... - uses: DeterminateSystems/flakehub-cache-action@main For more details: https://dtr.mn/magic-nix-cache-eol

Check warning on line 16 in .github/workflows/ci.yml

View workflow job for this annotation

GitHub Actions / Build x86 image

Magic Nix Cache is deprecated

Magic Nix Cache has been deprecated due to a change in the underlying GitHub APIs and will stop working on 1 February 2025. To continue caching Nix builds in GitHub Actions, use FlakeHub Cache instead. Replace... - uses: DeterminateSystems/magic-nix-cache-action@main ...with... - uses: DeterminateSystems/flakehub-cache-action@main For more details: https://dtr.mn/magic-nix-cache-eol

Check warning on line 16 in .github/workflows/ci.yml

View workflow job for this annotation

GitHub Actions / Test

Magic Nix Cache is deprecated

Magic Nix Cache has been deprecated due to a change in the underlying GitHub APIs and will stop working on 1 February 2025. To continue caching Nix builds in GitHub Actions, use FlakeHub Cache instead. Replace... - uses: DeterminateSystems/magic-nix-cache-action@main ...with... - uses: DeterminateSystems/flakehub-cache-action@main For more details: https://dtr.mn/magic-nix-cache-eol

Check warning on line 16 in .github/workflows/ci.yml

View workflow job for this annotation

GitHub Actions / Build arm image

Magic Nix Cache is deprecated

Magic Nix Cache has been deprecated due to a change in the underlying GitHub APIs and will stop working on 1 February 2025. To continue caching Nix builds in GitHub Actions, use FlakeHub Cache instead. Replace... - uses: DeterminateSystems/magic-nix-cache-action@main ...with... - uses: DeterminateSystems/flakehub-cache-action@main For more details: https://dtr.mn/magic-nix-cache-eol

Check warning on line 16 in .github/workflows/ci.yml

View workflow job for this annotation

GitHub Actions / Tag multi-arch

Magic Nix Cache is deprecated

Magic Nix Cache has been deprecated due to a change in the underlying GitHub APIs and will stop working on 1 February 2025. To continue caching Nix builds in GitHub Actions, use FlakeHub Cache instead. Replace... - uses: DeterminateSystems/magic-nix-cache-action@main ...with... - uses: DeterminateSystems/flakehub-cache-action@main For more details: https://dtr.mn/magic-nix-cache-eol
- name: Build connet
run: nix develop --command make build

Expand All @@ -27,7 +27,7 @@
with:
nix_path: nixpkgs=channel:nixos-unstable
github_access_token: ${{ secrets.GITHUB_TOKEN }}
- uses: DeterminateSystems/magic-nix-cache-action@main

Check warning on line 30 in .github/workflows/ci.yml

View workflow job for this annotation

GitHub Actions / Build

Magic Nix Cache is deprecated

Magic Nix Cache has been deprecated due to a change in the underlying GitHub APIs and will stop working on 1 February 2025. To continue caching Nix builds in GitHub Actions, use FlakeHub Cache instead. Replace... - uses: DeterminateSystems/magic-nix-cache-action@main ...with... - uses: DeterminateSystems/flakehub-cache-action@main For more details: https://dtr.mn/magic-nix-cache-eol

Check warning on line 30 in .github/workflows/ci.yml

View workflow job for this annotation

GitHub Actions / Test

Magic Nix Cache is deprecated

Magic Nix Cache has been deprecated due to a change in the underlying GitHub APIs and will stop working on 1 February 2025. To continue caching Nix builds in GitHub Actions, use FlakeHub Cache instead. Replace... - uses: DeterminateSystems/magic-nix-cache-action@main ...with... - uses: DeterminateSystems/flakehub-cache-action@main For more details: https://dtr.mn/magic-nix-cache-eol

Check warning on line 30 in .github/workflows/ci.yml

View workflow job for this annotation

GitHub Actions / Build nix packages

Magic Nix Cache is deprecated

Magic Nix Cache has been deprecated due to a change in the underlying GitHub APIs and will stop working on 1 February 2025. To continue caching Nix builds in GitHub Actions, use FlakeHub Cache instead. Replace... - uses: DeterminateSystems/magic-nix-cache-action@main ...with... - uses: DeterminateSystems/flakehub-cache-action@main For more details: https://dtr.mn/magic-nix-cache-eol

Check warning on line 30 in .github/workflows/ci.yml

View workflow job for this annotation

GitHub Actions / Build

Magic Nix Cache is deprecated

Magic Nix Cache has been deprecated due to a change in the underlying GitHub APIs and will stop working on 1 February 2025. To continue caching Nix builds in GitHub Actions, use FlakeHub Cache instead. Replace... - uses: DeterminateSystems/magic-nix-cache-action@main ...with... - uses: DeterminateSystems/flakehub-cache-action@main For more details: https://dtr.mn/magic-nix-cache-eol

Check warning on line 30 in .github/workflows/ci.yml

View workflow job for this annotation

GitHub Actions / Build x86 image

Magic Nix Cache is deprecated

Magic Nix Cache has been deprecated due to a change in the underlying GitHub APIs and will stop working on 1 February 2025. To continue caching Nix builds in GitHub Actions, use FlakeHub Cache instead. Replace... - uses: DeterminateSystems/magic-nix-cache-action@main ...with... - uses: DeterminateSystems/flakehub-cache-action@main For more details: https://dtr.mn/magic-nix-cache-eol

Check warning on line 30 in .github/workflows/ci.yml

View workflow job for this annotation

GitHub Actions / Test

Magic Nix Cache is deprecated

Magic Nix Cache has been deprecated due to a change in the underlying GitHub APIs and will stop working on 1 February 2025. To continue caching Nix builds in GitHub Actions, use FlakeHub Cache instead. Replace... - uses: DeterminateSystems/magic-nix-cache-action@main ...with... - uses: DeterminateSystems/flakehub-cache-action@main For more details: https://dtr.mn/magic-nix-cache-eol

Check warning on line 30 in .github/workflows/ci.yml

View workflow job for this annotation

GitHub Actions / Build arm image

Magic Nix Cache is deprecated

Magic Nix Cache has been deprecated due to a change in the underlying GitHub APIs and will stop working on 1 February 2025. To continue caching Nix builds in GitHub Actions, use FlakeHub Cache instead. Replace... - uses: DeterminateSystems/magic-nix-cache-action@main ...with... - uses: DeterminateSystems/flakehub-cache-action@main For more details: https://dtr.mn/magic-nix-cache-eol

Check warning on line 30 in .github/workflows/ci.yml

View workflow job for this annotation

GitHub Actions / Tag multi-arch

Magic Nix Cache is deprecated

Magic Nix Cache has been deprecated due to a change in the underlying GitHub APIs and will stop working on 1 February 2025. To continue caching Nix builds in GitHub Actions, use FlakeHub Cache instead. Replace... - uses: DeterminateSystems/magic-nix-cache-action@main ...with... - uses: DeterminateSystems/flakehub-cache-action@main For more details: https://dtr.mn/magic-nix-cache-eol
- name: Run tests
run: nix develop --command make test
- name: Run lint
Expand All @@ -49,9 +49,11 @@
with:
nix_path: nixpkgs=channel:nixos-unstable
github_access_token: ${{ secrets.GITHUB_TOKEN }}
- uses: DeterminateSystems/magic-nix-cache-action@main

Check warning on line 52 in .github/workflows/ci.yml

View workflow job for this annotation

GitHub Actions / Build

Magic Nix Cache is deprecated

Magic Nix Cache has been deprecated due to a change in the underlying GitHub APIs and will stop working on 1 February 2025. To continue caching Nix builds in GitHub Actions, use FlakeHub Cache instead. Replace... - uses: DeterminateSystems/magic-nix-cache-action@main ...with... - uses: DeterminateSystems/flakehub-cache-action@main For more details: https://dtr.mn/magic-nix-cache-eol

Check warning on line 52 in .github/workflows/ci.yml

View workflow job for this annotation

GitHub Actions / Test

Magic Nix Cache is deprecated

Magic Nix Cache has been deprecated due to a change in the underlying GitHub APIs and will stop working on 1 February 2025. To continue caching Nix builds in GitHub Actions, use FlakeHub Cache instead. Replace... - uses: DeterminateSystems/magic-nix-cache-action@main ...with... - uses: DeterminateSystems/flakehub-cache-action@main For more details: https://dtr.mn/magic-nix-cache-eol

Check warning on line 52 in .github/workflows/ci.yml

View workflow job for this annotation

GitHub Actions / Build nix packages

Magic Nix Cache is deprecated

Magic Nix Cache has been deprecated due to a change in the underlying GitHub APIs and will stop working on 1 February 2025. To continue caching Nix builds in GitHub Actions, use FlakeHub Cache instead. Replace... - uses: DeterminateSystems/magic-nix-cache-action@main ...with... - uses: DeterminateSystems/flakehub-cache-action@main For more details: https://dtr.mn/magic-nix-cache-eol

Check warning on line 52 in .github/workflows/ci.yml

View workflow job for this annotation

GitHub Actions / Build

Magic Nix Cache is deprecated

Magic Nix Cache has been deprecated due to a change in the underlying GitHub APIs and will stop working on 1 February 2025. To continue caching Nix builds in GitHub Actions, use FlakeHub Cache instead. Replace... - uses: DeterminateSystems/magic-nix-cache-action@main ...with... - uses: DeterminateSystems/flakehub-cache-action@main For more details: https://dtr.mn/magic-nix-cache-eol

Check warning on line 52 in .github/workflows/ci.yml

View workflow job for this annotation

GitHub Actions / Build x86 image

Magic Nix Cache is deprecated

Magic Nix Cache has been deprecated due to a change in the underlying GitHub APIs and will stop working on 1 February 2025. To continue caching Nix builds in GitHub Actions, use FlakeHub Cache instead. Replace... - uses: DeterminateSystems/magic-nix-cache-action@main ...with... - uses: DeterminateSystems/flakehub-cache-action@main For more details: https://dtr.mn/magic-nix-cache-eol

Check warning on line 52 in .github/workflows/ci.yml

View workflow job for this annotation

GitHub Actions / Test

Magic Nix Cache is deprecated

Magic Nix Cache has been deprecated due to a change in the underlying GitHub APIs and will stop working on 1 February 2025. To continue caching Nix builds in GitHub Actions, use FlakeHub Cache instead. Replace... - uses: DeterminateSystems/magic-nix-cache-action@main ...with... - uses: DeterminateSystems/flakehub-cache-action@main For more details: https://dtr.mn/magic-nix-cache-eol

Check warning on line 52 in .github/workflows/ci.yml

View workflow job for this annotation

GitHub Actions / Build arm image

Magic Nix Cache is deprecated

Magic Nix Cache has been deprecated due to a change in the underlying GitHub APIs and will stop working on 1 February 2025. To continue caching Nix builds in GitHub Actions, use FlakeHub Cache instead. Replace... - uses: DeterminateSystems/magic-nix-cache-action@main ...with... - uses: DeterminateSystems/flakehub-cache-action@main For more details: https://dtr.mn/magic-nix-cache-eol

Check warning on line 52 in .github/workflows/ci.yml

View workflow job for this annotation

GitHub Actions / Tag multi-arch

Magic Nix Cache is deprecated

Magic Nix Cache has been deprecated due to a change in the underlying GitHub APIs and will stop working on 1 February 2025. To continue caching Nix builds in GitHub Actions, use FlakeHub Cache instead. Replace... - uses: DeterminateSystems/magic-nix-cache-action@main ...with... - uses: DeterminateSystems/flakehub-cache-action@main For more details: https://dtr.mn/magic-nix-cache-eol
- uses: DeterminateSystems/flake-checker-action@main
- name: Build default
run: nix build .
- name: Build docker
run: nix build .#docker
- name: Flake check
run: nix flake check
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ lint:
test-always:
go test -v -cover -timeout 10s -count 1 ./...

test-nix:
nix build .#checks.x86_64-linux.moduleTest

test-nix-interactive:
nix run .#checks.x86_64-linux.moduleTest.driverInteractive

.PHONY: gen
gen:
fd --extension ".pb.go" . --exec-batch rm {}
Expand Down
81 changes: 80 additions & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
flake-utils.url = "github:numtide/flake-utils";
};

outputs = { nixpkgs, flake-utils, ... }:
outputs = { self, nixpkgs, flake-utils, ... }:
{
nixosModules.default = ./nix/client-module.nix;
nixosModules.server = ./nix/server-module.nix;
Expand All @@ -17,6 +17,10 @@
pkgs = import nixpkgs {
inherit system;
};
testCerts = pkgs.runCommand "test-certs" { } ''
mkdir $out && cd $out
${pkgs.minica}/bin/minica -ip-addresses 192.168.1.3
'';
in
{
formatter = pkgs.nixpkgs-fmt;
Expand Down Expand Up @@ -49,5 +53,80 @@
'')
];
};
checks = {
moduleTest = pkgs.testers.runNixOSTest {
name = "moduleTest";
nodes.server = {
imports = [ self.nixosModules.server ];
environment.etc."server.cert" = {
source = "${testCerts}/192.168.1.3/cert.pem";
};
environment.etc."server.key" = {
source = "${testCerts}/192.168.1.3/key.pem";
};
environment.etc."tokens" = {
text = "abcba";
};
services.connet-server = {
enable = true;
openFirewall = true;
settings.server = {
cert-file = "/etc/server.cert";
key-file = "/etc/server.key";
tokens-file = "/etc/tokens";
};
};
};
nodes.clientDst = {
imports = [ self.nixosModules.default ];
environment.etc."server.cert" = {
source = "${testCerts}/192.168.1.3/cert.pem";
};
environment.etc."tokens" = {
text = "abcba";
};
services.connet-client = {
enable = true;
openFirewall = true;
settings.client = {
token-file = "/etc/tokens";
server-addr = "192.168.1.3:19190";
server-cas = "/etc/server.cert";
destinations.abc = {
addr = ":3000";
};
};
};
};
nodes.clientSrc = {
imports = [ self.nixosModules.default ];
environment.etc."server.cert" = {
source = "${testCerts}/192.168.1.3/cert.pem";
};
environment.etc."tokens" = {
text = "abcba";
};
services.connet-client = {
enable = true;
openFirewall = true;
settings.client = {
token-file = "/etc/tokens";
server-addr = "192.168.1.3:19190";
server-cas = "/etc/server.cert";
sources.abc = {
addr = ":3000";
};
};
};
};

testScript = ''
start_all()
server.wait_for_unit("connet-server.service")
clientDst.wait_for_unit("connet-client.service")
clientSrc.wait_for_unit("connet-client.service")
'';
};
};
});
}
8 changes: 7 additions & 1 deletion server.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,12 @@ func NewServer(opts ...ServerOption) (*Server, error) {
return nil, err
}

controlHost := "localhost"
if len(cfg.cert.Leaf.IPAddresses) > 0 {
controlHost = cfg.cert.Leaf.IPAddresses[0].String()
} else if len(cfg.cert.Leaf.DNSNames) > 0 {
controlHost = cfg.cert.Leaf.DNSNames[0]
}
controlCAs := x509.NewCertPool()
controlCAs.AddCert(cfg.cert.Leaf)
relay, err := relay.NewServer(relay.Config{
Expand All @@ -92,7 +98,7 @@ func NewServer(opts ...ServerOption) (*Server, error) {
Stores: relay.NewFileStores(filepath.Join(cfg.dir, "relay")),

ControlAddr: relaysAddr,
ControlHost: "localhost",
ControlHost: controlHost,
ControlToken: relayAuth.Token,
ControlCAs: controlCAs,
})
Expand Down
Loading