|
20 | 20 | forAllSystems = nixpkgs.lib.genAttrs supportedSystems;
|
21 | 21 |
|
22 | 22 | # 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 | + ]; |
24 | 29 |
|
25 | 30 | goVersion = "1.22.3";
|
26 | 31 | goOverlay = final: prev: {
|
|
32 | 37 | };
|
33 | 38 | });
|
34 | 39 | };
|
| 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 | + }; |
35 | 63 | in
|
36 | 64 | {
|
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 | + }: |
40 | 73 | let
|
41 |
| - pkgs = (nixpkgsFor.${system}.extend goOverlay); |
| 74 | + inherit (lib) types mkOption; |
| 75 | + cfg = config.services.naisdevice; |
42 | 76 | in
|
43 | 77 | {
|
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 | + }; |
60 | 88 |
|
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 | + }; |
62 | 101 | };
|
63 |
| - } |
64 |
| - ); |
| 102 | + }; |
65 | 103 |
|
66 |
| - # Add dependencies that are only needed for development |
67 | 104 | devShells = forAllSystems (
|
68 | 105 | system:
|
69 | 106 | let
|
70 |
| - pkgs = (nixpkgsFor.${system}.extend goOverlay); |
| 107 | + pkgs = nixpkgsFor.${system}; |
71 | 108 | in
|
72 | 109 | {
|
73 | 110 | default = pkgs.mkShell {
|
|
84 | 121 | }
|
85 | 122 | );
|
86 | 123 |
|
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); |
91 | 124 | formatter.x86_64-linux = nixpkgs.legacyPackages.x86_64-linux.nixfmt-rfc-style;
|
92 | 125 | };
|
93 | 126 | }
|
0 commit comments