refactor: make the whole thing more generic

This commit is contained in:
2024-04-02 16:28:57 +02:00
parent 7b648e1955
commit 651f3ad808
193 changed files with 763 additions and 521 deletions

9
modules/nixos/README.md Normal file
View File

@@ -0,0 +1,9 @@
# NixOS Modules
This is a collection of modules, built like the NixOS repo that extends it with
either generic features that might be shared between systems or simplifications
of things that might otherwise lead to duplicate code.
All of these should be more or less ready to copy yourself.
Any modules that are just presets are used with `original.option.preset.name.enable = true;`

View File

@@ -0,0 +1,36 @@
{ config, lib, ... }:
with lib;
let cfg = config.boot.quiet;
in {
options.boot.quiet = { enable = mkEnableOption (mdDoc "Clean, quiet boot"); };
config = mkIf cfg.enable {
boot = {
loader = {
timeout = 0;
systemd-boot.consoleMode = "max";
};
kernelParams = [
# Redirect all kernel messages to a console off screen
#"fbcon=vc:2-6"
#"console=tty1"
"video=3840x2160@144"
"splash"
"quiet"
#"rd.udev.log_level=3"
#"rd.systemd.show_status=false"
#"udev.log_priority=3"
#"boot.shell_on_fail"
#"vt.global_cursor_default=0" # no cursor blinking
];
consoleLogLevel = 0;
initrd.verbose = false;
};
};
}

22
modules/nixos/default.nix Normal file
View File

@@ -0,0 +1,22 @@
{ ... }: {
imports = [
./boot/quiet.nix
./desktops/hyprland.nix
./fonts/fira-code.nix
./fonts/noto-sans.nix
./fonts/nerdfonts.nix
./hardware/audio.nix
./hardware/gbmonctl.nix
./hardware/nvidia.nix
./hardware/cc1.nix
./hardware/fv43u.nix
./hardware/virtual-camera.nix
./locales/theaninova.nix
./services/airprint.nix
];
}

View File

@@ -0,0 +1,38 @@
{ config, lib, pkgs, username, ... }:
with lib;
let cfg = config.desktops.hyprland;
in {
options.desktops.hyprland = {
enable = mkEnableOption (mdDoc "Enable a DE based on Hyprland");
};
config = mkIf cfg.enable {
services.getty.autologinUser = "${username}";
services.getty.extraArgs = [ "--noclear" "--noissue" "--nonewline" ];
services.getty.loginOptions = "-p -f -- \\u"; # preserve environment
services.dbus.enable = true;
xdg.portal = {
enable = true;
extraPortals =
[ pkgs.xdg-desktop-portal-gtk pkgs.xdg-desktop-portal-kde ];
};
services.pcscd.enable = true;
# nautilus on non-gnome
services.gvfs.enable = true;
# fix pinentry on non-gnome
services.dbus.packages = with pkgs; [ gcr ];
services.gnome.gnome-online-accounts.enable = true;
services.gnome.evolution-data-server.enable = true;
programs.hyprland.enable = true;
programs.kdeconnect.enable = true;
environment.sessionVariables.NIXOS_OZONE_WL = "1";
};
}

View File

@@ -0,0 +1,50 @@
{ pkgs, lib, config, ... }:
with lib;
let cfg = config.fonts.fira-code;
in {
options.fonts.fira-code = {
enable = mkEnableOption "Enable the preset for Fira Code";
stylisticSets = mkOption {
type = types.listOf types.string;
description = mdDoc
"[Stylistic sets](https://github.com/tonsky/FiraCode/wiki/How-to-enable-stylistic-sets) for Fira Code";
default =
[ "zero" "onum" "ss04" "cv19" "cv23" "ss09" "ss06" "ss07" "ss10" ];
};
default = mkOption {
type = types.bool;
description = "Make Fira Code the default monospace font";
default = false;
};
};
config = mkIf cfg.enable {
fonts = {
packages = with pkgs; [ fira-code ];
nerdfonts.additionalFonts = [ "FiraCode" ];
fontconfig = {
defaultFonts.monospace = mkIf cfg.default [
(if (config.fonts.nerdfonts.enable) then
"Fira Code Nerd Font"
else
"FiraCode")
];
localConf = ''
<match target="font">
<test name="family" compare="contains">
<string>Fira</string>
</test>
<edit name="fontfeatures" mode="append">
${
lib.concatStringsSep " "
(map (set: "<string>${set}</string>") cfg.stylisticSets)
}
</edit>
</match>
'';
};
};
};
}

View File

@@ -0,0 +1,26 @@
{ pkgs, lib, config, ... }:
with lib;
let cfg = config.fonts.nerdfonts;
in {
options.fonts.nerdfonts = {
enable = mkEnableOption "Enable nerdfonts";
additionalFonts = mkOption {
type = types.listOf types.str;
default = [ ];
description = "Additional fonts to include in the nerdfonts package";
};
};
config = mkIf cfg.enable {
fonts = {
packages = with pkgs;
[
(nerdfonts.override {
fonts = [ "NerdFontsSymbolsOnly" ] ++ cfg.additionalFonts;
})
];
};
};
}

View File

@@ -0,0 +1,30 @@
{ pkgs, lib, config, ... }:
with lib;
let cfg = config.fonts.noto-sans;
in {
options.fonts.noto-sans = {
enable = mkEnableOption "Enable the Noto Sans font";
default = mkOption {
type = types.bool;
description = "Make Noto Sans the default sans-serif font";
default = false;
};
};
config = mkIf cfg.enable {
fonts = {
packages = with pkgs; [ noto-fonts noto-fonts-cjk noto-fonts-emoji ];
nerdfonts.additionalFonts = [ "Noto" ];
fontconfig = {
defaultFonts.sansSerif = mkIf cfg.default [
(if (config.fonts.nerdfonts.enable) then
"Noto Sans Nerd Font"
else
"Noto Sans")
];
};
};
};
}

View File

@@ -0,0 +1,22 @@
{ pkgs, lib, config, ... }:
with lib;
let cfg = config.hardware.audio.preset.pipewire;
in {
options.hardware.audio.preset.pipewire = {
enable = mkEnableOption "Enable pipewire with sane defaults";
};
config = mkIf cfg.enable {
hardware.pulseaudio.enable = false;
security.rtkit.enable = true;
services.pipewire = {
enable = true;
alsa.enable = true;
alsa.support32Bit = true;
pulse.enable = true;
jack.enable = true;
};
};
}

View File

@@ -0,0 +1,39 @@
xkb_symbols "cc1-thea"
{
include "us(basic)"
include "level3(ralt_switch)"
key <AE11> {[minus, underscore, at]};
key <AE12> {[equal, question, ssharp]};
key <LatQ> {[q, Q, asterisk]};
key <LatW> {[w, W, 9]};
key <LatE> {[e, E, braceleft]};
key <LatR> {[r, R, 1]};
key <LatT> {[t, T, braceright]};
key <LatY> {[y, Y, bar]};
key <LatU> {[u, U, 5]};
key <LatI> {[i, I, exclam]};
key <LatO> {[o, O, 3]};
key <LatP> {[p, P, greater]};
key <LatA> {[a, A, 0]};
key <LatS> {[s, S, 4]};
key <LatD> {[d, D, parenright]};
key <LatF> {[f, F, 6]};
key <LatG> {[g, G, asciicircum]};
key <LatH> {[h, H, bracketright]};
key <LatJ> {[j, J, percent]};
key <LatK> {[k, K, 7]};
key <LatL> {[l, L, slash]};
key <AC10> {[semicolon, colon, dollar, EuroSign]};
key <AC11> {[apostrophe, quotedbl, ampersand]};
key <LatZ> {[z, Z, dead_diaeresis]};
key <LatX> {[x, X, plus]};
key <LatC> {[c, C, parenleft]};
key <LatV> {[v, V, less]};
key <LatB> {[b, B, 8]};
key <LatN> {[n, N, 2]};
key <LatM> {[m, M, bracketleft, mu]};
key <AB08> {[comma, numbersign, grave]};
key <AB09> {[period, asciitilde, backslash]};
};

View File

@@ -0,0 +1,29 @@
{ pkgs, lib, config, username, ... }:
with lib;
let cfg = config.hardware.cc1;
in {
options.hardware.cc1 = {
enable = mkEnableOption "Enable CC1 optimizations";
layout = mkOption {
type = with lib.types; enum [ "cc1-thea" ];
default = "cc1-thea";
};
};
config = mkIf cfg.enable {
# TODO: per-device layout?
console.useXkbConfig = true;
services.xserver.xkb = {
layout = cfg.layout;
extraLayouts.cc1-thea = {
description = "A CC1 optimized layout";
languages = [ "eng" "ger" ];
symbolsFile = ./${cfg.layout};
};
};
users.users.${username}.extraGroups = [ "dialout" ];
};
}

View File

@@ -0,0 +1,17 @@
{ pkgs, lib, config, username, ... }:
with lib;
let cfg = config.hardware.fv43u;
in {
options.hardware.fv43u = {
enable =
mkEnableOption "Enable optimisations for the Gigabyte FV43U monitor";
};
config = mkIf cfg.enable {
fonts.fontconfig.subpixel.rgba = "bgr";
hardware.gbmonctl.enable = true;
boot.kernelParams = [ "video=3840x2160@144" ];
};
}

