dotfiles/nix/base-system/darwin-configuration.nix

371 lines
13 KiB
Nix
Raw Normal View History

{ pkgs, config, lib, ... }:
2024-06-21 09:38:34 -04:00
let
vfkit = pkgs.callPackage ../packages/vfkit.nix {};
in
2022-02-21 14:01:24 -05:00
{
2022-05-02 19:25:20 -04:00
nix = {
package = pkgs.nix;
2025-06-12 18:23:40 -04:00
enable = true;
# SEE: https://github.com/NixOS/nix/issues/4119#issuecomment-1734738812
settings.sandbox = "relaxed";
2022-05-02 19:25:20 -04:00
extraOptions = ''
2025-06-12 18:23:40 -04:00
experimental-features = nix-command flakes
extra-platforms = x86_64-darwin aarch64-darwin x86_64-linux
2024-06-12 19:00:42 -04:00
trusted-users = root zaphar
2022-05-02 19:25:20 -04:00
'';
};
2022-11-20 14:04:02 -05:00
# Right now the documentation build is broken.
# TODO(jwall): Add this back when they work again.
documentation.enable = false;
2022-02-21 14:01:24 -05:00
# I'm not a zealot about this one.
nixpkgs.config.allowUnfree = true;
2022-04-17 16:02:03 -04:00
nixpkgs.overlays = [
(self: super: {
neovim = super.neovim.override {
viAlias = true;
vimAlias = true;
};
})
];
2024-02-19 10:40:10 -05:00
# TODO(zaphar): Move this to a module.
#launchd.user.agents.ipfs = {
# serviceConfig = {
# ProgramArguments = [
# "${pkgs.kubo}/bin/ipfs"
# "daemon"
# "--init"
# ];
# KeepAlive = true;
# RunAtLoad = true;
# };
#};
2023-07-11 11:31:13 -04:00
2025-04-04 13:24:54 -04:00
services.ollama = {
enable = true;
user="zaphar";
};
2024-10-08 10:09:49 -04:00
services.my-lorri.enable = true;
services.durnitisp.enable = true;
2024-02-19 10:40:10 -05:00
services.node-exporter.enable = true;
services.prometheus.enable = true;
2024-02-23 11:58:30 -05:00
services.heracles.enable = true;
services.heracles.settings = [
{
title = "Metrics";
span = {
end = "now";
2024-06-11 16:56:55 -04:00
duration = "1h";
step_duration = "1min";
2024-02-23 11:58:30 -05:00
};
graphs = [
{
title = "CPU and Mem Used";
query_type = "Range";
2024-02-28 11:13:56 -05:00
yaxes = [
{
anchor = "y";
tickformat = "~%";
}
];
2024-02-23 11:58:30 -05:00
plots = [
2024-02-28 11:13:56 -05:00
{ # Memory Usage
source = "http://${config.services.prometheus.listen}";
query = ''
(node_memory_wired_bytes
+ node_memory_compressed_bytes
+ node_memory_active_bytes)
/ node_memory_total_bytes
'';
config = {
2024-02-28 11:13:56 -05:00
name_format = "`\${labels.instance} - Memory`";
yaxis = "y";
fill = "tozeroy";
};
}
2024-02-23 11:58:30 -05:00
{ # CPU plot
source = "http://${config.services.prometheus.listen}";
query = ''
2024-02-28 11:13:56 -05:00
sum by (job,instance, mode)(irate(node_cpu_seconds_total{mode!="idle"}[5m]))
2024-02-23 11:58:30 -05:00
/ ignoring(mode) group_left
2024-03-20 15:15:08 -04:00
sum by (job,instance)(irate(node_cpu_seconds_total[5m]))
2024-02-23 11:58:30 -05:00
'';
config = {
2024-02-23 11:58:30 -05:00
name_format = "`\${labels.instance} - \${labels.mode}`";
2024-02-28 11:13:56 -05:00
axis = "y";
2024-02-23 11:58:30 -05:00
};
}
2024-02-28 11:13:56 -05:00
];
}
{
title = "Network Latency";
2024-02-28 11:13:56 -05:00
query_type = "Range";
d3_tick_format = "~s";
yaxes = [
{
anchor = "y";
type = "log";
2024-02-28 11:13:56 -05:00
}
];
plots = [
{
2024-02-23 11:58:30 -05:00
source = "http://${config.services.prometheus.listen}";
query = ''
stun_attempt_latency_ms
2024-02-23 11:58:30 -05:00
'';
config = {
name_format = "`UDP \${labels.domain} latency`";
2024-02-28 11:13:56 -05:00
yaxis = "y";
};
}
{
source = "http://${config.services.prometheus.listen}";
query = ''
ping_latency
2024-02-28 11:13:56 -05:00
'';
config = {
name_format = "`Ping \${labels.domain} latency`";
2024-02-28 11:13:56 -05:00
yaxis = "y";
};
}
];
}
{
title = "Network Errors 5m delta";
query_type = "Range";
d3_tick_format = "~s";
yaxes = [
{
anchor = "y";
}
];
plots = [
{
source = "http://${config.services.prometheus.listen}";
query = ''
delta(stun_attempt_counter{result="err"}[5m])
'';
config = {
name_format = "`UDP \${labels.domain} failure count`";
yaxis = "y1";
};
}
{
source = "http://${config.services.prometheus.listen}";
query = ''
delta(ping_counter{result="dropped"}[5m])
'';
config = {
name_format = "`icmp \${labels.domain} drop count`";
yaxis = "y1";
};
}
];
}
2024-02-28 11:13:56 -05:00
{
title = "Network Traffic Bytes";
2024-02-28 11:13:56 -05:00
query_type = "Range";
d3_tick_format = "~s";
yaxes = [
{
anchor = "y";
type = "log";
2024-02-28 11:13:56 -05:00
}
];
plots = [
{
source = "http://${config.services.prometheus.listen}";
query = ''
irate(node_network_receive_bytes_total{device=~"(lo|en).*"}[5m])
2024-02-28 11:13:56 -05:00
'';
config = {
name_format = "`\${labels.device} Rx`";
2024-02-28 11:13:56 -05:00
yaxis = "y";
};
}
{
source = "http://${config.services.prometheus.listen}";
query = ''
irate(node_network_transmit_bytes_total{device=~"(lo|en).*"}[5m])
2024-02-28 11:13:56 -05:00
'';
config = {
name_format = "`\${labels.device} Tx`";
2024-02-28 11:13:56 -05:00
yaxis = "y";
2024-02-23 11:58:30 -05:00
};
}
];
}
];
}
];
2024-02-19 10:40:10 -05:00
services.victoria-logs.enable = true;
services.vector.enable = true;
services.vector.settings = {
data_dir = "/var/lib/vector";
api = {
enabled = true;
2024-06-20 23:24:21 -04:00
address = "127.0.0.1:8686";
};
sources = {
prometheus = {
type = "file";
include = [
config.services.prometheus.stdoutPath
config.services.prometheus.stderrPath
];
};
#heracles = {
# type = "file";
# include = [
# config.services.heracles.stdoutPath
# config.services.heracles.stderrPath
# ];
#};
# TODO(zaphar): We should remap durnitisp output to strip the TTY control characters.
durnitisp = {
type = "file";
include = [
config.services.durnitisp.stdoutPath
config.services.durnitisp.stderrPath
];
};
vector = {
2024-06-11 16:56:55 -04:00
type = "internal_logs";
};
victoria-logs = {
type = "file";
include = [
config.services.victoria-logs.stdoutPath
config.services.victoria-logs.stderrPath
];
};
system = {
type = "file";
include = [
"/var/log/system.log"
"/var/log/com.apple.xpc.launchd/launchd.log"
];
};
syslog_source = {
type = "exec";
command = ["/usr/bin/log" "stream" "--style" "ndjson"];
mode = "streaming";
};
};
transforms = {
durnitisp_no_tty = {
type = "remap";
inputs = [
"durnitisp"
];
source = ''
.message = strip_ansi_escape_codes(.message) ?? .message
'';
};
syslog = {
type = "remap";
inputs = [
"syslog_source"
];
source = ''
.message = parse_json(.message) ?? .message
del(.command)
.syslog
.eventType = .message.eventType
.processImagePath = .message.processImagePath
'';
};
};
sinks = {
victoria_vector = {
type = "elasticsearch";
mode = "bulk";
endpoints = [
"http://${config.services.victoria-logs.listenAddr}/insert/elasticsearch"
];
inputs = [
"vector"
];
api_version = "v8";
healthcheck.enabled = false;
query = {
_msg_field = "message";
_time_field = "timestamp";
_stream_fields = "host,source_type";
};
};
victoria_syslog = {
type = "elasticsearch";
mode = "bulk";
endpoints = [
"http://${config.services.victoria-logs.listenAddr}/insert/elasticsearch"
];
inputs = [
"syslog"
];
api_version = "v8";
healthcheck.enabled = false;
query = {
_msg_field = "message";
_time_field = "timestamp";
_stream_fields = "host,processImagePath,eventType";
};
};
victoria_files = {
type = "elasticsearch";
mode = "bulk";
endpoints = [
2024-06-11 16:56:55 -04:00
"http://${config.services.victoria-logs.listenAddr}/insert/elasticsearch"
];
inputs = [
"prometheus"
#"heracles"
"durnitisp_no_tty"
"victoria-logs"
"system"
];
api_version = "v8";
healthcheck.enabled = false;
query = {
_msg_field = "message";
_time_field = "timestamp";
_stream_fields = "host,file";
};
};
};
};
2022-02-21 14:01:24 -05:00
# Use a custom configuration.nix location.
# $ darwin-rebuild switch -I darwin-config=$HOME/.config/nixpkgs/darwin/configuration.nix
# environment.darwinConfig = "$HOME/.config/nixpkgs/darwin/configuration.nix";
2024-06-21 09:38:34 -04:00
environment.systemPackages = [
2024-08-22 23:23:51 -05:00
# Required on darwin for podman machine to work.
2024-06-21 09:38:34 -04:00
vfkit
];
2022-02-21 14:01:24 -05:00
#services.spacebar.enable = true;
#services.spacebar.package = "${pkgs.spacebar}";
# Create /etc/bashrc that loads the nix-darwin environment.
# programs.bash.enable = true; # default shell on catalina
2022-02-21 14:01:24 -05:00
# programs.fish.enable = true;
system.defaults = {
finder.AppleShowAllExtensions = true;
};
system.systemBuilderArgs = lib.mkIf (config.nix.settings.sandbox == "relaxed") {
sandboxProfile = ''
(allow file-read* file-write* process-exec mach-lookup (subpath "${builtins.storeDir}"))
'';
};
2025-06-12 18:23:40 -04:00
system.primaryUser = "zaphar";
2022-02-21 14:01:24 -05:00
# Used for backwards compatibility, please read the changelog before changing.
# $ darwin-rebuild changelog
system.stateVersion = 4;
}