From c2a369c4987fbf79410e125c34b927ddc68d242f Mon Sep 17 00:00:00 2001 From: Julius de Jeu Date: Sun, 14 Nov 2021 22:46:14 +0100 Subject: [PATCH] Add grafana and postgresql I should probably move some stuff over from my other postgres instance --- flake.nix | 35 ++++++++++++++++++ hosts/grafana/configuration.nix | 55 +++++++++++++++++++++++++++++ hosts/grafana/secrets.nix | Bin 0 -> 122 bytes hosts/nginx/configuration.nix | 1 + hosts/postgresql/configuration.nix | 41 +++++++++++++++++++++ 5 files changed, 132 insertions(+) create mode 100644 hosts/grafana/configuration.nix create mode 100644 hosts/grafana/secrets.nix create mode 100644 hosts/postgresql/configuration.nix diff --git a/flake.nix b/flake.nix index 41ffcdd..b0ad559 100644 --- a/flake.nix +++ b/flake.nix @@ -51,6 +51,21 @@ ]; }; + nixosConfigurations.postgresql = nixpkgs.lib.nixosSystem { + system = "x86_64-linux"; + modules = [ + "${nixpkgs}/nixos/modules/virtualisation/lxc-container.nix" + ./hosts/postgresql/configuration.nix + ]; + }; + nixosConfigurations.grafana = nixpkgs.lib.nixosSystem { + system = "x86_64-linux"; + modules = [ + "${nixpkgs}/nixos/modules/virtualisation/lxc-container.nix" + ./hosts/grafana/configuration.nix + ]; + }; + deploy.nodes.nginx = { hostname = "10.42.20.2"; fastConnection = true; @@ -111,6 +126,26 @@ }; }; + deploy.nodes.postgresql = { + hostname = "10.42.20.8"; + fastConnection = true; + profiles.system = { + user = "root"; + path = deploy-rs.lib.x86_64-linux.activate.nixos + self.nixosConfigurations.postgresql; + }; + }; + + deploy.nodes.grafana = { + hostname = "10.42.20.9"; + fastConnection = true; + profiles.system = { + user = "root"; + path = deploy-rs.lib.x86_64-linux.activate.nixos + self.nixosConfigurations.grafana; + }; + }; + checks = builtins.mapAttrs (system: deployLib: deployLib.deployChecks self.deploy) deploy-rs.lib; diff --git a/hosts/grafana/configuration.nix b/hosts/grafana/configuration.nix new file mode 100644 index 0000000..b80de61 --- /dev/null +++ b/hosts/grafana/configuration.nix @@ -0,0 +1,55 @@ +{ config, pkgs, ... }: +let secrets = import ./secrets.nix; +in { + imports = [ + # Import common config + ../../common/generic-lxc.nix + ../../common + ]; + + networking.hostName = "grafana"; + + # This value determines the NixOS release from which the default + # settings for stateful data, like file locations and database versions + # on your system were taken. It‘s perfectly fine and recommended to leave + # this value at the release version of the first install of this system. + # Before changing this value read the documentation for this option + # (e.g. man configuration.nix or on https://nixos.org/nixos/options.html). + system.stateVersion = "21.11"; # Did you read the comment? + + environment.systemPackages = with pkgs; [ ]; + + environment.etc.adminPass = { + enable = true; + text = secrets.passwd; + }; + + environment.etc.signKey = { + enable = true; + text = secrets.secretKey; + }; + + networking.firewall.allowedTCPPorts = [ 3000 ]; + + services.grafana = { + enable = true; + protocol = "http"; + domain = "grafana.voidcorp.nl"; + rootUrl = "https://grafana.voidcorp.nl/"; + addr = "0.0.0.0"; + port = 3000; + database = { + type = "postgres"; + host = "postgresql.voidlocal"; + user = "grafana"; + passwordFile = "/etc/adminPass"; + }; + security = { + adminUser = secrets.adminUser; + adminPasswordFile = "/etc/adminPass"; + secretKeyFile = "/etc/signKey"; + }; + analytics.reporting.enable = false; + }; + +} diff --git a/hosts/grafana/secrets.nix b/hosts/grafana/secrets.nix new file mode 100644 index 0000000000000000000000000000000000000000..36d224176e70cfc9304d9055b6a2db80bdae4003 GIT binary patch literal 122 zcmV-=0EPbmM@dveQdv+`078Lvny}tpLWxsoqlQsK$AVh!NredGtf{0p5rx|p?-Aex zQUj#%fCMenNu!l}g-%M1@T~+<8zY?9;0Eq%VgrZ`B}y|TjM?1xqtaR(vI#Y$z%_z{ czG!uC%B8_5H}A&c-Q_j)F4wY-Q!>VU+}r;-%>V!Z literal 0 HcmV?d00001 diff --git a/hosts/nginx/configuration.nix b/hosts/nginx/configuration.nix index b3e374d..53db57e 100644 --- a/hosts/nginx/configuration.nix +++ b/hosts/nginx/configuration.nix @@ -54,6 +54,7 @@ in { virtualHosts."s3.voidcorp.nl" = proxy "http://10.42.20.6:9000/"; virtualHosts."explore.s3.voidcorp.nl" = proxy "http://10.42.20.6:9001/"; virtualHosts."registry.voidcorp.nl" = proxy "http://10.42.20.7:5000/"; + virtualHosts."grafana.voidcorp.nl" = proxy "http://10.42.20.9:3000/"; }; security.acme.email = "acme@voidcorp.nl"; diff --git a/hosts/postgresql/configuration.nix b/hosts/postgresql/configuration.nix new file mode 100644 index 0000000..d9d0d96 --- /dev/null +++ b/hosts/postgresql/configuration.nix @@ -0,0 +1,41 @@ +{ config, pkgs, ... }: +let +in { + imports = [ + # Import common config + ../../common/generic-lxc.nix + ../../common + ]; + + networking.hostName = "postgresql"; + + # This value determines the NixOS release from which the default + # settings for stateful data, like file locations and database versions + # on your system were taken. It‘s perfectly fine and recommended to leave + # this value at the release version of the first install of this system. + # Before changing this value read the documentation for this option + # (e.g. man configuration.nix or on https://nixos.org/nixos/options.html). + system.stateVersion = "21.11"; # Did you read the comment? + + environment.systemPackages = with pkgs; [ ]; + + networking.firewall.allowedTCPPorts = [ 5432 ]; + + services.postgresql = { + enable = true; + authentication = "host all all 10.42.0.0/16 trust"; + ensureDatabases = [ "prometheus" "grafana" ]; + ensureUsers = [ + { + name = "prometheus"; + ensurePermissions = { "DATABASE \"prometheus\"" = "ALL PRIVILEGES"; }; + } + { + name = "grafana"; + ensurePermissions = { "DATABASE \"grafana\"" = "ALL PRIVILEGES"; }; + } + ]; + enableTCPIP = true; + }; + +}