Skip to content

Commit bd48ae3

Browse files
committed
basic nixos module in flake, rename binaries
1 parent 430636f commit bd48ae3

File tree

10 files changed

+111
-44
lines changed

10 files changed

+111
-44
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,4 @@ packaging/windows/naisdevice.key
2424
*.db
2525
operational/scripts/data/
2626
.direnv
27+
result

.nix/module.nix

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
naisdevice:
2+
{
3+
config,
4+
lib,
5+
pkgs,
6+
...
7+
}:
8+
let
9+
inherit (lib) types mkOption;
10+
cfg = config.services.naisdevice;
11+
pkg = cfg.package;
12+
in
13+
{
14+
options.services.naisdevice = {
15+
enable = lib.mkEnableOption "naisdevice-helper service";
16+
package = mkOption {
17+
type = types.package;
18+
default = pkgs.naisdevice;
19+
description = lib.mdDoc ''
20+
The naisdevice package to use.
21+
'';
22+
};
23+
};
24+
25+
config = lib.mkIf cfg.enable {
26+
systemd.services.naisdevice-helper = {
27+
description = "naisdevice-helper service";
28+
wantedBy = [ "multi-user.target" ];
29+
serviceConfig.ExecStart = "${pkg}/bin/helper";
30+
serviceConfig.Restart = "Always";
31+
};
32+
};
33+
}

Makefile

+14-14
Original file line numberDiff line numberDiff line change
@@ -37,28 +37,28 @@ controlplane:
3737
# Run by GitHub actions on linux
3838
linux-client:
3939
mkdir -p ./bin/linux-client
40-
GOOS=linux GOARCH=amd64 go build -o bin/linux-client/naisdevice-systray --tags "$(GOTAGS)" -ldflags "-s $(LDFLAGS)" ./cmd/systray
41-
GOOS=linux GOARCH=amd64 go build -o bin/linux-client/naisdevice-agent --tags "$(GOTAGS)" -ldflags "-s $(LDFLAGS)" ./cmd/device-agent
42-
GOOS=linux GOARCH=amd64 go build -o bin/linux-client/naisdevice-helper --tags "$(GOTAGS)" -ldflags "-s $(LDFLAGS)" ./cmd/helper
40+
GOOS=linux GOARCH=amd64 go build -o bin/linux-client/naisdevice-systray --tags "$(GOTAGS)" -ldflags "-s $(LDFLAGS)" ./cmd/naisdevice-systray
41+
GOOS=linux GOARCH=amd64 go build -o bin/linux-client/naisdevice-agent --tags "$(GOTAGS)" -ldflags "-s $(LDFLAGS)" ./cmd/naisdevice-agent
42+
GOOS=linux GOARCH=amd64 go build -o bin/linux-client/naisdevice-helper --tags "$(GOTAGS)" -ldflags "-s $(LDFLAGS)" ./cmd/naisdevice-helper
4343

4444
# Run by GitHub actions on macos
4545
macos-client:
4646
mkdir -p ./bin/macos-client
47-
GOOS=darwin GOARCH=amd64 go build -o bin/macos-client/naisdevice-agent --tags "$(GOTAGS)" -ldflags "-s $(LDFLAGS)" ./cmd/device-agent
48-
GOOS=darwin GOARCH=amd64 go build -o bin/macos-client/naisdevice-systray --tags "$(GOTAGS)" -ldflags "-s $(LDFLAGS)" ./cmd/systray
49-
GOOS=darwin GOARCH=amd64 go build -o bin/macos-client/naisdevice-helper --tags "$(GOTAGS)" -ldflags "-s $(LDFLAGS)" ./cmd/helper
47+
GOOS=darwin GOARCH=amd64 go build -o bin/macos-client/naisdevice-agent --tags "$(GOTAGS)" -ldflags "-s $(LDFLAGS)" ./cmd/naisdevice-agent
48+
GOOS=darwin GOARCH=amd64 go build -o bin/macos-client/naisdevice-systray --tags "$(GOTAGS)" -ldflags "-s $(LDFLAGS)" ./cmd/naisdevice-systray
49+
GOOS=darwin GOARCH=amd64 go build -o bin/macos-client/naisdevice-helper --tags "$(GOTAGS)" -ldflags "-s $(LDFLAGS)" ./cmd/naisdevice-helper
5050

5151
# Run by GitHub actions on linux
5252
windows-client:
5353
mkdir -p ./bin/windows-client
5454

