Split up code to support server configuration

This commit is contained in:
Jan-Bulthuis 2025-04-16 13:54:14 +02:00
parent 6364d8afa0
commit fa2413f272
15 changed files with 524 additions and 256 deletions

View File

@ -72,6 +72,12 @@
configuration = ./users/jan.nix;
};
};
"vm-audio" = mkConfig "x86_64-linux" ./machines/vm-audio.nix {
jan = {
sudo = true;
configuration = ./users/server.nix;
};
};
};
lib = import ./shell-modules/default.nix self.inputs;
};

View File

@ -15,7 +15,7 @@
# Enabled modules
modules = {
base.enable = true;
base.desktop.enable = true;
bluetooth.enable = true;
power-saving.enable = false;
networkmanager.enable = true;

55
machines/vm-audio.nix Normal file
View File

@ -0,0 +1,55 @@
{ lib, ... }:
{
imports = [
# Import environment
./vm-base.nix
];
config = {
# Machine hostname
networking.hostName = "vm-audio";
# Enabled modules
modules = {
};
# Hardware configuration
hardware.enableRedistributableFirmware = true;
boot.initrd.availableKernelModules = [
"ata_piix"
"uhci_hcd"
"virtio_pci"
"virtio_scsi"
"sd_mod"
"sr_mod"
];
boot.initrd.kernelModules = [ ];
boot.kernelModules = [ "kvm-intel" ];
boot.extraModulePackages = [ ];
hardware.cpu.intel.updateMicrocode = true;
# Filesystems
fileSystems."/" = {
device = "/dev/disk/by-partlabel/root";
fsType = "ext4";
};
fileSystems."/boot" = {
device = "/dev/disk/by-partlabel/EFI";
fsType = "vfat";
options = [
"fmask=0077"
"dmask=0077"
];
};
# Swapfile
swapDevices = [
{
device = "/var/lib/swapfile";
size = 6 * 1024;
}
];
};
}

60
machines/vm-base.nix Normal file
View File

@ -0,0 +1,60 @@
{ lib, ... }:
{
imports = [
# Import environment
../default.nix
];
config = {
# State version
system.stateVersion = "24.11";
# Machine hostname
networking.hostName = lib.mkDefault "vm-base";
# Enabled modules
modules = {
base.enable = true;
ssh.enable = true;
};
# Hardware configuration
hardware.enableRedistributableFirmware = true;
boot.initrd.availableKernelModules = [
"ata_piix"
"uhci_hcd"
"virtio_pci"
"virtio_scsi"
"sd_mod"
"sr_mod"
];
boot.initrd.kernelModules = [ ];
boot.kernelModules = [ "kvm-intel" ];
boot.extraModulePackages = [ ];
hardware.cpu.intel.updateMicrocode = true;
# Filesystems
fileSystems."/" = {
device = "/dev/disk/by-partlabel/root";
fsType = "ext4";
};
fileSystems."/boot" = {
device = "/dev/disk/by-partlabel/EFI";
fsType = "vfat";
options = [
"fmask=0077"
"dmask=0077"
];
};
# Swapfile
swapDevices = [
{
device = "/var/lib/swapfile";
size = 6 * 1024;
}
];
};
}

View File

@ -27,42 +27,13 @@ in
pciutils
zip
unzip
# TODO: MOVE
quickemu # TODO: Reenable once building this is fixed
pdftk
# TODO: Move to USB module
# usbutils
# udiskie
# udisks
brightnessctl
];
security.krb5 = {
enable = true;
settings = {
libdefaults = {
rdns = false;
};
realms = {
"GEWISWG.GEWIS.NL" = {
kdc = [
"https://gewisvdesktop.gewis.nl/KdcProxy"
];
};
};
};
};
modules = {
# Enable base modules
clean-tmp.enable = true;
fontconfig.enable = true;
neovim.enable = true;
systemd-boot.enable = true;
nixgreety.enable = true;
pipewire.enable = true;
};
# TODO: Remove everything below, it is here out of convenience and should be elsewhere
@ -75,34 +46,9 @@ in
enable = true;
};
networking.firewall.enable = true;
programs.dconf.enable = true;
services.libinput.enable = true;
services.upower.enable = true; # For battery percentage in gnome
modules.unfree.enable = true;
modules.unfree.allowedPackages = [
"nvidia-x11"
"nvidia-settings"
];
nix.settings.experimental-features = "nix-command flakes";
# networking.useDHCP = true;
nixpkgs.hostPlatform = "x86_64-linux";
networking.firewall.allowedTCPPortRanges = [
{
from = 10000;
to = 11000;
}
];
networking.firewall.allowedUDPPortRanges = [
{
from = 10000;
to = 11000;
}
];
security.rtkit.enable = true;
# TODO: Move to USB module
# services.gvfs.enable = true;
services.udisks2.enable = true;
console.packages = [
pkgs.dina-psfu

81
modules/base/desktop.nix Normal file
View File

@ -0,0 +1,81 @@
{
lib,
config,
pkgs,
...
}:
with lib;
let
cfg = config.modules.base.desktop;
in
{
options.modules.base.desktop = {
enable = mkEnableOption "desktop";
};
config = mkIf cfg.enable {
environment.systemPackages = with pkgs; [
# TODO: MOVE
quickemu # TODO: Reenable once building this is fixed
pdftk
# TODO: Move to USB module
# usbutils
# udiskie
# udisks
brightnessctl
];
# Move to Realm module
security.krb5 = {
enable = true;
settings = {
libdefaults = {
rdns = false;
};
realms = {
"GEWISWG.GEWIS.NL" = {
kdc = [
"https://gewisvdesktop.gewis.nl/KdcProxy"
];
};
};
};
};
modules = {
# Enable base modules
base.enable = true;
fontconfig.enable = true;
nixgreety.enable = true;
pipewire.enable = true;
graphics.enable = true;
};
programs.dconf.enable = true;
services.libinput.enable = true;
services.upower.enable = true; # For battery percentage in gnome
modules.unfree.allowedPackages = [
"nvidia-x11"
"nvidia-settings"
];
networking.firewall.allowedTCPPortRanges = [
{
from = 10000;
to = 11000;
}
];
networking.firewall.allowedUDPPortRanges = [
{
from = 10000;
to = 11000;
}
];
security.rtkit.enable = true;
# TODO: Move to USB module
# services.gvfs.enable = true;
services.udisks2.enable = true;
};
}

View File

@ -10,6 +10,7 @@ with lib;
imports = [
# Import modules
./base/default.nix
./base/desktop.nix
./bluetooth/default.nix
./boot/clean-tmp.nix
./boot/silent-boot.nix
@ -28,6 +29,7 @@ with lib;
./power-saving/default.nix
./printing/default.nix
./sound/pipewire.nix
./ssh/default.nix
./users/default.nix
./unfree/default.nix
./vpn/tailscale.nix

View File

@ -5,8 +5,15 @@
...
}:
with lib;
let
cfg = config.modules.fontconfig;
in
{
config = {
options.modules.graphics = {
enable = mkEnableOption "graphics";
};
config = mkIf cfg.enable {
# TODO: Modularize further, especially modesetting should be its own module.
# Set up graphics
hardware.graphics.enable32Bit = true;

20
modules/ssh/default.nix Normal file
View File

@ -0,0 +1,20 @@
{
lib,
config,
pkgs,
...
}:
with lib;
let
cfg = config.modules.ssh;
in
{
options.modules.ssh = {
enable = mkEnableOption "ssh";
};
config = mkIf cfg.enable {
services.openssh.enable = true;
};
}

View File

@ -37,7 +37,7 @@ in
};
};
config =
config = mkIf config.desktop.enable (
lib.recursiveUpdate
{
# Ensure desktop related systemd services (xdg) have access to session variables.
@ -84,5 +84,6 @@ in
# }
# ."${cfg.decorations}"
{ }
)
);
}

View File

@ -54,6 +54,7 @@ in
];
options.desktop = {
enable = mkEnableOption "desktop";
name = mkOption {
type = types.str;
default = "Shell";
@ -90,7 +91,7 @@ in
};
};
config = {
config = mkIf cfg.enable {
specialisation = mapAttrs (name: value: {
configuration = (environmentBuilders."${value.type}" value);
}) cfg.environments;

View File

@ -0,0 +1,156 @@
{
pkgs,
lib,
config,
...
}:
with lib;
let
cfg = config.desktop.theming;
in
{
imports = [
# Import all themes
./themes/catppuccin.nix
./themes/gruvbox.nix
./themes/oxocarbon.nix
./themes/papercolor.nix
./themes/sakura.nix
./themes/nord.nix
];
options.desktop.theming =
let
colors = config.desktop.theming.schemeColors;
in
{
darkMode = mkOption {
type = types.bool;
default = false;
example = true;
description = "Whether the app should use dark mode.";
};
colorScheme = mkOption {
type = types.nullOr types.str;
default = "${pkgs.base16-schemes}/share/themes/catppuccin-mocha.yaml";
description = "Base 16 color scheme to use for styling. See stylix documentation for more information.";
};
schemeColors = mkOption {
type = types.attrsOf types.anything;
default = config.lib.stylix.colors;
description = "Generated colors from scheme";
};
colors = {
bg = mkOption {
type = types.str;
default = colors.base00;
};
fg = mkOption {
type = types.str;
default = colors.base05;
};
bg-status = mkOption {
type = types.str;
default = colors.base01;
};
fg-status = mkOption {
type = types.str;
default = colors.base04;
};
bg-selection = mkOption {
type = types.str;
default = colors.base02;
};
bg-highlight = mkOption {
type = types.str;
default = colors.base03;
};
fg-search = mkOption {
type = types.str;
default = colors.base0A;
};
accent = mkOption {
type = types.str;
default = colors.base0E;
};
border-focused = mkOption {
type = types.str;
default = cfg.colors.fg;
};
border-unfocused = mkOption {
type = types.str;
default = cfg.colors.bg-selection;
};
};
colorsCSS = mkOption {
type = types.lines;
default =
":root {\n"
+ concatStrings (
map (color: " --nix-color-${color.name}: #${color.value};\n") (attrsToList cfg.colors)
)
+ "}\n\n";
description = "Colors as css variables";
};
};
config = {
# Configure gnome theme
dconf.settings = {
"org/gnome/desktop/interface" = {
color-scheme = if cfg.darkMode then "prefer-dark" else "prefer-light";
};
};
# Configure qt theme
qt = {
enable = true;
platformTheme.name = "adwaita";
style.name = if cfg.darkMode then "adwaita-dark" else "adwaita-light";
};
# Configure gtk theme
gtk = {
enable = true;
theme = {
name = if cfg.darkMode then "Adwaita-dark" else "Adwaita-light";
package = pkgs.gnome-themes-extra;
};
};
# TODO: This should just straight up not be here
programs.direnv = {
enable = true;
nix-direnv.enable = true;
};
modules.git.ignores = [
".direnv"
];
# Enable stylix
# TODO: Move to own module
stylix = {
enable = true;
autoEnable = false;
targets = {
foot.enable = true;
nixvim.enable = true;
qutebrowser.enable = true;
vscode = {
enable = true;
profileNames = [ "Default" ];
};
zathura.enable = true;
};
base16Scheme = cfg.colorScheme;
polarity = if cfg.darkMode then "dark" else "light";
};
};
}

View File

@ -91,94 +91,10 @@ in
{
imports = [
./background.nix
# Import all themes
./themes/catppuccin.nix
./themes/gruvbox.nix
./themes/oxocarbon.nix
./themes/papercolor.nix
./themes/sakura.nix
./themes/nord.nix
./colors.nix
];
options.desktop.theming =
let
colors = config.desktop.theming.schemeColors;
in
{
darkMode = mkOption {
type = types.bool;
default = false;
example = true;
description = "Whether the app should use dark mode.";
};
colorScheme = mkOption {
type = types.nullOr types.str;
default = null;
description = "Base 16 color scheme to use for styling. See stylix documentation for more information.";
};
schemeColors = mkOption {
type = types.attrsOf types.anything;
default = config.lib.stylix.colors;
description = "Generated colors from scheme";
};
colors = {
bg = mkOption {
type = types.str;
default = colors.base00;
};
fg = mkOption {
type = types.str;
default = colors.base05;
};
bg-status = mkOption {
type = types.str;
default = colors.base01;
};
fg-status = mkOption {
type = types.str;
default = colors.base04;
};
bg-selection = mkOption {
type = types.str;
default = colors.base02;
};
bg-highlight = mkOption {
type = types.str;
default = colors.base03;
};
fg-search = mkOption {
type = types.str;
default = colors.base0A;
};
accent = mkOption {
type = types.str;
default = colors.base0E;
};
border-focused = mkOption {
type = types.str;
default = cfg.colors.fg;
};
border-unfocused = mkOption {
type = types.str;
default = cfg.colors.bg-selection;
};
};
colorsCSS = mkOption {
type = types.lines;
default =
":root {\n"
+ concatStrings (
map (color: " --nix-color-${color.name}: #${color.value};\n") (attrsToList cfg.colors)
)
+ "}\n\n";
description = "Colors as css variables";
};
options.desktop.theming = {
layout = {
borderRadius = mkOption {
type = types.int;
@ -250,27 +166,13 @@ in
};
};
config = {
config = mkIf config.desktop.enable {
# Enable fontconfig
modules.fontconfig.enable = true;
# Install configured fonts
home.packages = fontPackageList;
# Configure gnome theme
dconf.settings = {
"org/gnome/desktop/interface" = {
color-scheme = if cfg.darkMode then "prefer-dark" else "prefer-light";
};
};
# Configure qt theme
qt = {
enable = true;
platformTheme.name = "adwaita";
style.name = if cfg.darkMode then "adwaita-dark" else "adwaita-light";
};
# Configure gtk theme
gtk =
let
@ -287,26 +189,11 @@ in
in
{
enable = true;
theme = {
name = if cfg.darkMode then "Adwaita-dark" else "Adwaita-light";
package = pkgs.gnome-themes-extra;
};
# TODO: Toggles
gtk3.extraCss = disableCSD;
gtk4.extraCss = disableCSD;
};
# TODO: This should just straight up not be here
programs.direnv = {
enable = true;
nix-direnv.enable = true;
};
modules.git.ignores = [
".direnv"
];
# TODO: Make cursors configurable using modules.
home.pointerCursor = {
gtk.enable = true;
@ -322,23 +209,6 @@ in
# Enable stylix
# TODO: Move to own module
stylix = {
enable = true;
autoEnable = false;
targets = {
foot.enable = true;
nixvim.enable = true;
qutebrowser.enable = true;
vscode = {
enable = true;
profileNames = [ "NixOS" ];
};
zathura.enable = true;
};
base16Scheme = cfg.colorScheme;
polarity = if cfg.darkMode then "dark" else "light";
fonts = {
serif = getAttrs [
"name"

View File

@ -27,6 +27,7 @@
];
# desktop.development = "river-light";
desktop.enable = true;
desktop.environments = {
river-dark = {
name = "River Dark";

62
users/server.nix Normal file
View File

@ -0,0 +1,62 @@
# How Jan likes his linux to be configured on servers
{
pkgs,
...
}:
{
config = {
# State version
home.stateVersion = "24.11";
# TODO: Move into modules
home.packages = with pkgs; [
libreoffice-still
remmina
pinentry
thunderbird
signal-desktop
prusa-slicer
freecad-wayland
inkscape
ente-auth
bitwarden
];
# Enabled modules
modules = {
# Tools
git = {
enable = true;
user = "Jan-Bulthuis";
email = "git@bulthuis.dev";
# TODO: Move
ignores = [
".envrc"
".direnv"
"flake.nix"
"flake.lock"
];
};
btop.enable = true;
fish.enable = true;
keyring.enable = true;
scripts.enable = true;
# Development
neovim.enable = true;
# Languages
haskell.enable = false;
js.enable = true;
nix.enable = true;
rust.enable = true;
python.enable = true;
cpp.enable = true;
# Enable unfree
unfree.enable = true;
};
};
}