Skip to content

Instantly share code, notes, and snippets.

@thorhop
Last active March 26, 2020 10:28
Show Gist options
  • Save thorhop/9e6b09d2cb0b904ae594 to your computer and use it in GitHub Desktop.
Save thorhop/9e6b09d2cb0b904ae594 to your computer and use it in GitHub Desktop.
My current NixOS config
# 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, ... }:
{
imports =
[ # Include the results of the hardware scan.
./hardware-configuration.nix
/dir/to/musnix/default.nix
];
boot.loader = {
efi.canTouchEfiVariables = true;
gummiboot.enable = true;
};
networking = {
hostName = "Mjolnir"; # Define your hostname.
hostId = "XXXXXXX";
networkmanager.enable = true;
};
# Select internationalisation properties.
i18n = {
consoleFont = "sun12x22"; # "ter-132n";
consoleKeyMap = "no-latin1";
defaultLocale = "nb_NO.UTF-8";
};
time.timeZone = "Europe/Oslo";
users.extraUsers.thor = {
isNormalUser = true;
extraGroups = ["wheel" "audio" "video" "networkmanager" "input"];
uid = 1000;
};
# Enable the X11 windowing system.
services = {
# To show the manual in one of the terminals
nixosManual.showManual = true;
acpid.enable = true;
# Disable NTP, enable chrony...
ntp.enable = false;
chrony.enable = true;
# Setup X
xserver = {
enable = true;
layout = "no";
videoDrivers = [ "intel" ];
vaapiDrivers = [ pkgs.vaapiIntel ];
displayManager.slim.enable = true;
desktopManager.kde5.enable = true;
desktopManager.kde5.phononBackends = [ "vlc" ];
deviceSection = ''
Option "AccelMethod" "sna"
Option "TearFree" "true"
'';
displayManager.sessionCommands = ''
# Map left superkey to left ALT+F1
xcape -e "Super_L=Alt_L|F1"
'';
synaptics = {
enable = true;
twoFingerScroll = true;
#buttonsMap = [1 3 2];
};
startGnuPGAgent = true;
};
quassel = {
enable = true;
user = "thor";
dataDir = "/home/thor/.config/quassel-irc.org/";
};
# Install standard network services
samba.enable = true;
geoclue2.enable = true;
minidlna.enable = true;
avahi.enable = true;
# ...and a guardian at the gate
fail2ban.enable = true;
locate.enable = true;
# Gotta be kind to your eyes...
redshift = {
enable = true;
# Bergen, Norway
latitude = "60.397076";
longitude = "5.324383";
temperature.night = 2500;
};
# Adding smartmond to implement a more rigerous checking
# of the hit and miss S.M.A.R.T. drive health check system
smartd.enable = true;
udev.extraRules = ''
SUBSYSTEM=="usb", ATTR{idVendor}=="0499", ATTR{idProduct}=="150e", RUN="/etc/nixos/load_ur44.sh"
'';
};
programs.bash.enableCompletion = true;
programs.ssh.startAgent = false;
fonts = {
enableFontDir = true;
enableGhostscriptFonts = true;
fonts = with pkgs; [
corefonts # Micrsoft free fonts
inconsolata # monospaced
ubuntu_font_family # Ubuntu fonts
terminus_font # for hidpi screens, large fonts
liberation_ttf
];
#fontconfig.dpi = 192;
};
# Nixpkgs bulid options
nixpkgs.config = {
allowUnfree = true;
firefox = {
enableGoogleTalkPlugin = true;
enableAdobeFlash = true;
};
};
# List packages installed in system profile. To search by name, run:
# $ nix-env -qaP | grep wget
environment.systemPackages = with pkgs; [
firefoxWrapper
wget git sudo nodejs terminus_font gpgme xcape
#?Missing dependency for optimus?#
virtualgl
jack2 qjackctl
];
musnix = {
enable = true;
kernel.optimize = true;
kernel.realtime = true;
kernel.debug = true;
};
}
# Do not modify this file! It was generated by ‘nixos-generate-config’
# and may be overwritten by future invocations. Please make changes
# to /etc/nixos/configuration.nix instead.
{ config, lib, pkgs, ... }:
{
imports =
[ <nixpkgs/nixos/modules/installer/scan/not-detected.nix>
];
boot = {
initrd.availableKernelModules = [ "xhci_hcd" "ehci_pci" "ahci" "usb_storage" "i915" "fbcon"];
#kernelPackages = pkgs.linuxPackages_latest;
kernelModules = [ "kvm-intel" "i915" "fbcon" ];
kernelParams = [ "snd-hda-intel.index=1,0" "rcutree.rcu_idle_gp_delay=1" ];
extraModulePackages = [ pkgs.iwlwifi ];
};
hardware = {
enableAllFirmware = true;
pulseaudio.enable = true;
bluetooth.enable = true;
opengl.driSupport32Bit = true;
#bumblebee = {
# enable = true;
# group = "video";
#};
};
security.rtkit.enable = true;
security.sudo.enable = true;
security.polkit.extraConfig = ''
polkit.addRule(function(action, subject) {
var YES = polkit.Result.YES;
var permission = {
// only required for udisks1:
"org.freedesktop.udisks.filesystem-mount": YES,
"org.freedesktop.udisks.filesystem-mount-system-internal": YES,
"org.freedesktop.udisks.luks-unlock": YES,
"org.freedesktop.udisks.drive-eject": YES,
"org.freedesktop.udisks.drive-detach": YES,
// only required for udisks2:
"org.freedesktop.udisks2.filesystem-mount": YES,
"org.freedesktop.udisks2.filesystem-mount-system": YES,
"org.freedesktop.udisks2.encrypted-unlock": YES,
"org.freedesktop.udisks2.eject-media": YES,
"org.freedesktop.udisks2.power-off-drive": YES
};
if (subject.isInGroup("wheel")) {
return permission[action.id];
}
});
'';
fileSystems."/" =
{ device = "/dev/disk/by-uuid/fe84eabe-6e40-48da-a9dc-f2e55d72a400";
fsType = "btrfs";
options = "subvol=root compress=no";
};
fileSystems."/home" =
{ device = "/dev/disk/by-uuid/fe84eabe-6e40-48da-a9dc-f2e55d72a400";
fsType = "btrfs";
options = "subvol=home compress=no";
};
fileSystems."/etc" =
{ device = "/dev/disk/by-uuid/fe84eabe-6e40-48da-a9dc-f2e55d72a400";
fsType = "btrfs";
options = "subvol=etc compress=no";
};
fileSystems."/boot" =
{ device = "/dev/disk/by-uuid/9FE6-5063";
fsType = "vfat";
};
swapDevices =
[ { device = "/dev/disk/by-uuid/74e23e17-7225-42e2-9053-55c4c237634d"; }
];
nix.maxJobs = 8;
}
{ config, lib, pkgs, ... }:
with lib;
let
cfg = config.musnix;
kernelConfigLatencyTOP = ''
LATENCYTOP y
SCHEDSTATS y
'';
kernelConfigOptimize = ''
IOSCHED_DEADLINE y
DEFAULT_DEADLINE y
DEFAULT_IOSCHED "deadline"
HPET_TIMER y
TREE_RCU_TRACE n
'';
kernelConfigRealtime = ''
PREEMPT_RT_FULL y
PREEMPT y
'';
kernelDebug = ''
KGDB y
'';
kernelSources = rec {
version = "3.14.31";
src = pkgs.fetchurl {
url = "mirror://kernel/linux/kernel/v3.x/linux-${version}.tar.xz";
sha256 = "a6dd667bde3eab17ccd7dc0af1fc1e8188dc12295f11c2e18113905f830b47c8";
};
};
realtimePatch = rec {
version = "rt28";
kversion = "3.14.31";
name = "rt-${kversion}-${version}";
patch = pkgs.fetchurl {
url = "https://www.kernel.org/pub/linux/kernel/projects/rt/3.14/patch-${kversion}-${version}.patch.xz";
sha256 = "0aafc2e25dbfcb98f678276b30bd681b07209452269538ab7e268967d9fda03e";
};
};
in
{
options = {
musnix = {
enable = mkOption {
type = types.bool;
default = false;
description = ''
Enable musnix, a module for real-time audio.
'';
};
kernel.latencytop = mkOption {
type = types.bool;
default = false;
description = ''
WARNING: Enabling this option will rebuild your kernel.
If enabled, this option will configure the kernel to use a
latency tracking infrastructure that is used by the
"latencytop" userspace tool.
'';
};
kernel.optimize = mkOption {
type = types.bool;
default = false;
description = ''
WARNING: Enabling this option will rebuild your kernel.
If enabled, this option will configure the kernel to be
preemptible, to use the deadline I/O scheduler, and to use
the High Precision Event Timer (HPET).
'';
};
kernel.realtime = mkOption {
type = types.bool;
default = false;
description = ''
WARNING: Enabling this option will rebuild your kernel.
If enabled, this option will apply the CONFIG_PREEMPT_RT
patch to the kernel.
'';
};
kernel.debug = mkOption {
type = types.bool;
default = false;
description = ''
WARNING: Enabling this option will rebuild your kernel.
If enabled, this option will enable the KGDB, or the
kernel debugger. This is used to debug the realtime
kernel and should ONLY be enabled if the user knows
how to use it or has been instructed to use it.
'';
};
alsaSeq.enable = mkOption {
type = types.bool;
default = true;
description = ''
If enabled, load ALSA Sequencer kernel modules. Currently,
this only loads the `snd_seq` and `snd_rawmidi` modules.
'';
};
ffado.enable = mkOption {
type = types.bool;
default = false;
description = ''
If enabled, use the Free FireWire Audio Drivers (FFADO).
'';
};
soundcardPciId = mkOption {
type = types.str;
default = "";
example = "$00:1b.0";
description = ''
The PCI ID of the primary soundcard. Used to set the PCI
latency timer.
To find the PCI ID of your soundcard:
lspci | grep -i audio
'';
};
};
};
config = mkIf (config.sound.enable && cfg.enable) {
boot = {
kernel.sysctl = { "vm.swappiness" = 10; };
kernelModules =
if cfg.alsaSeq.enable
then [ "snd-seq"
"snd-rawmidi"
]
else [];
kernelPackages =
let
rtKernel =
pkgs.linux_3_14.override {
argsOverride = kernelSources;
kernelPatches = [ realtimePatch ];
extraConfig = kernelConfigRealtime
+ optionalString cfg.kernel.optimize kernelConfigOptimize
+ optionalString cfg.kernel.latencytop kernelConfigLatencyTOP
+ optionalString cfg.kernel.debug kernelDebug;
};
stdKernel =
if cfg.kernel.optimize
then pkgs.linux.override {
extraConfig = "PREEMPT y\n"
+ kernelConfigOptimize
+ optionalString cfg.kernel.latencytop kernelConfigLatencyTOP
+ optionalString cfg.kernel.debug kernelDebug;
}
else if cfg.kernel.latencytop
then pkgs.linux.override { extraConfig = kernelConfigLatencyTOP; }
else pkgs.linux;
in if cfg.kernel.realtime
then pkgs.recurseIntoAttrs (pkgs.linuxPackagesFor rtKernel pkgs.linuxPackages_3_14)
else pkgs.recurseIntoAttrs (pkgs.linuxPackagesFor stdKernel pkgs.linuxPackages);
kernelParams = [ "threadirq" ];
postBootCommands = ''
echo 2048 > /sys/class/rtc/rtc0/max_user_freq
echo 2048 > /proc/sys/dev/hpet/max-user-freq
'' + optionalString (cfg.soundcardPciId != "") ''
setpci -v -d *:* latency_timer=b0
setpci -v -s ${cfg.soundcardPciId} latency_timer=ff
'';
};
environment.systemPackages =
if cfg.ffado.enable
then [ pkgs.ffado ]
else [];
powerManagement.cpuFreqGovernor = "performance";
security.pam.loginLimits = [
{ domain = "@audio"; item = "memlock"; type = "-"; value = "unlimited"; }
{ domain = "@audio"; item = "rtprio"; type = "-"; value = "99"; }
{ domain = "@audio"; item = "nofile"; type = "soft"; value = "99999"; }
{ domain = "@audio"; item = "nofile"; type = "hard"; value = "99999"; }
];
services.udev = {
packages =
if cfg.ffado.enable
then [ pkgs.ffado ]
else [];
extraRules = ''
KERNEL=="rtc0", GROUP="audio"
KERNEL=="hpet", GROUP="audio"
'';
};
users.extraGroups= { audio = {}; };
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment