Skip to content

Instantly share code, notes, and snippets.

@BigValen
Last active September 4, 2018 08:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BigValen/7266d80a44a02227f631e844621e1354 to your computer and use it in GitHub Desktop.
Save BigValen/7266d80a44a02227f631e844621e1354 to your computer and use it in GitHub Desktop.
# Edit this configuration file to define what should be installed on
# your system. Help is available in the configuration.nix(5) man page
# and in the NixOS manual (accessible by running ‘nixos-help’).
{ config, pkgs, lib, ... }:
with lib;
{
imports =
[ # Include the results of the hardware scan.
./hardware-configuration.nix
./rescue_boot.nix
];
nix.gc.automatic = true;
nix.gc.dates = "weekly";
nix.gc.options = "--delete-older-than 10d";
# boot.kernelPackages = pkgs.linuxPackages_4_4;
boot.loader.grub.enable = true;
boot.loader.grub.version = 2;
#boot.loader.grub.device = "/dev/disk/by-partuuid/9ea28dc0-01";
boot.loader.grub.device = "/dev/disk/by-id/usb-Generic_STORAGE_DEVICE_000000009407-0:0";
boot.loader.grub.splashImage = null;
boot.loader.grub.gfxmodeEfi= "text";
boot.loader.grub.gfxmodeBios= "text";
swapDevices = [ { device = "/dev/zvol/npool/swap"; } ];
# ZFS settings
boot.supportedFilesystems = [ "zfs " ];
boot.zfs.devNodes = "/dev/disk/by-id";
networking = {
defaultGateway = "192.168.0.1";
domain = "sutton.magicbluesmoke.net";
hostName = "nas";
hostId = "deadbeef";
interfaces.eno1 = {
ipv4.addresses = [
{ address="192.168.0.24"; prefixLength = 24; }
{ address="192.168.0.254"; prefixLength = 24; }
];
};
#interfaces.eno2 = {
# ip4 = [
# { useDhcp = true; };
# ];
#};
firewall = {
allowedTCPPorts = [ 80 53 443 3445 5201 32400 4949 445 139 3000 8000 9090 ];
allowedUDPPorts = [ 53 514 5201 ];
allowPing = true;
allowedUDPPortRanges = [{from = 60000; to = 61000;}];
};
nameservers = [ "192.168.0.24" "8.8.4.4" ];
};
# networking.wireless.enable = true; # Enables wireless support via wpa_supplicant.
security.sudo = {
wheelNeedsPassword = false;
enable = true;
configFile = ''
Defaults:root,%wheel env_keep+=TERMINFO_DIRS
Defaults:root,%wheel env_keep+=TERMINFO
Defaults env_keep+=SSH_AUTH_SOCK
root ALL=(ALL) SETENV: ALL
%wheel ALL=(ALL:ALL) NOPASSWD: ALL, SETENV: ALL
looney ALL=(ALL) SETENV: ALL
'';
};
# Select internationalisation properties.
# i18n = {
# consoleFont = "Lat2-Terminus16";
# consoleKeyMap = "us";
# defaultLocale = "en_US.UTF-8";
# };
# Set your time zone.
time.timeZone = "Europe/Dublin";
environment.systemPackages = with pkgs; [
# Debug tools
tcpdump
zlib
cacert
# System tools
parted psmisc atop
rrdtool
git
python
mailutils john
wget
curl
bind
logrotate
ipmitool
samba4Full
smartmontools
talloc
htop
];
# List services that you want to enable:
services = {
bind = {
cacheNetworks = [ "192.168.0.0/23" "127.0.0.0/8"] ;
enable = true;
forwarders = [ "8.8.4.4" "8.8.8.8" ] ;
zones = [
{ file = ./db.sutton.magicbluesmoke.net; master = true; name = "sutton.magicbluesmoke.net"; slaves = []; }
{ file = ./db.192.168.0; master = true; name = "0.168.192.in-addr.arpa"; slaves = []; }
];
ipv4Only = true;
};
cron = {
enable = true;
mailto = "john.looney@gmail.com";
};
dhcpd4 = {
enable = true;
interfaces = ["eno1"];
machines = [
{
hostName = "nas.sutton.magicbluesmoke.net";
ethernetAddress = "b0:5a:da:87:f0:74";
ipAddress = "192.168.0.24";
}
];
extraConfig = ''
option domain-name-servers 192.168.0.24, 8.8.4.4, 8.8.8.8;
option domain-name "sutton.magicbluesmoke.net";
option domain-search "sutton.magicbluesmoke.net";
option routers 192.168.0.1;
subnet 192.168.0.0 netmask 255.255.255.0 {
range 192.168.0.10 192.168.0.230;
default-lease-time 86400;
max-lease-time 2592000;
allow-client-updates;
ddns-updates on;
ddns-update-style interim;
}
'';
};
httpd = {
enablePHP = true;
virtualHosts =
[
{ hostName = "nas.sutton.magicbluesmoke.net";
documentRoot = "/home/webroot";
serverAliases = [ "nas" ];
adminAddr = "alice@example.org";
enableUserDir = true;
extraConfig = "
ScriptAlias /cgi-bin/ /home/webroot/cgi-bin/ ";
}
];
enable = true;
adminAddr = "john.looney@gmail.com";
};
locate = {
enable = true;
};
prometheus = {
enable = true;
alertmanagerURL = [ "http://localhost:9093" ];
globalConfig = {
scrape_interval = "30s";
};
scrapeConfigs = let
nameInstance = address: name: {
source_labels = [ "__address__" ];
target_label = "instance";
regex = address;
replacement = name;
};
in [
{
job_name = "prometheus";
static_configs = [{
targets = [
"localhost:9090"
];
}];
relabel_configs = [
(nameInstance "localhost:9090" "workbot")
];
} {
job_name = "nodes";
scrape_interval = "10s";
static_configs = [{
targets = [
"localhost:9100"
];
}];
relabel_configs = [
(nameInstance "localhost:9100" "workbot")
];
} {
job_name = "systemd";
scrape_interval = "60s";
static_configs = [{
targets = [
"localhost:9333"
];
}];
relabel_configs = [
(nameInstance "localhost:9333" "workbot")
];
}
];
exporters = {
node = {
enable = true;
listenAddress = "127.0.0.1";
enabledCollectors = [
"systemd"
];
};
};
};
grafana = {
enable = true;
addr = "0.0.0.0";
domain = "nas.sutton.magicbluesmoke.com";
};
logrotate = { enable = true; };
mysql.package = pkgs.mysql;
mysql.enable = false;
openssh.enable = true;
postfix = {
enable = true;
config.mailq_path = "${pkgs.postfix}/sbin/mailq";
};
plex = {
package = pkgs.plex;
enable = false;
};
smartd = {
enable = true;
notifications.mail.recipient = "john.looney@gmail.com";
notifications.mail.enable = true;
};
samba = {
enable = true;
syncPasswordsByPam = true;
shares = {
Books = {
path = "/home/Books";
"read only" = "yes";
"browseable" = "yes";
"guest ok" = "yes";
};
DVDS = {
path = "/home/DVDS";
"read only" = "yes";
"browseable" = "yes";
"guest ok" = "yes";
};
Music = {
path = "/home/Music";
"read only" = "yes";
"browseable" = "yes";
"guest ok" = "yes";
"available" = "yes";
"public" = "yes";
};
Video = {
path = "/home/Video";
"read only" = "yes";
"browseable" = "yes";
"guest ok" = "yes";
};
HomeVideos = {
path = "/home/HomeVideo";
"read only" = "yes";
"browseable" = "yes";
"guest ok" = "yes";
};
julie = {
comment = "Julie's Homedir";
path = "/home/julie";
"valid users" = "julie";
# "admin users" = "julie";
writeable = "Yes";
};
looney = {
comment = "John's Homedir";
path = "/home/looney";
"valid users" = "looney";
# "admin users" = "looney";
writeable = "Yes";
};
};
extraConfig = ''
[global]
guest account = home
map to guest = Bad User
security = user
load printers = no
printing = bsd
printcap name = /dev/null
disable spoolss = yes
browseable = yes
writeable = yes
printable = no
server string = nas
workgroup = WORKGROUP
netbios name = nas
# Debug logging information
log level = 2
log file = /var/log/samba/log.%m
max log size = 50
debug timestamp = yes
'';
};
zfs.autoSnapshot.enable = true;
};
# Define a user account. Don't forget to set a password with ‘passwd’.
users.extraGroups = {
kvm = {};
};
users.extraUsers = {
looney = {
isNormalUser = true;
uid = 1000;
extraGroups = [ "wheel" ];
openssh.authorizedKeys.keys = [ "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDJO6sfbq6owMTXi8EkWRQIWPumTjT0H6yK5zDlOeoMtTE0htz1a63/lG9WlT+H/G8y4TjG+bn3Ma8xWZIoS5WB1dCvyCren620RchZNJmc47A5p+eWtqm9ctwghN+WJVjBk5N6gI9VfU3np+OjJECDMsJTtEjJeqJ6LDXv5cavafOEsL/uFG1noZRJ94ug88uIcmUevyy85nh3QfoGXCrPjd3Th6zCfCHDopDn+ykQiAgJv+oUYxrYUkxnOJXKmdD3i1sm2De8lbtEJA/rgBFjRRL+xG0TQ6bp4Xfl0lA6LCUfcDlq+RO6/l8bS9i2sQZk+Jm++AnhFoBltwQC20J5 looney@looney2-l.dub.corp.google.com" ];
};
home = {
isNormalUser = true;
uid = 502;
};
};
virtualisation = {
docker = {
enable = true;
enableOnBoot = true;
storageDriver = "zfs";
autoPrune = {
enable = true;
};
};
};
system.autoUpgrade.enable = true;
nix.extraOptions = "auto-optimise-store = true";
nixpkgs.config = {
allowUnfree = true;
};
systemd.services.prometheus-node-exporter.script = ''
exec ${pkgs.prometheus-node-exporter}/bin/node_exporter --no-collector.hwmon \
${optionalString (config.services.prometheus.exporters.node.enabledCollectors != [])
''-collectors.enabled ${concatStringsSep "," config.services.prometheus.exporters.node.enabledCollectors}''} \
-web.listen-address ${config.services.prometheus.exporters.node.listenAddress}:${toString config.services.prometheus.exporters.node.port} \
${concatStringsSep " \\\n " config.services.prometheus.exporters.node.extraFlags}
'';
}
@BigValen
Copy link
Author

BigValen commented Sep 4, 2018

[root@nas:/sys/class/hwmon]# nixos-rebuild switch --show-trace
building Nix...
building the system configuration...
error: while evaluating the attribute 'activationScript' of the derivation 'nixos-system-nas-18.03.133188.8b92a4e6004' at /nix/store/z0gsgq0309r5j3ks7aqzlsibcipa0r1z-nixos-18.03.133188.8b92a4e6004/nixos/pkgs/stdenv/generic/make-derivation.nix:148:11:
while evaluating the attribute 'system.activationScripts.script' at /nix/var/nix/profiles/per-user/root/channels/nixos/nixpkgs/nixos/modules/system/activation/activation-script.nix:62:9:
while evaluating 'textClosureMap' at /nix/var/nix/profiles/per-user/root/channels/nixos/nixpkgs/lib/strings-with-deps.nix:70:35, called from /nix/var/nix/profiles/per-user/root/channels/nixos/nixpkgs/nixos/modules/system/activation/activation-script.nix:83:18:
while evaluating 'id' at /nix/var/nix/profiles/per-user/root/channels/nixos/nixpkgs/lib/trivial.nix:9:8, called from undefined position:
while evaluating the attribute 'text' at /nix/var/nix/profiles/per-user/root/channels/nixos/nixpkgs/nixos/modules/system/activation/activation-script.nix:9:5:
while evaluating the attribute 'text' at /nix/var/nix/profiles/per-user/root/channels/nixos/nixpkgs/lib/strings-with-deps.nix:77:38:
while evaluating the attribute 'sources' of the derivation 'etc' at /nix/store/z0gsgq0309r5j3ks7aqzlsibcipa0r1z-nixos-18.03.133188.8b92a4e6004/nixos/pkgs/stdenv/generic/make-derivation.nix:148:11:
while evaluating anonymous function at /nix/var/nix/profiles/per-user/root/channels/nixos/nixpkgs/nixos/modules/system/etc/etc.nix:20:20, called from undefined position:
while evaluating the attribute 'source' at /nix/var/nix/profiles/per-user/root/channels/nixos/nixpkgs/lib/attrsets.nix:199:44:
while evaluating anonymous function at /nix/var/nix/profiles/per-user/root/channels/nixos/nixpkgs/lib/modules.nix:75:45, called from /nix/var/nix/profiles/per-user/root/channels/nixos/nixpkgs/lib/attrsets.nix:199:52:
while evaluating the attribute 'value' at /nix/var/nix/profiles/per-user/root/channels/nixos/nixpkgs/lib/modules.nix:312:9:
while evaluating the option environment.etc.systemd/system.source': while evaluating the attribute 'mergedValue' at /nix/var/nix/profiles/per-user/root/channels/nixos/nixpkgs/lib/modules.nix:339:5: while evaluating anonymous function at /nix/var/nix/profiles/per-user/root/channels/nixos/nixpkgs/lib/modules.nix:339:32, called from /nix/var/nix/profiles/per-user/root/channels/nixos/nixpkgs/lib/modules.nix:339:19: while evaluating 'check' at /nix/var/nix/profiles/per-user/root/channels/nixos/nixpkgs/lib/types.nix:230:15, called from /nix/var/nix/profiles/per-user/root/channels/nixos/nixpkgs/lib/modules.nix:340:10: while evaluating the attribute 'buildCommand' of the derivation 'system-units' at /nix/store/z0gsgq0309r5j3ks7aqzlsibcipa0r1z-nixos-18.03.133188.8b92a4e6004/nixos/pkgs/stdenv/generic/make-derivation.nix:148:11: while evaluating the attribute 'text' of the derivation 'unit-prometheus-node-exporter.service' at /nix/store/z0gsgq0309r5j3ks7aqzlsibcipa0r1z-nixos-18.03.133188.8b92a4e6004/nixos/pkgs/stdenv/generic/make-derivation.nix:148:11: while evaluating the attribute 'text' at /nix/var/nix/profiles/per-user/root/channels/nixos/nixpkgs/lib/attrsets.nix:199:44: while evaluating anonymous function at /nix/var/nix/profiles/per-user/root/channels/nixos/nixpkgs/lib/modules.nix:75:45, called from /nix/var/nix/profiles/per-user/root/channels/nixos/nixpkgs/lib/attrsets.nix:199:52: while evaluating the attribute 'value' at /nix/var/nix/profiles/per-user/root/channels/nixos/nixpkgs/lib/modules.nix:312:9: while evaluating the option systemd.units.prometheus-node-exporter.service.text':
while evaluating the attribute 'isDefined' at /nix/var/nix/profiles/per-user/root/channels/nixos/nixpkgs/lib/modules.nix:344:5:
while evaluating 'filterOverrides' at /nix/var/nix/profiles/per-user/root/channels/nixos/nixpkgs/lib/modules.nix:419:21, called from /nix/var/nix/profiles/per-user/root/channels/nixos/nixpkgs/lib/modules.nix:328:18:
while evaluating 'concatMap' at /nix/var/nix/profiles/per-user/root/channels/nixos/nixpkgs/lib/lists.nix:102:18, called from /nix/var/nix/profiles/per-user/root/channels/nixos/nixpkgs/lib/modules.nix:425:8:
while evaluating 'concatMap' at /nix/var/nix/profiles/per-user/root/channels/nixos/nixpkgs/lib/lists.nix:102:18, called from /nix/var/nix/profiles/per-user/root/channels/nixos/nixpkgs/lib/modules.nix:323:17:
while evaluating anonymous function at /nix/var/nix/profiles/per-user/root/channels/nixos/nixpkgs/lib/modules.nix:323:28, called from undefined position:
while evaluating 'dischargeProperties' at /nix/var/nix/profiles/per-user/root/channels/nixos/nixpkgs/lib/modules.nix:386:25, called from /nix/var/nix/profiles/per-user/root/channels/nixos/nixpkgs/lib/modules.nix:324:62:
while evaluating the attribute 'value' at /nix/var/nix/profiles/per-user/root/channels/nixos/nixpkgs/lib/modules.nix:216:48:
while evaluating the attribute 'config.text' at /nix/var/nix/profiles/per-user/root/channels/nixos/nixpkgs/nixos/modules/system/boot/systemd.nix:318:7:
while evaluating 'attrsToSection' at /nix/var/nix/profiles/per-user/root/channels/nixos/nixpkgs/nixos/modules/system/boot/systemd-lib.nix:96:20, called from /nix/var/nix/profiles/per-user/root/channels/nixos/nixpkgs/nixos/modules/system/boot/systemd.nix:332:13:
while evaluating anonymous function at /nix/var/nix/profiles/per-user/root/channels/nixos/nixpkgs/lib/attrsets.nix:224:10, called from undefined position:
while evaluating anonymous function at /nix/var/nix/profiles/per-user/root/channels/nixos/nixpkgs/nixos/modules/system/boot/systemd-lib.nix:97:55, called from /nix/var/nix/profiles/per-user/root/channels/nixos/nixpkgs/lib/attrsets.nix:224:16:
while evaluating the attribute 'ExecStart' at /nix/var/nix/profiles/per-user/root/channels/nixos/nixpkgs/lib/attrsets.nix:199:44:
while evaluating anonymous function at /nix/var/nix/profiles/per-user/root/channels/nixos/nixpkgs/lib/types.nix:268:22, called from /nix/var/nix/profiles/per-user/root/channels/nixos/nixpkgs/lib/attrsets.nix:199:52:
while evaluating the attribute 'value' at /nix/var/nix/profiles/per-user/root/channels/nixos/nixpkgs/lib/modules.nix:347:27:
while evaluating anonymous function at /nix/var/nix/profiles/per-user/root/channels/nixos/nixpkgs/lib/modules.nix:339:32, called from /nix/var/nix/profiles/per-user/root/channels/nixos/nixpkgs/lib/modules.nix:339:19:
while evaluating 'merge' at /nix/var/nix/profiles/per-user/root/channels/nixos/nixpkgs/nixos/modules/system/boot/systemd-unit-options.nix:20:18, called from /nix/var/nix/profiles/per-user/root/channels/nixos/nixpkgs/lib/modules.nix:342:8:
while evaluating 'mergeOneOption' at /nix/var/nix/profiles/per-user/root/channels/nixos/nixpkgs/lib/options.nix:62:25, called from /nix/var/nix/profiles/per-user/root/channels/nixos/nixpkgs/nixos/modules/system/boot/systemd-unit-options.nix:27:14:
The unique option systemd.services.prometheus-node-exporter.serviceConfig.ExecStart' is defined multiple times, in /nix/var/nix/profiles/per-user/root/channels/nixos/nixpkgs/nixos/modules/services/monitoring/prometheus/exporters.nix' and `/nix/var/nix/profiles/per-user/root/channels/nixos/nixpkgs/nixos/modules/system/boot/systemd.nix'.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment