Skip to content

Commit

Permalink
Merge pull request #526 from nix-community/shared
Browse files Browse the repository at this point in the history
  • Loading branch information
zimbatm authored Oct 3, 2024
2 parents b7aa1d7 + 5293526 commit 61b4d9b
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 84 deletions.
25 changes: 4 additions & 21 deletions darwin/common/nix.nix
Original file line number Diff line number Diff line change
@@ -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 [
Expand All @@ -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;
}
16 changes: 4 additions & 12 deletions darwin/mixins/telegraf.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
};
};
Expand Down
25 changes: 4 additions & 21 deletions nixos/common/nix.nix
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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;
}
33 changes: 3 additions & 30 deletions nixos/mixins/telegraf.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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 [
{
Expand All @@ -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 =
[
{
Expand All @@ -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) {
Expand Down
23 changes: 23 additions & 0 deletions shared/common/nix.nix
Original file line number Diff line number Diff line change
@@ -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;
}
38 changes: 38 additions & 0 deletions shared/mixins/telegraf.nix
Original file line number Diff line number Diff line change
@@ -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;
};
};
};
}

0 comments on commit 61b4d9b

Please sign in to comment.