Skip to content

Commit

Permalink
Grafana POC
Browse files Browse the repository at this point in the history
  • Loading branch information
Toomoch committed Aug 15, 2024
1 parent be4998e commit 30eeb9e
Show file tree
Hide file tree
Showing 10 changed files with 99 additions and 74 deletions.
8 changes: 4 additions & 4 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 1 addition & 11 deletions home/dotfiles/tmux.conf
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,12 @@ bind % split-window -h -c "#{pane_current_path}"
## -- tmux-sensible

# Address vim mode switching delay (http://superuser.com/a/252717/65504)
set -sg escape-time 5
set -sg escape-time 10
set-option -g repeat-time 0

# Increase scrollback buffer size from 2000 to 50000 lines
set -g history-limit 50000

# Increase tmux messages display duration from 750ms to 4s
set -g display-time 4000

# Refresh 'status-left' and 'status-right' more often, from every 15s to 5s
set -g status-interval 5

# Upgrade $TERM
# set -g default-terminal "screen-256color"

# Emacs key bindings in tmux command prompt (prefix + :) are better than
# vi keys, even for vim users
set -g status-keys emacs
Expand All @@ -46,7 +37,6 @@ set -g focus-events on
# Super useful when using "grouped sessions" and multi-monitor setup
setw -g aggressive-resize on

### -- nuevo

set-window-option -g mode-keys vi
bind -T copy-mode-vi v send-keys -X begin-selection
Expand Down
3 changes: 2 additions & 1 deletion system/machine/h81/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@
homelab.enable = true;
homelab.homepage-dashboard.enable = true;
homelab.homeassistant.enable = true;
homelab.immich.enable = true;
homelab.immich.enable = false;
homelab.smb.enable = true;
homelab.nextcloud.enable = true;
homelab.grafana.enable = true;
vm.podman.enable = true;
vm.docker.enable = true;
vm.libvirtd.enable = true;
Expand Down
1 change: 1 addition & 0 deletions system/modules/homelab/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
./immich.nix
./smb.nix
./nextcloud.nix
./grafana.nix
];
}
36 changes: 36 additions & 0 deletions system/modules/homelab/grafana.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{ inputs, pkgs, config, lib, ... }:
let
vars = import ./variables.nix { inherit config inputs pkgs lib; };
in
{
options.homelab = {
grafana.enable = lib.mkEnableOption "Whether to enable Grafana";
};

config = lib.mkIf vars.cfg.grafana.enable {
services.grafana = {
enable = true;
settings.server.domain = "grafana.${vars.domain}";
};
services.prometheus = {
enable = true;
globalConfig.scrape_interval = "10s"; # "1m"
scrapeConfigs = [
{
job_name = "node";
static_configs = [{
targets = [ "localhost:${toString config.services.prometheus.exporters.node.port}" ];
}];
}
];
};
services.prometheus.exporters.node = {
enable = true;
port = 9000;
# https://github.com/NixOS/nixpkgs/blob/nixos-24.05/nixos/modules/services/monitoring/prometheus/exporters.nix
enabledCollectors = [ "systemd" ];
# /nix/store/zgsw0yx18v10xa58psanfabmg95nl2bb-node_exporter-1.8.1/bin/node_exporter --help
extraFlags = [ "--collector.ethtool" "--collector.softirqs" "--collector.tcpstat" ];
};
};
}
7 changes: 7 additions & 0 deletions system/modules/homelab/homeassistant-configuration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,10 @@ http:
trusted_proxies:
- ::1
- 127.0.0.1

