main
zimbatm 2 years ago
parent f1df228d66
commit 974032c41a
No known key found for this signature in database
GPG Key ID: 71BAF6D40C1D63D7

@ -25,10 +25,10 @@
packages.default = pkgs.callPackage ./default.nix {}; packages.default = pkgs.callPackage ./default.nix {};
devShells.default = pkgs.callPackage ./shell.nix {}; devShells.default = pkgs.callPackage ./shell.nix {};
checks = let checks = let
nixosTests = (pkgs.callPackages ./nix/checks/nixos-test.nix { nixosTests = pkgs.callPackages ./nix/checks/nixos-test.nix {
makeTest = import (pkgs.path + "/nixos/tests/make-test-python.nix"); makeTest = import (pkgs.path + "/nixos/tests/make-test-python.nix");
inherit (self.nixosModules) vaultAgent systemdVaultd; inherit (self.nixosModules) vaultAgent systemdVaultd;
}); };
in { in {
treefmt = pkgs.callPackage ./nix/checks/treefmt.nix {}; treefmt = pkgs.callPackage ./nix/checks/treefmt.nix {};
inherit (nixosTests) unittests vault-agent systemd-vaultd; inherit (nixosTests) unittests vault-agent systemd-vaultd;

@ -1,7 +1,10 @@
{ config, lib, pkgs, ... }:
{ {
environment.systemPackages = [ pkgs.vault ]; config,
lib,
pkgs,
...
}: {
environment.systemPackages = [pkgs.vault];
services.vault = { services.vault = {
enable = true; enable = true;
dev = true; dev = true;
@ -11,7 +14,7 @@
environment.variables.VAULT_TOKEN = config.services.vault.devRootTokenID; environment.variables.VAULT_TOKEN = config.services.vault.devRootTokenID;
systemd.services.setup-vault-agent-approle = { systemd.services.setup-vault-agent-approle = {
path = [ pkgs.jq pkgs.vault pkgs.systemd ]; path = [pkgs.jq pkgs.vault pkgs.systemd];
wantedBy = ["multi-user.target"]; wantedBy = ["multi-user.target"];
serviceConfig = { serviceConfig = {
@ -48,7 +51,7 @@
# Make sure our setup service is started before our vault-agent # Make sure our setup service is started before our vault-agent
systemd.services.vault-agent-test = { systemd.services.vault-agent-test = {
wants = [ "setup-vault-agent-approle.service" ]; wants = ["setup-vault-agent-approle.service"];
after = [ "setup-vault-agent-approle.service" ]; after = ["setup-vault-agent-approle.service"];
}; };
} }

@ -1,12 +1,14 @@
{ config, lib, pkgs, ... }:
let
systemd-vaultd = pkgs.callPackage ../../default.nix {};
in
{ {
config,
lib,
pkgs,
...
}: let
systemd-vaultd = pkgs.callPackage ../../default.nix {};
in {
systemd.sockets.systemd-vaultd = { systemd.sockets.systemd-vaultd = {
description = "systemd-vaultd socket"; description = "systemd-vaultd socket";
wantedBy = [ "sockets.target" ]; wantedBy = ["sockets.target"];
socketConfig = { socketConfig = {
ListenStream = "/run/systemd-vaultd/sock"; ListenStream = "/run/systemd-vaultd/sock";
@ -16,8 +18,8 @@ in
}; };
systemd.services.systemd-vaultd = { systemd.services.systemd-vaultd = {
description = "systemd-vaultd daemon"; description = "systemd-vaultd daemon";
requires = [ "systemd-vaultd.socket" ]; requires = ["systemd-vaultd.socket"];
after = [ "systemd-vaultd.socket" ]; after = ["systemd-vaultd.socket"];
serviceConfig = { serviceConfig = {
ExecStart = "${systemd-vaultd}/bin/systemd-vaultd"; ExecStart = "${systemd-vaultd}/bin/systemd-vaultd";
}; };

@ -1,5 +1,9 @@
{ config, lib, pkgs, ... }: {
let config,
lib,
pkgs,
...
}: let
cfg = config.services.vault; cfg = config.services.vault;
settingsFormat = pkgs.formats.json {}; settingsFormat = pkgs.formats.json {};
@ -23,7 +27,7 @@ let
options = { options = {
method = lib.mkOption { method = lib.mkOption {
type = lib.types.listOf autoAuthMethodModule; type = lib.types.listOf autoAuthMethodModule;
default = [ ]; default = [];
}; };
}; };
}; };
@ -45,17 +49,16 @@ let
options = { options = {
auto_auth = lib.mkOption { auto_auth = lib.mkOption {
type = autoAuthModule; type = autoAuthModule;
default = { }; default = {};
}; };
template_config = lib.mkOption { template_config = lib.mkOption {
type = templateConfigModule; type = templateConfigModule;
default = { }; default = {};
}; };
}; };
}; };
in in {
{
options.services.vault.agents = lib.mkOption { options.services.vault.agents = lib.mkOption {
default = {}; default = {};
description = "Instances of vault agent"; description = "Instances of vault agent";
@ -69,15 +72,17 @@ in
}); });
}; };
config = { config = {
systemd.services = lib.mapAttrs' (name: instanceCfg: lib.nameValuePair "vault-agent-${name}" ({ systemd.services = lib.mapAttrs' (name: instanceCfg:
after = [ "network.target" ]; lib.nameValuePair "vault-agent-${name}" {
wantedBy = [ "multi-user.target" ]; after = ["network.target"];
wantedBy = ["multi-user.target"];
# Needs getent in PATH # Needs getent in PATH
path = [ pkgs.glibc ]; path = [pkgs.glibc];
serviceConfig = { serviceConfig = {
Restart = "on-failure"; Restart = "on-failure";
ExecStart = "${pkgs.vault}/bin/vault agent -config=${settingsFormat.generate "agent.json" instanceCfg.settings}"; ExecStart = "${pkgs.vault}/bin/vault agent -config=${settingsFormat.generate "agent.json" instanceCfg.settings}";
}; };
})) cfg.agents; })
cfg.agents;
}; };
} }

Loading…
Cancel
Save