55-
go run github.com/akavel/rsrc -arch amd64 -manifest ./packaging/windows/admin_manifest.xml -ico assets/nais-logo-blue.ico -o ./cmd/helper/main_windows.syso
56-
go run github.com/akavel/rsrc -ico assets/nais-logo-blue.ico -o ./cmd/device-agent/main_windows.syso
57-
GOOS=windows GOARCH=amd64 go build -o bin/windows-client/naisdevice-systray.exe --tags "$(GOTAGS)" -ldflags "-s $(LDFLAGS) -H=windowsgui" ./cmd/systray
55+
go run github.com/akavel/rsrc -arch amd64 -manifest ./packaging/windows/admin_manifest.xml -ico assets/nais-logo-blue.ico -o ./cmd/naisdevice-helper/main_windows.syso
56+
go run github.com/akavel/rsrc -ico assets/nais-logo-blue.ico -o ./cmd/naisdevice-agent/main_windows.syso
57+
GOOS=windows GOARCH=amd64 go build -o bin/windows-client/naisdevice-systray.exe --tags "$(GOTAGS)" -ldflags "-s $(LDFLAGS) -H=windowsgui" ./cmd/naisdevice-systray
5858
./packaging/windows/sign-exe bin/windows-client/naisdevice-systray.exe ./packaging/windows/naisdevice.crt ./packaging/windows/naisdevice.key
59-
GOOS=windows GOARCH=amd64 go build -o bin/windows-client/naisdevice-agent.exe --tags "$(GOTAGS)" -ldflags "-s $(LDFLAGS) -H=windowsgui" ./cmd/device-agent
59+
GOOS=windows GOARCH=amd64 go build -o bin/windows-client/naisdevice-agent.exe --tags "$(GOTAGS)" -ldflags "-s $(LDFLAGS) -H=windowsgui" ./cmd/naisdevice-agent
6060
./packaging/windows/sign-exe bin/windows-client/naisdevice-agent.exe ./packaging/windows/naisdevice.crt ./packaging/windows/naisdevice.key
61-
GOOS=windows GOARCH=amd64 go build -o bin/windows-client/naisdevice-helper.exe --tags "$(GOTAGS)" -ldflags "-s $(LDFLAGS)" ./cmd/helper
61+
GOOS=windows GOARCH=amd64 go build -o bin/windows-client/naisdevice-helper.exe --tags "$(GOTAGS)" -ldflags "-s $(LDFLAGS)" ./cmd/naisdevice-helper
6262
./packaging/windows/sign-exe bin/windows-client/naisdevice-helper.exe ./packaging/windows/naisdevice.crt ./packaging/windows/naisdevice.key
6363

6464
local:
@@ -67,9 +67,9 @@ local:
6767
go build -o bin/local/gateway-agent --tags "$(GOTAGS)" -ldflags "-s $(LDFLAGS)" ./cmd/gateway-agent
6868
go build -o bin/local/prometheus-agent --tags "$(GOTAGS)" -ldflags "-s $(LDFLAGS)" ./cmd/prometheus-agent
6969
go build -o bin/local/controlplane-cli --tags "$(GOTAGS)" -ldflags "-s $(LDFLAGS)" ./cmd/controlplane-cli
70-
go build -o bin/local/naisdevice-agent --tags "$(GOTAGS)" -ldflags "-s $(LDFLAGS)" ./cmd/device-agent
71-
go build -o bin/local/naisdevice-systray --tags "$(GOTAGS)" -ldflags "-s $(LDFLAGS)" ./cmd/systray
72-
go build -o bin/local/naisdevice-helper --tags "$(GOTAGS)" -ldflags "-s $(LDFLAGS)" ./cmd/helper
70+
go build -o bin/local/naisdevice-agent --tags "$(GOTAGS)" -ldflags "-s $(LDFLAGS)" ./cmd/naisdevice-agent
71+
go build -o bin/local/naisdevice-systray --tags "$(GOTAGS)" -ldflags "-s $(LDFLAGS)" ./cmd/naisdevice-systray
72+
go build -o bin/local/naisdevice-helper --tags "$(GOTAGS)" -ldflags "-s $(LDFLAGS)" ./cmd/naisdevice-helper
7373

7474
linux-icon: packaging/linux/icons/*/apps/naisdevice.png
7575
packaging/linux/icons/*/apps/naisdevice.png: assets/svg/blue.svg
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

flake.nix

+63-30
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,12 @@
2020
forAllSystems = nixpkgs.lib.genAttrs supportedSystems;
2121

2222
# Nixpkgs instantiated for supported system types.
23-
nixpkgsFor = forAllSystems (system: import nixpkgs { inherit system; });
23+
nixpkgsFor = forAllSystems (system: import nixpkgs { inherit system overlays; });
24+
25+
overlays = [
26+
goOverlay
27+
naisdeviceOverlay
28+
];
2429

2530
goVersion = "1.22.3";
2631
goOverlay = final: prev: {
@@ -32,42 +37,74 @@
3237
};
3338
});
3439
};
40+
41+
buildNaisdevice =
42+
pkgs: vendorHash:
43+
pkgs.buildGoModule {
44+
pname = "naisdevice";
45+
subPackages = [
46+
"cmd/naisdevice-helper"
47+
"cmd/naisdevice-systray"
48+
"cmd/naisdevice-agent"
49+
];
50+
inherit version;
51+
src = ./.;
52+
vendorHash = vendorHash;
53+
54+
meta = with pkgs.lib; {
55+
description = "naisdevice - next gen vpn";
56+
homepage = "https://github.com/nais/device";
57+
license = licenses.mit;
58+
};
59+
};
60+
naisdeviceOverlay = final: prev: {
61+
naisdevice = buildNaisdevice prev.pkgs "sha256-+Wgx4/usjAivatYC4jcwjpssGS8U22nimcvVmLfsvfA=";
62+
};
3563
in
3664
{
37-
# Provide some binary packages for selected system types.
38-
packages = forAllSystems (
39-
system:
65+
package = nixpkgsFor.x86_64-linux.naisdevice;
66+
nixosModules.naisdevice =
67+
{
68+
config,
69+
lib,
70+
pkgs,
71+
...
72+
}:
4073
let
41-
pkgs = (nixpkgsFor.${system}.extend goOverlay);
74+
inherit (lib) types mkOption;
75+
cfg = config.services.naisdevice;
4276
in
4377
{
44-
device-agent = pkgs.buildGoModule {
45-
pname = "device-agent";
46-
inherit version;
47-
# In 'nix develop', we don't need a copy of the source tree
48-
# in the Nix store.
49-
src = ./.;
50-
51-
# This hash locks the dependencies of this package. It is
52-
# necessary because of how Go requires network access to resolve
53-
# VCS. See https://www.tweag.io/blog/2021-03-04-gomod2nix/ for
54-
# details. Normally one can build with a fake hash and rely on native Go
55-
# mechanisms to tell you what the hash should be or determine what
56-
# it should be "out-of-band" with other tooling (eg. gomod2nix).
57-
# To begin with it is recommended to set this, but one must
58-
# remember to bump this hash when your dependencies change.
59-
# vendorHash = pkgs.lib.fakeHash;
78+
options.services.naisdevice = {
79+
enable = lib.mkEnableOption "naisdevice-helper service";
80+
package = mkOption {
81+
type = types.package;
82+
default = nixpkgsFor.x86_64-linux.naisdevice;
83+
description = lib.mdDoc ''
84+
The naisdevice package to use.
85+
'';
86+
};
87+
};
6088

61-
vendorHash = "sha256-AgRQO3h7Atq4lnieTBohzrwrw0lRcbQi2cvpeol3owM=";
89+
config = lib.mkIf cfg.enable {
90+
environment.systemPackages = [ pkgs.wireguard-tools ];
91+
systemd.services.naisdevice-helper = {
92+
description = "naisdevice-helper service";
93+
wantedBy = [ "multi-user.target" ];
94+
path = [
95+
pkgs.wireguard-tools
96+
pkgs.iproute2
97+
];
98+
serviceConfig.ExecStart = "${cfg.package}/bin/naisdevice-helper";
99+
serviceConfig.Restart = "always";
100+
};
62101
};
63-
}
64-
);
102+
};
65103

66-
# Add dependencies that are only needed for development
67104
devShells = forAllSystems (
68105
system:
69106
let
70-
pkgs = (nixpkgsFor.${system}.extend goOverlay);
107+
pkgs = nixpkgsFor.${system};
71108
in
72109
{
73110
default = pkgs.mkShell {
@@ -84,10 +121,6 @@
84121
}
85122
);
86123

87-
# The default package for 'nix build'. This makes sense if the
88-
# flake provides only one package or there is a clear "main"
89-
# package.
90-
defaultPackage = forAllSystems (system: self.packages.${system}.device-agent);
91124
formatter.x86_64-linux = nixpkgs.legacyPackages.x86_64-linux.nixfmt-rfc-style;
92125
};
93126
}

0 commit comments

Comments
 (0)