logger:
default: debug
logs:
custom_components.huawei_solar: debug
huawei_solar: debug
pymodbus: debug # only include this if you're having connectivity issues
15 changes: 7 additions & 8 deletions system/modules/homelab/homeassistant.nix
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
{ inputs, pkgs, lib, config, ... }:
with import ./variables.nix { inherit config inputs pkgs lib; };
with lib;
let
hass_config = "${serviceData}/hass";
hass_config = "${vars.serviceData}/hass";
vars = import ./variables.nix { inherit config inputs pkgs lib; };
in
{

options.homelab = {
homeassistant.enable = mkEnableOption ("Whether to enable homelab stuff");
homeassistant.enable = lib.mkEnableOption "Whether to enable homelab stuff";
};

config = mkMerge [
(mkIf cfg.homeassistant.enable {
config = lib.mkMerge [
(lib.mkIf vars.cfg.homeassistant.enable {
virtualisation.oci-containers.containers.homeassistant = {
image = "ghcr.io/home-assistant/home-assistant:stable";
ports = [
Expand All @@ -22,9 +21,9 @@ in
"${./homeassistant-configuration.yaml}:/config/configuration.yaml:ro"
];
environment = {
TZ = timezone;
TZ = vars.timezone;
};
extraOptions = commonextraOptions ++ [
extraOptions = vars.commonextraOptions ++ [
"--network=host"
"--device=/dev/serial/by-id/usb-1a86_USB_Serial-if00-port0:/dev/ttyUSB0:rw"
];
Expand Down
52 changes: 14 additions & 38 deletions system/modules/homelab/homelab.nix
Original file line number Diff line number Diff line change
@@ -1,32 +1,31 @@
{ inputs, config, lib, pkgs, pkgs-unstable, ... }:
with import ./variables.nix { inherit config inputs pkgs lib; };
with lib;
let
jmusicbot = "${serviceData}/jmusicbot";
dashy_config = "${inputs.private}/configfiles/dashy.yml";
tgtg_volume = "${serviceData}/tgtg";
vars = import ./variables.nix { inherit config inputs pkgs lib; };
jmusicbot = "${vars.serviceData}/jmusicbot";
tgtg_volume = "${vars.serviceData}/tgtg";

cockpit-machines = pkgs.callPackage ../packages/cockpit-machines.nix { };
in
{
options.homelab = {
enable = mkEnableOption ("Whether to enable homelab stuff");
enablevps = mkEnableOption ("Whether to enable VPS homelab stuff");
enable = lib.mkEnableOption "Whether to enable homelab stuff";
enablevps = lib.mkEnableOption "Whether to enable VPS homelab stuff";
};

config = mkMerge [
(mkIf cfg.enable {
config = lib.mkMerge [
(lib.mkIf vars.cfg.enable {
virtualisation.oci-containers.backend = "docker";
services.cockpit = {
enable = true;
enable = false;
openFirewall = true;
settings = {
WebService = {
Origins = "https://cockpit.${domain} wss://cockpit.${domain}";
Origins = "https://cockpit.${vars.domain} wss://cockpit.${vars.domain}";
ProtocolHeader = "X-Forwarded-Proto";
};
};
};
environment.systemPackages = with pkgs; [
environment.systemPackages = [
];
systemd.tmpfiles.rules = [
"d ${jmusicbot} 0755 root root"
Expand All @@ -53,7 +52,7 @@ in
services.caddy = {
enable = true;
package = pkgs.callPackage ../../packages/caddy-plugins.nix { };
extraConfig = builtins.readFile ("${inputs.private}/configfiles/Caddyfile");
extraConfig = builtins.readFile "${inputs.private}/configfiles/Caddyfile";
};

sops.secrets."duckdns/token".sopsFile = "${inputs.private}/secrets/sops/duckdns.env";
Expand All @@ -62,27 +61,8 @@ in
systemd.services.caddy.serviceConfig = {
EnvironmentFile = "${config.sops.secrets."duckdns/token".path}";
};

#Dashy
virtualisation.oci-containers.backend = "docker";
virtualisation.oci-containers.containers = {
#dashy = {
# image = "docker.io/lissy93/dashy:latest";
# ports = [
# "8080:80"
# ];
# volumes = [
# "${dashy_config}:/app/public/conf.yml:ro"
# ];
# extraOptions = commonextraOptions;

#};

};


})
(mkIf cfg.enablevps {
(lib.mkIf vars.cfg.enablevps {
sops.secrets."tgtg/env" = {
sopsFile = "${inputs.private}/secrets/sops/tgtg.env";
format = "dotenv";
Expand All @@ -99,16 +79,12 @@ in
TELEGRAM = "true";
};
environmentFiles = [ "${config.sops.secrets."tgtg/env".path}" ];
extraOptions = commonextraOptions;
extraOptions = vars.commonextraOptions;
volumes = [
"${tgtg_volume}:/tokens"
];
};
};


})


];
}
23 changes: 19 additions & 4 deletions system/modules/homelab/nextcloud.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{ inputs, pkgs, lib, config, ... }:
let
vars = import ./variables.nix { inherit config inputs pkgs lib; };
dataBase = "${vars.serviceData}/postgresql/${config.services.postgresql.package.psqlSchema}";
in
{

Expand All @@ -9,13 +10,17 @@ in
};

config = lib.mkIf vars.cfg.nextcloud.enable {
systemd.tmpfiles.rules = [
"d ${dataBase} 0750 postgres postgres - -"
];
services.postgresql.dataDir = "${dataBase}";
sops.secrets."nextcloud" = {
sopsFile = "${inputs.private}/secrets/sops/nextcloud";
format = "binary";
owner = "nextcloud";
group = "nextcloud";
};
environment.systemPackages = [ pkgs.ffmpeg-headless ];
environment.systemPackages = [ pkgs.ffmpeg-headless ];

services.nextcloud = {
enable = true;
Expand All @@ -41,9 +46,10 @@ in
# Allow access when hitting either of these hosts or IPs
trusted_proxies = [ "127.0.0.1" ];
maintenance_window_start = 4; # Run jobs at 4am UTC
"memories.exiftool" = "${pkgs.exiftool}/bin/exiftool";
"memories.vod.ffmpeg" = "${lib.getExe pkgs.ffmpeg-headless}";
"memories.vod.ffprobe" = "${pkgs.ffmpeg-headless}/bin/ffprobe";
memories.exiftool = "${lib.getExe pkgs.exiftool}";
memories.vod.ffmpeg = "${lib.getExe pkgs.ffmpeg-headless}";
memories.vod.ffprobe = "${pkgs.ffmpeg-headless}/bin/ffprobe";
preview_ffmpeg_path = "${pkgs.ffmpeg-headless}/bin/ffmpeg";
};
config = {
adminpassFile = "${config.sops.secrets."nextcloud".path}";
Expand All @@ -54,11 +60,20 @@ in
"output_buffering" = "0";
};
};
systemd.services.nextcloud-cron = {
path = [ pkgs.perl ];
};

services.nginx = {
enable = lib.mkForce false;
};

systemd.services.phpfpm-nextcloud.serviceConfig = {
DeviceAllow = [ "/dev/dri/renderD128" ];
SupplementaryGroups = [ "render" "video" ];
PrivateDevices = lib.mkForce false;
};

services.phpfpm.pools.nextcloud.settings = {
"listen.owner" = config.services.caddy.user;
"listen.group" = config.services.caddy.group;
Expand Down
16 changes: 8 additions & 8 deletions system/modules/virtualisation.nix
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
{ config, pkgs, lib, ... }:
with lib; let
let
cfg = config.vm;
in
{
options.vm = {
podman.enable = mkEnableOption ("Wheter to enable podman");
docker.enable = mkEnableOption ("Wheter to enable Docker");
libvirtd.enable = mkEnableOption ("Whether to enable libvirtd");
podman.enable = lib.mkEnableOption "Wheter to enable podman";
docker.enable = lib.mkEnableOption "Wheter to enable Docker";
libvirtd.enable = lib.mkEnableOption "Whether to enable libvirtd";
};

config = mkMerge [
(mkIf cfg.podman.enable {
config = lib.mkMerge [
(lib.mkIf cfg.podman.enable {
environment.systemPackages = with pkgs; [
podman-compose
distrobox
Expand All @@ -25,15 +25,15 @@ in
};
};
})
(mkIf cfg.docker.enable {
(lib.mkIf cfg.docker.enable {
environment.systemPackages = with pkgs; [
docker-compose
];
virtualisation = {
docker.enable = true;
};
})
(mkIf cfg.libvirtd.enable {
(lib.mkIf cfg.libvirtd.enable {
environment.systemPackages = with pkgs; [
win-virtio
];
Expand Down

0 comments on commit 30eeb9e

Please sign in to comment.