From 5c17645462604f9a548a7c6733afa91fcae8c1a9 Mon Sep 17 00:00:00 2001 From: zowoq <59103226+zowoq@users.noreply.github.com> Date: Fri, 27 Sep 2024 17:51:27 +1000 Subject: [PATCH 1/2] add shared nix config --- darwin/common/nix.nix | 25 ++++--------------------- nixos/common/nix.nix | 25 ++++--------------------- shared/common/nix.nix | 23 +++++++++++++++++++++++ 3 files changed, 31 insertions(+), 42 deletions(-) create mode 100644 shared/common/nix.nix diff --git a/darwin/common/nix.nix b/darwin/common/nix.nix index 0bb14a66..c2403fdf 100644 --- a/darwin/common/nix.nix +++ b/darwin/common/nix.nix @@ -1,20 +1,10 @@ { lib, config, ... }: { - services.nix-daemon.enable = true; - - # Fallback quickly if substituters are not available. - nix.settings.connect-timeout = 5; - - # Enable flakes - nix.settings.experimental-features = - [ - "nix-command" - "flakes" - ] - ++ lib.optional (lib.versionOlder (lib.versions.majorMinor config.nix.package.version) "2.22") "repl-flake"; + imports = [ + ../../shared/common/nix.nix + ]; - # The default at 10 is rarely enough. - nix.settings.log-lines = lib.mkDefault 25; + services.nix-daemon.enable = true; # do not use nix.settings.auto-optimise-store, because of https://github.com/NixOS/nix/issues/7273 nix.optimise.interval = lib.mkDefault [ @@ -24,12 +14,5 @@ } ]; - # Avoid disk full issues - nix.settings.max-free = lib.mkDefault (3000 * 1024 * 1024); - nix.settings.min-free = lib.mkDefault (512 * 1024 * 1024); - - # Avoid copying unnecessary stuff over SSH - nix.settings.builders-use-substitutes = true; - nix.daemonIOLowPriority = lib.mkDefault true; } diff --git a/nixos/common/nix.nix b/nixos/common/nix.nix index 64ff7e56..f003eb88 100644 --- a/nixos/common/nix.nix +++ b/nixos/common/nix.nix @@ -1,30 +1,16 @@ { lib, config, ... }: { + imports = [ + ../../shared/common/nix.nix + ]; + # Disable nix channels. Use flakes instead. nix.channel.enable = lib.mkDefault false; - # Fallback quickly if substituters are not available. - nix.settings.connect-timeout = lib.mkDefault 5; - - # Enable flakes - nix.settings.experimental-features = - [ - "nix-command" - "flakes" - ] - ++ lib.optional (lib.versionOlder (lib.versions.majorMinor config.nix.package.version) "2.22") "repl-flake"; - - # The default at 10 is rarely enough. - nix.settings.log-lines = lib.mkDefault 25; - # De-duplicate store paths using hardlinks except in containers # where the store is host-managed. nix.optimise.automatic = lib.mkDefault (!config.boot.isContainer); - # Avoid disk full issues - nix.settings.max-free = lib.mkDefault (3000 * 1024 * 1024); - nix.settings.min-free = lib.mkDefault (512 * 1024 * 1024); - # TODO: cargo culted. nix.daemonCPUSchedPolicy = lib.mkDefault "batch"; nix.daemonIOSchedClass = lib.mkDefault "idle"; @@ -40,7 +26,4 @@ # 100 is the default for user slices and 500 is systemd-coredumpd@ # We rather want a build to be killed than our precious user sessions as builds can be easily restarted. systemd.services.nix-daemon.serviceConfig.OOMScoreAdjust = lib.mkDefault 250; - - # Avoid copying unnecessary stuff over SSH - nix.settings.builders-use-substitutes = true; } diff --git a/shared/common/nix.nix b/shared/common/nix.nix new file mode 100644 index 00000000..f0096413 --- /dev/null +++ b/shared/common/nix.nix @@ -0,0 +1,23 @@ +{ lib, config, ... }: +{ + # Fallback quickly if substituters are not available. + nix.settings.connect-timeout = lib.mkDefault 5; + + # Enable flakes + nix.settings.experimental-features = + [ + "nix-command" + "flakes" + ] + ++ lib.optional (lib.versionOlder (lib.versions.majorMinor config.nix.package.version) "2.22") "repl-flake"; + + # The default at 10 is rarely enough. + nix.settings.log-lines = lib.mkDefault 25; + + # Avoid disk full issues + nix.settings.max-free = lib.mkDefault (3000 * 1024 * 1024); + nix.settings.min-free = lib.mkDefault (512 * 1024 * 1024); + + # Avoid copying unnecessary stuff over SSH + nix.settings.builders-use-substitutes = true; +} From 5293526ad15c2df54926269fce357ddd657db1f8 Mon Sep 17 00:00:00 2001 From: zowoq <59103226+zowoq@users.noreply.github.com> Date: Fri, 27 Sep 2024 17:51:48 +1000 Subject: [PATCH 2/2] add shared telegraf config --- darwin/mixins/telegraf.nix | 16 ++++------------ nixos/mixins/telegraf.nix | 33 +++------------------------------ shared/mixins/telegraf.nix | 38 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+), 42 deletions(-) create mode 100644 shared/mixins/telegraf.nix diff --git a/darwin/mixins/telegraf.nix b/darwin/mixins/telegraf.nix index bb075da7..ca3fbf45 100644 --- a/darwin/mixins/telegraf.nix +++ b/darwin/mixins/telegraf.nix @@ -5,22 +5,14 @@ ... }: { + imports = [ + ../../shared/mixins/telegraf.nix + ]; + services.telegraf = { - enable = true; extraConfig = { - agent.interval = "60s"; inputs = { smart.path_smartctl = "${pkgs.smartmontools}/bin/smartctl"; - system = { }; - mem = { }; - swap = { }; - disk.tagdrop.fstype = [ "ramfs" ]; - diskio = { }; - internal = { }; - }; - outputs.prometheus_client = { - listen = ":9273"; - metric_version = 2; }; }; }; diff --git a/nixos/mixins/telegraf.nix b/nixos/mixins/telegraf.nix index 2eff3924..c4c32306 100644 --- a/nixos/mixins/telegraf.nix +++ b/nixos/mixins/telegraf.nix @@ -89,13 +89,14 @@ let in { + imports = [ + ../../shared/mixins/telegraf.nix + ]; systemd.services.telegraf.path = lib.optional (!isVM && hasNvme) pkgs.nvme-cli; services.telegraf = { - enable = true; extraConfig = { - agent.interval = "60s"; inputs = { prometheus = lib.mkIf config.services.promtail.enable [ { @@ -106,8 +107,6 @@ in kernel_vmstat = { }; nginx.urls = lib.mkIf config.services.nginx.statusPage [ "http://localhost/nginx_status" ]; smart = lib.mkIf (!isVM) { path_smartctl = "/run/wrappers/bin/smartctl-telegraf"; }; - system = { }; - mem = { }; file = [ { @@ -129,36 +128,10 @@ in } ]; systemd_units = { }; - swap = { }; - disk.tagdrop = { - fstype = [ - "tmpfs" - "ramfs" - "devtmpfs" - "devfs" - "iso9660" - "overlay" - "aufs" - "squashfs" - "efivarfs" - ]; - device = [ - "rpc_pipefs" - "lxcfs" - "nsfs" - "borgfs" - ]; - }; - diskio = { }; - internal = { }; zfs = { poolMetrics = true; }; } // lib.optionalAttrs config.boot.swraid.enable { mdstat = { }; }; - outputs.prometheus_client = { - listen = ":9273"; - metric_version = 2; - }; }; }; security.wrappers.smartctl-telegraf = lib.mkIf (!isVM) { diff --git a/shared/mixins/telegraf.nix b/shared/mixins/telegraf.nix new file mode 100644 index 00000000..7af0e20f --- /dev/null +++ b/shared/mixins/telegraf.nix @@ -0,0 +1,38 @@ +{ + services.telegraf = { + enable = true; + extraConfig = { + agent.interval = "60s"; + inputs = { + system = { }; + mem = { }; + swap = { }; + disk.tagdrop = { + fstype = [ + "tmpfs" + "ramfs" + "devtmpfs" + "devfs" + "iso9660" + "overlay" + "aufs" + "squashfs" + "efivarfs" + ]; + device = [ + "rpc_pipefs" + "lxcfs" + "nsfs" + "borgfs" + ]; + }; + diskio = { }; + internal = { }; + }; + outputs.prometheus_client = { + listen = ":9273"; + metric_version = 2; + }; + }; + }; +}