View File

@@ -1,18 +1,22 @@
{ pkgs, lib, config, ... }:
with lib;
let cfg = config.hardware.gbmonctl;
in with lib; {
in {
options.hardware.gbmonctl = {
enable = mkOption {
type = types.bool;
default = false;
description = lib.mkDoc ''
description = mkDoc ''
Enables a CLI tool to change monitor settings over USB to the Gigabyte M32U
In theory any Gigabyte Monitor that uses a Realtek HID device (presumably the M28U also uses this) to control it over OSD sidekick should have the same protocol, but this is the only one I own.
'';
};
};
config = lib.mkIf cfg.enable {
config = mkIf cfg.enable {
environment.systemPackages = [ pkgs.gbmonctl ];
services.udev.packages = [ pkgs.gbmonctl ];
};

View File

@@ -0,0 +1,51 @@
{ pkgs, lib, config, ... }:
with lib;
let cfg = config.hardware.nvidia.preset.proprietary;
in {
options.hardware.nvidia.preset.proprietary = {
enable = mkEnableOption
"Enable proprietary NVIDIA driver support with some sane defaults";
};
config = mkIf cfg.enable {
hardware.opengl = {
enable = true;
driSupport = true;
driSupport32Bit = true;
extraPackages = with pkgs; [ libvdpau-va-gl nvidia-vaapi-driver ];
};
services.xserver.videoDrivers = [ "nvidia" ];
boot.kernelParams = [ "nvidia_drm.fbdev=1" ];
boot.kernelModules =
[ "nvidia" "nvidia_modeset" "nvidia_uvm" "nvidia_drm" ];
boot.initrd.kernelModules =
[ "nvidia" "nvidia_modeset" "nvidia_uvm" "nvidia_drm" ];
hardware.nvidia = {
modesetting.enable = true;
# seems to cause crashes on sleep
powerManagement.enable = false;
open = true;
nvidiaSettings = false;
# no idea if this actually does anything...
nvidiaPersistenced = false;
};
environment = {
variables = {
VDPAU_DRIVER = "va_gl";
LIBVA_DRIVER_NAME = "nvidia";
};
systemPackages = with pkgs; [
glxinfo
nvtopPackages.nvidia
libva-utils
vulkan-tools
];
};
};
}

View File

@@ -0,0 +1,22 @@
{ pkgs, lib, config, ... }:
with lib;
let cfg = config.hardware.virtual-camera;
in {
options.hardware.virtual-camera = {
enable = mkEnableOption "Enable the virtual camera";
};
config = mkIf cfg.enable {
boot = {
# Virtual Camera/Mic
kernelModules = [ "v4l2loopback" "snd-aloop" "sg" ];
extraModulePackages = with config.boot.kernelPackages;
[ v4l2loopback.out ];
extraModprobeConfig = ''
options v4l2loopback exclusive_caps=1 card_label="Virtual Camera"
'';
};
};
}

View File

@@ -0,0 +1,32 @@
{ pkgs, lib, config, ... }:
with lib;
let cfg = config.locale.preset.theaninova;
in {
options.locale.preset.theaninova = {
enable = mkEnableOption "Enable the locale preset for Theaninova";
};
config = mkIf cfg.enable {
time.timeZone = "Europe/Berlin";
i18n = {
inputMethod = {
enabled = "ibus";
ibus.engines = [ pkgs.ibus-engines.anthy ];
};
defaultLocale = "en_GB.UTF-8";
extraLocaleSettings = {
LC_ADDRESS = "de_DE.UTF-8";
LC_IDENTIFICATION = "de_DE.UTF-8";
LC_MEASUREMENT = "de_DE.UTF-8";
LC_MONETARY = "de_DE.UTF-8";
LC_NAME = "de_DE.UTF-8";
LC_NUMERIC = "de_DE.UTF-8";
LC_PAPER = "de_DE.UTF-8";
LC_TELEPHONE = "de_DE.UTF-8";
LC_TIME = "de_DE.UTF-8";
};
};
};
}

View File

@@ -0,0 +1,23 @@
{ pkgs, lib, config, ... }:
with lib;
let cfg = config.services.airprint;
in {
options.services.airprint = {
enable = mkEnableOption "Enable printing over the air using sane and avahi";
};
config = mkIf cfg.enable {
hardware.sane = {
enable = true;
extraBackends = [ pkgs.sane-airscan ];
};
services.printing.enable = true;
services.avahi = {
enable = true;
nssmdns4 = true;
openFirewall = true;
};
};
}