Working on modularizing stuff, again

This commit is contained in:
Chris Kruining 2024-07-21 14:03:57 +02:00
parent b698ce3485
commit 9ba5f8fdf0
32 changed files with 1481 additions and 88 deletions

View file

@ -0,0 +1,3 @@
{
ls = "eza -al";
};

View file

@ -0,0 +1,2 @@
{}:
{}

View file

@ -0,0 +1,50 @@
{ config, lib, pkgs, ... }:
{
imports = [ ./hardware-configuration.nix ];
modules = {
themes.active = "everforrest";
networking.networkManager.enable = true;
develop = {
rust.enable = true;
js.enable = true;
dotnet.enable = true;
};
desktop = {
plasma.enable = true;
terminal = {
default = "alacritty";
allacrity.enable = true;
};
editors = {
default = "nano";
nano.enable = true;
};
browsers = {
default = "firefox";
firefox.enable = true;
firefox.privacy.enable = true;
};
};
shell = {
default = "zsh";
toolset = {
git.enable = true;
gnupg.enable = true;
};
};
};
programs.kdeconnect = {
enable = true;
package = pkgs.valent;
};
}

View file

@ -0,0 +1,94 @@
{ config, lib, pkgs, inputs, ... }:
{
imports = [
./hardware-configuration.nix
../../modules/system/boot.nix
../../modules/system/networking.nix
../../modules/system/audio.nix
../../modules/system/zsa_voyager.nix
../../modules/desktop/plasma.nix
../../modules/programs/security.nix
../../modules/programs/theme.nix
../../modules/programs/shell.nix
../../modules/programs/gaming.nix
../../modules/programs/harden.nix
../../modules/programs/communication.nix
../../modules/programs/office.nix
inputs.home-manager.nixosModules.default
];
nixpkgs.config = {
allowUnfree = true;
};
nix.settings.experimental-features = [ "nix-command" "flakes" ];
# Define a user account. Don't forget to set a password with passwd.
users.users.chris = {
isNormalUser = true;
extraGroups = [ "wheel" "audio" ]; # Enable sudo for the user.
packages = with pkgs; [];
};
home-manager = {
useGlobalPkgs = true;
useUserPackages = true;
extraSpecialArgs = { inherit inputs; };
backupFileExtension = "backup";
users = {
chris.imports = [ ../../users/chris.nix ];
# root.imports = [ ../../users/root.nix ];
};
};
environment.systemPackages = with pkgs; [
neovim
wget
# chromium
thunderbird
zoxide
atuin
btop
dust
bat
tldr
eza
nextcloud-client
];
systemd.services.numLockOnTty = {
wantedBy = [ "multi-user.target" ];
serviceConfig = {
ExecStart = lib.mkForce (pkgs.writeShellScript "numLockOnTty" ''
for tty in /dev/tty{1..6}; do
${pkgs.kbd}/bin/setleds -D +num < "$tty";
done
'');
};
};
# This option defines the first version of NixOS you have installed on this particular machine,
# and is used to maintain compatibility with application data (e.g. databases) created on older NixOS versions.
#
# Most users should NEVER change this value after the initial install, for any reason,
# even if you've upgraded your system to a new NixOS release.
#
# This value does NOT affect the Nixpkgs version your packages and OS are pulled from,
# so changing it will NOT upgrade your system.
#
# This value being lower than the current NixOS release does NOT mean your system is
# out of date, out of support, or vulnerable.
#
# Do NOT change this value unless you have manually inspected all the changes it would make to your configuration,
# and migrated your data accordingly.
#
# For more information, see `man configuration.nix` or https://nixos.org/manual/nixos/stable/options#opt-system.stateVersion .
system.stateVersion = "23.11"; # Did you read the comment?
}

View file

@ -0,0 +1,40 @@
# 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, modulesPath, ... }:
{
imports =
[ (modulesPath + "/installer/scan/not-detected.nix")
];
boot.initrd.availableKernelModules = [ "xhci_pci" "ahci" "usb_storage" "usbhid" "sd_mod" ];
boot.initrd.kernelModules = [ ];
boot.kernelModules = [ "kvm-intel" ];
boot.extraModulePackages = [ ];
fileSystems."/" =
{ device = "/dev/disk/by-uuid/8c4eaf57-fdb2-4c4c-bcc0-74e85a1c7985";
fsType = "ext4";
};
fileSystems."/boot" =
{ device = "/dev/disk/by-uuid/C842-316A";
fsType = "vfat";
options = [ "fmask=0022" "dmask=0022" ];
};
swapDevices =
[ { device = "/dev/disk/by-uuid/0ddf001a-5679-482e-b254-04a1b9094794"; }
];
# Enables DHCP on each ethernet and wireless interface. In case of scripted networking
# (the default) this is the recommended approach. When using systemd-networkd it's
# still possible to use this option, but it's recommended to use it in conjunction
# with explicit per-interface declarations with `networking.interfaces.<interface>.useDHCP`.
networking.useDHCP = lib.mkDefault true;
# networking.interfaces.enp0s31f6.useDHCP = lib.mkDefault true;
nixpkgs.hostPlatform = lib.mkDefault "x86_64-linux";
hardware.cpu.intel.updateMicrocode = lib.mkDefault config.hardware.enableRedistributableFirmware;
}

View file

@ -0,0 +1,2 @@
{}:
{}

8
lib/options.nix Normal file
View file

@ -0,0 +1,8 @@
{lib, ...}: let
inherit (lib.options) mkOption;
in {
mkOpt = type: default: mkOption {inherit type default;};
mkOpt' = type: default: description:
mkOption {inherit type default description;};
}

View file

@ -0,0 +1,16 @@
{ config, options, lib, pkgs, ... }:
let
inherit (lib.modules) mkIf;
in
{
options.modules.develop = let
inherit (lib.options) mkEnableOption;
in
{
xdg.enable = mkEnableOption "XDG-related conf" // { default = true; };
};
config = mkIf conf.modules.develop.xdg.enable {
};
}

36
modules/develop/rust.nix Normal file
View file

@ -0,0 +1,36 @@
{ config, options, lib, pkgs, ... }:
let
inherit (lib.attrsets) attrValues;
inherit (lib.modules) mkIf mkMerge;
inherit (lib.meta) getExe;
in
{
options.modules.develop.rust = let
inherit (lib.options) mkEnableOption;
in {
enable = mkEnableOption "Rust developmnt";
};
config = mkMerge [
(mkIf config.modules.develop.rust.enable (
nixpkgs.overlays = [ inputs.rust.overlays.default ];
user.packages = attrValues {
rust-package = pkgs.rust-bin.nightly.latest.default;
inherit (pkgs) rust-analyser rust-script;
};
environment.shellAlliases = {
rs = "rustc";
ca = "cargo";
};
))
(mkIf config.modules.develop.cdg.enable {
env = {
CARGO_HOME = "$XDG_DATA_HOME/cargo";
PATH = [ "$CARGO_HOME/bin" ];
};
})
];
}

View file

@ -30,18 +30,10 @@
enableCompletion = true;
syntaxHighlighting.enable = true;
shellAliases = {
rebuild = "nixos-rebuild switch --flake /etc/nixos#default";
};
history = {
size = 10000;
path = "${config.xdg.dataHome}/zsh/history";
};
envExtra = ''
export SOME_ZSH_VARIABLE="something"
'';
oh-my-zsh = {
enable = true;

View file

@ -0,0 +1,33 @@
{
config,
options,
lib,
pkgs,
...
}: let
inherit (lib.meta) getExe;
inherit (lib.modules) mkDefault mkIf mkMerge;
cfg = config.modules.networking;
in {
options.modules.networking = let
inherit (lib.options) mkEnableOption;
in {
enable = mkEnableOption "network manager";
};
config =mkIf cfg.networkManager.enable {
systemd.services.NetworkManager-wait-online.enable = false;
networking = {
firewall.enable = true;
networkmanager = {
enable = mkDefault true;
wifi.backend = "wpa_supplicant";
};
};
hm.services.network-manager-applet.enable = true;
};
}

View file

@ -0,0 +1,71 @@
{ pkgs, options, config, lib, ... }:
let
inherit (builtins) getEnv;
inherit (lib.modules) mkIf mkMerge;
in
{
options.modules.networking.samba = let
inherit (lib.options) mkEnableOption;
in {
sharing.enable = mkEnableOption "Samba: enable NixOs -> external file-transfer";
receicing.enable = mkEnableOption "Samba: enable external -> NixOs file-transfer";
};
config = mkMerge [
(mkIf config.modules.networking.samba.sharing.enable {
users = {
group.samba-guest = {};
users.samba-guest = {
isSystemUser = true;
description = "Residence of our Samba guest users";
group = "samba-guest";
home = "/var/empty";
createHome = false;
shell = pkgs.shadow;
};
};
user.extraGroups = [ "samba-guest" ];
networking.firewall = {
allowPing = true;
allowedTCPPorts = [ 5327 ];
allowedUDPPorts = [ 3702 ];
};
services.samba-wsdd.enable = true;
services.samba = {
enable = true;
openFirewall = true;
extraConfig = ''
server string = ${config.networking.hostName}
netbios name = ${config.networking.hostName}
workgroup = WORKGROUP
security = user
create mask 0664
force create mode 0664
directory mask 0775
force directory mode 0775
follow symlink = yes
hosts allow = 192.168.1.0/24 localhost
hosts deny = 0.0.0.0/0
guest account = nobody
map to guest = bad user
'';
shares = {
Public = {
path = (getEnv "HOME") + "/Public";
browseable = "yes";
"read only" = "yes";
"guest ok" = "yes";
"forse user" = "${config.user.name}";
"force group" = "samba-guest";
"write list" = "${config.user.name}";
};
};
};
})
];
}

34
modules/options.nix Normal file
View file

@ -0,0 +1,34 @@
{ config, options, lib, pkgs, ... }:
let
inherit (builtins) elem isList pathExists toString;
inherit (lib.attrsets) mapAttrs mapAttrsToList;
inherit (lib.lists) findFirst;
inherit (lib.modules) mkAliasDefinitions;
inherit (lib.strings) concatMapStringsSep concatStringsSep;
inherit (lib.my) mkOpt mkOpt';
in
{
options = let
inherit (lib.options) mkOption;
inherit (lib.types) attrs attrsOf either listOf oneOf path str;
in
{
user = mkOpt attrs {};
kaas = {
dir = mkOpt path (findFirst pathExists (toString ../.) [
"${config.user.home}/Workspace/public/kaas"
"/etc/kaas"
]);
hostDir = mkOpt path "${config.kaas.dir}/hosts/${config.networking.hostName}";
binDir = mkOpt path "${config.kaas.dir}/bin";
configDir = mkOpt path "${config.kaas.dir}/config";
modulesDir = mkOpt path "${config.kaas.dir}/modules";
themesDir = mkOpt path "${config.kaas.modulesDir}/themes";
};
home = {
# HIER BEN IK GEBLEVEN!!!
};
};
}

View file

@ -1,19 +1,16 @@
{ pkgs, config, ... }:
{
let
inherit (lib.modules) mkIf;
in
{
options.modules.programs.communication = let
inherit (lib.options) mkEnableOption;
in {
enable = mkEnableOption "Discord and Teamspeak";
};
environment.systemPackages = with pkgs; [
discord
webcord
teamspeak_client
];
# config.xdg.desktopEntries.discord = {
# name = "Discord";
# genericName = "All-in-one cross-platform voice and text chat for gamers";
# exec = "Discord --in-process-gpu --use-gl=desktop";
# icon = "Discord";
# categories = [ "Network" "InstantMessaging" ];
# settings = {
# version = "1.4";
# };
# };
}

View file

@ -0,0 +1,15 @@
{ pkgs, config, ... }:
let
inherit (lib.modules) mkIf;
in
{
options.modules.programs = let
inherit (lib.options) mkEnableOption;
in {
enable = mkEnableOption "Rust developmnt";
};
config = mkIf conf.modules.programs.enable {
};
}

View file

@ -1,50 +1,5 @@
{ config, pkgs, ... }:
{
hardware.opengl = {
enable = true;
driSupport = true;
driSupport32Bit = true;
};
# Nvidia
services.xserver.videoDrivers = [ "nvidia" ];
hardware.nvidia = {
modesetting.enable = true;
open = false;
nvidiaSettings = true;
powerManagement = {
enable = true;
finegrained = false;
};
package = let
rcu_patch = pkgs.fetchpatch {
url = "https://github.com/gentoo/gentoo/raw/c64caf53/x11-drivers/nvidia-drivers/files/nvidia-drivers-470.223.02-gpl-pfn_valid.patch";
hash = "sha256-eZiQQp2S/asE7MfGvfe6dA/kdCvek9SYa/FFGp24dVg=";
};
in config.boot.kernelPackages.nvidiaPackages.mkDriver {
version = "535.154.05";
sha256_64bit = "sha256-fpUGXKprgt6SYRDxSCemGXLrEsIA6GOinp+0eGbqqJg=";
sha256_aarch64 = "sha256-G0/GiObf/BZMkzzET8HQjdIcvCSqB1uhsinro2HLK9k=";
openSha256 = "sha256-wvRdHguGLxS0mR06P5Qi++pDJBCF8pJ8hr4T8O6TJIo=";
settingsSha256 = "sha256-9wqoDEWY4I7weWW05F4igj1Gj9wjHsREFMztfEmqm10=";
persistencedSha256 = "sha256-d0Q3Lk80JqkS1B54Mahu2yY/WocOqFFbZVBh+ToGhaE=";
patches = [ rcu_patch ];
};
#prime = {
# sync.enable = true;
# Integrated
# interBusId = "PCI:0:0:0";
# Dedicated
# nvidiaBusId = "PCI:2:0:0";
#};
};
# Steam
programs.steam = {
enable = true;

View file

@ -21,15 +21,11 @@ in
];
users = {
groups = {
${group} = {};
};
users = {
${user} = {
isSystemUser = true;
group = group;
}
users."${user}" = {
isSystemUser = true;
group = group;
};
groups."${group}" = {};
};
system.activationScripts.var = mkForce ''

19
modules/services/auth.nix Normal file
View file

@ -0,0 +1,19 @@
{ config, options, lib, pkgs, ... }:
let
inherit (lib.modules) mkIf;
in
{
options.modules.services.auth = let
inherit (lib.options) mkEnableOption;
in {
enable = mkEnableOption "Media auth";
};
config = mkMerge [
(mkIf config.modules.services.auth.enable (
environment.systemPackages = with pkgs; [
authelia
];
))
];
}

View file

@ -0,0 +1,11 @@
{ pkgs, config, ... }:
let
inherit (lib.modules) mkIf;
in
{
options.modules.services = let
inherit (lib.options) mkEnableOption;
in {
enable = mkEnableOption "Enable all services";
};
}

140
modules/services/media.nix Normal file
View file

@ -0,0 +1,140 @@
{ config, options, lib, pkgs, ... }:
let
inherit (lib.attrsets) attrValues;
inherit (lib.modules) mkIf mkMerge mkForce;
inherit (lib.meta) getExe;
user = "media";
group = "media";
directory = "/var/media";
in
{
options.modules.services.media = let
inherit (lib.options) mkEnableOption;
in {
enable = mkEnableOption "Media tools";
};
config = mkIf config.modules.services.media.enable {
environment.systemPackages = with pkgs; [
podman-tui
jellyfin
jellyseerr
mediainfo
];
users = {
users."${user}" = {
isSystemUser = true;
group = group;
};
groups."${group}" = {};
};
system.activationScripts.var = mkForce ''
install -d -m 0755 -o ${user} -g ${group} ${directory}/series
install -d -m 0755 -o ${user} -g ${group} ${directory}/movies
install -d -m 0755 -o ${user} -g ${group} ${directory}/qbittorrent
install -d -m 0755 -o ${user} -g ${group} ${directory}/sabnzbd
install -d -m 0755 -o ${user} -g ${group} ${directory}/reiverr/config
install -d -m 0755 -o ${user} -g ${group} ${directory}/downloads/incomplete
install -d -m 0755 -o ${user} -g ${group} ${directory}/downloads/done
'';
services = let
serviceConf = {
enable = true;
openFirewall = true;
user = user;
group = group;
};
in {
jellyfin = serviceConf;
radarr = serviceConf;
sonarr = serviceConf;
bazarr = serviceConf;
lidarr = serviceConf;
jellyseerr = {
enable = true;
openFirewall = true;
};
prowlarr = {
enable = true;
openFirewall = true;
};
qbittorrent = {
enable = true;
openFirewall = true;
dataDir = "${directory}/qbittorrent";
port = 5000;
user = user;
group = group;
};
sabnzbd = {
enable = true;
openFirewall = true;
configFile = "${directory}/sabnzbd/config.ini";
port = 5001;
user = user;
group = group;
};
caddy = {
enable = true;
virtualHosts = {
"media.kruining.eu".extraConfig = ''
reverse_proxy http://127.0.0.1:9494
'';
"series.kruining.eu".extraConfig = ''
reverse_proxy http://127.0.0.1:8989
'';
"movies.kruining.eu".extraConfig = ''
reverse_proxy http://127.0.0.1:7878
'';
"jellyfin.kruining.eu".extraConfig = ''
reverse_proxy http://127.0.0.1:8096
'';
"cloud.kruining.eu".extraConfig = ''
php_fastcgi unix//run/phpfpm/nextcloud.sock {
env front_controller_active true
}
'';
};
};
};
modules.virtualisation = {
enable = true;
podman.enable = true;
};
virtualisation = {
oci-containers = {
backend = "podman";
containers = {
flaresolverr = {
image = "flaresolverr/flaresolverr";
autoStart = true;
ports = [ "127.0.0.1:8191:8191" ];
};
reiverr = {
image = "ghcr.io/aleksilassila/reiverr:v2.0.0-alpha.6";
autoStart = true;
ports = [ "127.0.0.1:9494:9494" ];
volumes = [ "${directory}/reiverr/config:/config" ];
};
};
};
};
systemd.services.jellyfin.serviceConfig.killSignal = lib.mkForce "SIGKILL";
};
}

48
modules/shell/default.nix Normal file
View file

@ -0,0 +1,48 @@
{ options, config, lib, pkgs, ... }:
let
inherit (lib.attrsets) attrValues;
inherit (lib.modules) mkIf mkMerge;
cfg = config.modules.shell;
in
{
options.modules.shell = let
inherit (lib.options) mkOption mkEnableOption;
inherit (lib.types) nullOr enum;
in {
default = mkOption {
type = nullOr (enum ["fish" "zsh" "xonsh"]);
default = null;
description = "Default system shell";
};
corePkgs.enable = mkEnableOption "core shell packages";
};
config = mkMerge [
(mkIf (cfg.default != null) {
users.defaultUserShell = pkgs."${cfg.default}";
})
(mkIf cfg.corePkgs.enable {
modules.shell.toolset = {
btop.enable = true;
fzf.enable = true;
starship.enable = true;
tmux.enable = true;
};
hm.programs.direnv = {
enable = true;
nix-direnv.enable = true;
config.whitelist.prefix = ["/home"];
};
user.packages = attrValues {
inherit (pkgs) any-nix-shell pwgen yt-dlp ripdrag yazi;
inherit (pkgs) bat fd zoxide;
rgFull = pkgs.ripgrep.override {withPCRE2 = true;};
};
})
];
}

View file

@ -0,0 +1,146 @@
{ config, options, lib, pkgs, ... }:
let
inherit (lib.modules) mkIf;
inherit (lib.strings) concatStringsSep;
in
{
options.modules.shell.toolset.btop = let
inherit (lib.options) mkEnableOption;
in { enable = mkEnableOption "system-monitor"; };
config = mkIf config.modules.shell.toolset.btop.enable {
hm.programs.btop = let
inherit (config.modules.themes) active;
in
{
enable = true;
settings = {
force_tty = false;
vim_keys = true; # Directional keys: "h,j,k,l,g,G"
update_ms = 1500; # ms (s^{-3})
temp_scale = "celsius";
base_10_sizes = false;
show_cpu_freq = true;
clock_format = "%H:%M";
background_update = true;
disks_filter = "exclude=/boot";
color_theme = "${active}";
rounded_corners = true;
theme_background = false;
truecolor = true;
presets = concatStringsSep "," [
"cpu:1:default"
"proc:0:default cpu:0:default"
"mem:0:default"
"net:0:default cpu:0:block"
"net:0:tty"
];
graph_symbol = "braille";
graph_symbol_cpu = "default";
graph_symbol_mem = "default";
graph_symbol_net = "default";
graph_symbol_proc = "default";
shown_boxes = "proc cpu mem net";
proc_sorting = "cpu lazy";
proc_reversed = false;
proc_tree = false;
proc_colors = true;
proc_gradient = true;
proc_per_core = true;
proc_mem_bytes = true;
proc_info_smaps = false;
proc_left = false;
cpu_graph_upper = "total";
cpu_graph_lower = "total";
cpu_single_graph = false;
cpu_bottom = false;
show_uptime = true;
check_temp = true;
cpu_sensor = "Auto";
show_coretemp = true;
cpu_core_map = "";
custom_cpu_name = "";
mem_graphs = true;
mem_below_net = false;
show_swap = true;
swap_disk = true;
show_disks = true;
only_physical = true;
use_fstab = false; # Enable -> disables `only_physical`
disk_free_priv = false;
show_io_stat = true;
io_mode = false;
io_graph_combined = false;
io_graph_speeds = "";
net_download = 100;
net_upload = 100;
net_auto = true;
net_sync = false;
net_iface = "br0";
show_battery = true;
selected_battery = "Auto";
log_level = "DEBUG";
};
};
home.configFile.btop-theme = let
inherit (config.modules.themes) active;
in
mkIf (active != null) {
target = "btop/themes/${active}.theme";
text = let
inherit (config.modules.themes.colors.main) bright types;
in ''
theme[main_bg]="${types.bg}"
theme[main_fg]="${types.fg}"
theme[title]="${types.fg}"
theme[hi_fg]="${types.highlight}"
theme[selected_bg]="${types.border}"
theme[selected_fg]="${types.bg}"
theme[inactive_fg]="${bright.black}"
theme[graph_text]="${bright.yellow}"
theme[meter_bg]="${bright.black}"
theme[proc_misc]="${bright.yellow}"
theme[cpu_box]="${bright.cyan}"
theme[mem_box]="${bright.green}"
theme[net_box]="${bright.magenta}"
theme[proc_box]="${bright.yellow}"
theme[div_line]="${bright.black}"
theme[temp_start]="${bright.yellow}"
theme[temp_mid]="${types.panelbg}"
theme[temp_end]="${bright.red}"
theme[cpu_start]="${bright.cyan}"
theme[cpu_mid]="${types.border}"
theme[cpu_end]="${bright.green}"
theme[free_start]="${bright.green}"
theme[free_mid]="${bright.green}"
theme[free_end]="${bright.green}"
theme[cached_start]="${bright.yellow}"
theme[cached_mid]="${bright.yellow}"
theme[cached_end]="${bright.magenta}"
theme[available_start]="${bright.yellow}"
theme[available_mid]="${bright.yellow}"
theme[available_end]="${bright.yellow}"
theme[used_start]="${types.panelbg}"
theme[used_mid]="${types.panelbg}"
theme[used_end]="${bright.red}"
theme[download_start]="${bright.blue}"
theme[download_mid]="${bright.blue}"
theme[download_end]="${bright.magenta}"
theme[upload_start]="${bright.blue}"
theme[upload_mid]="${bright.blue}"
theme[upload_end]="${bright.magenta}"
theme[process_start]="${bright.cyan}"
theme[process_mid]="${types.border}"
theme[process_end]="${bright.green}"
'';
};
};
}

View file

@ -0,0 +1,53 @@
{ config, options, lib, pkgs, ... }:
let
inherit (lib.attrsets) optionalAttrs;
inherit (lib.modules) mkIf;
in
{
options.modules.shell.toolset.fzf = let
inherit (lib.options) mkEnableOption;
in { enable = mkEnableOption "TUI Fuzzy Finder."; };
config = mkIf config.modules.shell.toolset.fzf.enable {
hm.programs.fzf = let
defShell = config.modules.shell.default;
in {
enable = true;
enableBashIntegration = true;
enableZshIntegration = defShell == "zsh";
enableFishIntegration = defShell == "fish";
tmux.enableShellIntegration = true;
tmux.shellIntegrationOptions = ["-d 40%"];
defaultCommand = "fd --type f";
defaultOptions = ["--height 40%" "--border"];
changeDirWidgetCommand = "fd --type d";
changeDirWidgetOptions = ["--preview 'tree -C {} | head -200'"];
fileWidgetCommand = "fd --type f";
fileWidgetOptions = ["--preview 'head {}'"];
historyWidgetOptions = ["--sort" "--exact"];
colors = let
inherit (config.modules.themes) active;
inherit (config.modules.themes.colors.main) normal types;
in
mkIf (active != null) {
bg = "${types.bg}";
"bg+" = "${types.bg}";
fg = "${types.border}";
"fg+" = "${types.border}";
hl = "${normal.red}";
"hl+" = "${normal.red}";
header = "${normal.red}";
marker = "${normal.magenta}";
info = "${normal.magenta}";
prompt = "${types.border}";
spinner = "${types.panelbg}";
pointer = "${types.border}";
};
};
};
}

View file

@ -0,0 +1,117 @@
{ config, options, lib, pkgs, ... }:
let
inherit (builtins) readFile;
inherit (lib.attrsets) attrValues optionalAttrs;
inherit (lib.modules) mkIf;
in
{
options.modules.shell.toolset.git = let
inherit (lib.options) mkEnableOption;
in { enable = mkEnableOption "version-control system"; };
config = mkIf config.modules.shell.toolset.git.enable {
user.packages = attrValues ({
inherit (pkgs) act dura lazygit;
inherit (pkgs.gitAndTools) gh git-open;
}
// optionalAttrs config.modules.shell.toolset.gnupg.enable {
inherit (pkgs.gitAndTools) git-crypt;
});
# Prevent x11 askPass prompt on git push:
programs.ssh.askPassword = "";
hm.programs.zsh.initExtra = ''
# -------===[ Helpful Git Fn's ]===------- #
gitignore() {
curl -s -o .gitignore https://gitignore.io/api/$1
}
'';
hm.programs.fish.functions = {
gitignore = "curl -sL https://www.gitignore.io/api/$argv";
};
env = {GITHUB_TOKEN = "$(cat /run/agenix/tokenGH)";};
hm.programs.git = {
enable = true;
package = pkgs.gitFull;
difftastic = {
enable = true;
background = "dark";
color = "always";
display = "inline";
};
ignores = [
# General:
"*.bloop"
"*.bsp"
"*.metals"
"*.metals.sbt"
"*metals.sbt"
"*.direnv"
"*.envrc"
"*hie.yaml"
"*.mill-version"
"*.jvmopts"
# OS-related:
".DS_Store?"
".DS_Store"
".CFUserTextEncoding"
".Trash"
".Xauthority"
"thumbs.db"
"Thumbs.db"
"Icon?"
# Compiled residues:
"*.class"
"*.exe"
"*.o"
"*.pyc"
"*.elc"
];
extraConfig = {
init.defaultBranch = "main";
core = {
editor = "nvim";
whitespace = "trailing-space,space-before-tab";
};
credential.helper = "${pkgs.gitFull}/bin/git-credential-libsecret";
user = {
name = "Chris Kruining";
email = "chris@kruining.eu";
signingKey = readFile "${config.user.home}/.ssh/id_ed25519.pub";
};
gpg.format = "ssh";
commit.gpgSign = true;
tag.gpgSign = true;
push = {
default = "current";
gpgSign = "if-asked";
autoSquash = true;
};
pull.rebase = true;
filter = {
required = true;
smudge = "git-lfs smudge -- %f";
process = "git-lfs filter-process";
clean = "git-lfs clean -- %f";
};
url = {
"https://github.com/".insteadOf = "gh:";
"git@github.com:".insteadOf = "ssh+gh:";
};
};
};
};
}

View file

@ -0,0 +1,31 @@
{ config, options, lib, pkgs, ... }:
let
inherit (builtins) getEnv;
inherit (lib.modules) mkIf;
cfg = config.modules.shell.toolset.gnupg;
in
{
options.modules.shell.toolset.gnupg = let
inherit (lib.options) mkEnableOption;
in { enable = mkEnableOption "cryptographic suite"; };
config = mkIf config.modules.shell.toolset.gnupg.enable {
environment.variables.GNUPGHOME = "$XDG_CONFIG_HOME/gnupg";
programs.gnupg.agent = {
enable = true;
enableSSHSupport = true;
pinentryPackage = pkgs.pinentry-gnome3;
settings = let
cacheTTL = 86400;
in {
default-cache-ttl = cacheTTL;
default-cache-ttl-ssh = cacheTTL;
max-cache-ttl = cacheTTL;
max-cache-ttl-ssh = cacheTTL;
};
};
};
}

View file

@ -0,0 +1,85 @@
{ config, options, lib, pkgs, ... }:
let
inherit (lib.modules) mkIf;
in
{
options.modules.shell.toolset.starship = let
inherit (lib.options) mkEnableOption;
in { enable = mkEnableOption "minimal shell ricing"; };
config = mkIf config.modules.shell.toolset.starship.enable {
hm.programs.starship = {
enable = true;
settings = let
inherit (config.modules.themes.colors.main) normal types;
in {
scan_timeout = 10;
add_newline = true;
line_break.disabled = true;
format = "$username$hostname$nix_shell$git_branch$git_commit$git_state$git_status$directory$jobs$cmd_duration$character";
username = {
style_user = "${normal.blue} bold";
style_root = "${normal.red} bold";
format = "[$user]($style) ";
disabled = false;
show_always = true;
};
hostname = {
ssh_only = false;
ssh_symbol = "🌐 ";
format = "on [$hostname](bold ${normal.red}) ";
trim_at = ".local";
disabled = false;
};
nix_shell = {
symbol = " ";
format = "[$symbol$name]($style) ";
style = "${normal.purple} bold";
};
git_branch = {
only_attached = true;
format = "[$symbol$branch]($style) ";
symbol = "";
style = "${normal.yellow} bold";
};
git_commit = {
only_detached = true;
format = "[$hash]($style) ";
style = "${normal.yellow} bold";
};
git_state = {
style = "${normal.purple} bold";
};
git_status = {
style = "${normal.green} bold";
};
directory = {
read_only = " ";
truncation_length = 0;
};
cmd_duration = {
format = "[$duration]($style) ";
style = "${normal.blue}";
};
jobs = {
style = "${normal.green} bold";
};
character = {
success_symbol = "[\\$](${normal.green} bold)";
error_symbol = "[\\$](${normal.red} bold)";
};
};
};
};
}

View file

@ -0,0 +1,126 @@
{ config, options, lib, pkgs, ... }:
let
inherit (lib.modules) mkIf;
in
{
options.modules.shell.toolset.tmux = let
inherit (lib.options) mkEnableOption;
in { enable = mkEnableOption "terminal multiplexer"; };
config = mkIf config.modules.shell.toolset.tmux.enable {
hm.programs.tmux = {
enable = true;
secureSocket = true;
keyMode = "vi";
prefix = "C-a";
terminal = "tmux-256color";
baseIndex = 1;
clock24 = true;
disableConfirmationPrompt = true;
escapeTime = 0;
aggressiveResize = false;
resizeAmount = 2;
reverseSplit = false;
historyLimit = 5000;
newSession = true;
plugins = let
inherit (pkgs.tmuxPlugins) resurrect continuum;
in [
{
plugin = resurrect;
extraConfig = "set -g @resurrect-strategy-nvim 'session'";
}
{
plugin = continuum;
extraConfig = ''
set -g @continuum-restore 'on'
set -g @continuum-save-interval '60' # minutes
'';
}
];
extraConfig = let
inherit (config.modules.themes.colors.main) normal types;
in ''
# -------===[ Color Correction ]===------- #
set-option -ga terminal-overrides ",*256col*:Tc"
set-option -ga terminal-overrides '*:Ss=\E[%p1%d q:Se=\E[ q'
set-environment -g COLORTERM "truecolor"
# -------===[ General-Configurations ]===------- #
set-option -g renumber-windows on
set-window-option -g automatic-rename on
set-window-option -g word-separators ' @"=()[]'
set-option -g mouse on
set-option -s focus-events on
set-option -g renumber-windows on
set-option -g allow-rename off
# -------===[ Activity/Sound ]===------- #
set-option -g bell-action none
set-option -g visual-bell off
set-option -g visual-silence off
set-option -g visual-activity off
set-window-option -g monitor-activity off
# -------===[ Status-Bar ]===------- #
set-option -g status on
set-option -g status-interval 1
set-option -g status-style bg=default,bold,italics
set-option -g status-position top
set-option -g status-justify left
set-option -g status-left-length "40"
set-option -g status-right-length "80"
# Messages:
set-option -g message-style fg="${types.bg}",bg="${types.highlight}",align="centre"
set-option -g message-command-style fg="${types.bg}",bg="${types.highlight}",align="centre"
# Panes:
set-option -g pane-border-style fg="${types.fg}"
set-option -g pane-active-border-style fg="${types.border}"
# Windows:
set-option -g window-status-format "#[fg=${types.fg}] #W/#{window_panes} "
set-option -g window-status-current-format "#{?client_prefix,#[fg=${types.bg}]#[bg=${normal.red}] #I:#W #[fg=${normal.red}]#[bg=default],#[fg=${types.bg}]#[bg=${normal.magenta}] #I:#W #[fg=${normal.magenta}]#[bg=default]}"
# -------===[ Statusline ]===------- #
set-option -g status-left "#[fg=${types.bg}]#[bg=${normal.blue}]#[bold] #[fg=${normal.blue}]#[bg=default]"
set-option -g status-bg default
set-option -g status-right "#[italics] #H | %b %d, %H:%M #[fg=${types.bg},bg=${types.highlight},bold,italics] base-#S "
# -------===[ Clock & Selection ]===------- #
set-window-option -g clock-mode-colour "${types.border}"
set-window-option -g mode-style "fg=${types.bg} bg=${types.highlight} bold"
# -------===[ Keybindings ]===------- #
bind-key c clock-mode
# Window Control(s):
bind-key q kill-session
bind-key Q kill-server
bind-key t new-window -c '#{pane_current_path}'
# Buffers:
bind-key b list-buffers
bind-key p paste-buffer
bind-key P choose-buffer
# Split bindings:
bind-key - split-window -v -c '#{pane_current_path}'
bind-key / split-window -h -c '#{pane_current_path}'
# Copy/Paste bindings:
bind-key -T copy-mode-vi v send-keys -X begin-selection -N "Start visual mode for selection"
bind-key -T copy-mode-vi y send-keys -X copy-selection -N "Yank text into buffer"
bind-key -T copy-mode-vi r send-keys -X rectangle-toggle -N "Yank region into buffer"
'';
};
};
}

149
modules/shell/zsh.nix Normal file
View file

@ -0,0 +1,149 @@
{ config, options, pkgs, lib, ... }:
let
inherit (lib.attrsets) mapAttrsToList;
inherit (lib.modules) mkIf;
inherit (lib.strings) concatStrings escapeNixString;
cfg = config.modules.shell;
in
{
config = mkIf (cfg.default == "zsh") {
modules.shell = {
corePkgs.enable = true;
toolset = {
macchina.enable = true;
starship.enable = true;
};
};
hm.programs.starship.enableZshIntegration = true;
# Enable completion for sys-packages:
environment.pathsToLink = ["/share/zsh"];
programs.zsh.enable = true;
hm.programs.zsh = {
enable = true;
enableCompletion = true;
autosuggestion.enable = true;
syntaxHighlighting.enable = true;
history = {
size = 10000;
path = "${config.xdg.dataHome}/zsh/history";
};
oh-my-zsh = {
enable = true;
plugins = ["git" "docker-compose" "zoxide"];
};
plugins = let
mkZshPlugin = {
pkg,
file ? "${pkg.pname}.plugin.zsh",
}: {
name = pkg.pname;
src = pkg.src;
inherit file;
};
in
with pkgs; [
(mkZshPlugin {pkg = zsh-abbr;})
(mkZshPlugin {pkg = zsh-autopair;})
(mkZshPlugin {pkg = zsh-you-should-use;})
(mkZshPlugin {
pkg = zsh-nix-shell;
file = "nix-shell.plugin.zsh";
})
];
syntaxHighlighting = let
inherit (config.modules.themes) active;
inherit (config.modules.themes.colors.main) normal bright types;
in
mkIf (active != null) {
enable = true;
highlighters = ["main" "brackets" "pattern" "cursor" "regexp" "root" "line"];
patterns = {
"sudo " = "fg=${normal.red},bold";
"rm -rf *" = "fg=${normal.red},bold";
};
styles = {
# -------===[ Comments ]===------- #
comment = "fg=${normal.black}";
# -------===[ Functions/Methods ]===------- #
alias = "fg=${normal.magenta}";
"suffix-alias" = "fg=${normal.magenta}";
"global-alias" = "fg=${normal.magenta}";
function = "fg=${normal.blue}";
command = "fg=${normal.green}";
precommand = "fg=${normal.green},italic";
autodirectory = "fg=${normal.yellow},italic";
"single-hyphen-option" = "fg=${normal.yellow}";
"double-hyphen-option" = "fg=${normal.yellow}";
"back-quoted-argument" = "fg=${normal.magenta}";
# -------===[ Built-ins ]===------- #
builtin = "fg=${normal.blue}";
"reserved-word" = "fg=${normal.green}";
"hashed-command" = "fg=${normal.green}";
# -------===[ Punctuation ]===------- #
commandseparator = "fg=${bright.red}";
"command-substitution-delimiter" = "fg=${types.border}";
"command-substitution-delimiter-unquoted" = "fg=${types.border}";
"process-substitution-delimiter" = "fg=${types.border}";
"back-quoted-argument-delimiter" = "fg=${bright.red}";
"back-double-quoted-argument" = "fg=${bright.red}";
"back-dollar-quoted-argument" = "fg=${bright.red}";
# -------===[ Strings ]===------- #
"command-substitution-quoted" = "fg=${bright.yellow}";
"command-substitution-delimiter-quoted" = "fg=${bright.yellow}";
"single-quoted-argument" = "fg=${bright.yellow}";
"single-quoted-argument-unclosed" = "fg=${normal.red}";
"double-quoted-argument" = "fg=${bright.yellow}";
"double-quoted-argument-unclosed" = "fg=${normal.red}";
"rc-quote" = "fg=${bright.yellow}";
# -------===[ Variables ]===------- #
"dollar-quoted-argument" = "fg=${types.highlight}";
"dollar-quoted-argument-unclosed" = "fg=${bright.red}";
"dollar-double-quoted-argument" = "fg=${types.highlight}";
assign = "fg=${types.highlight}";
"named-fd" = "fg=${types.highlight}";
"numeric-fd" = "fg=${types.highlight}";
# -------===[ Non-Exclusive ]===------- #
"unknown-token" = "fg=${normal.red}";
path = "fg=${types.highlight},underline";
path_pathseparator = "fg=${bright.red},underline";
path_prefix = "fg=${types.highlight},underline";
path_prefix_pathseparator = "fg=${bright.red},underline";
globbing = "fg=${types.highlight}";
"history-expansion" = "fg=${normal.magenta}";
"back-quoted-argument-unclosed" = "fg=${normal.red}";
redirection = "fg=${types.highlight}";
arg0 = "fg=${types.highlight}";
default = "fg=${types.highlight}";
cursor = "fg=${types.highlight}";
};
};
};
home.configFile.zsh-abbreviations = {
target = "zsh/abbreviations";
text = let
abbrevs = import "${config.snowflake.configDir}/shell-abbr";
in ''
${concatStrings (mapAttrsToList
(k: v: "abbr ${k}=${escapeNixString v}")
abbrevs
)}
'';
};
};
}

View file

@ -1,19 +1,66 @@
{ pkgs, ... }:
{ config, options, lib, pkgs, ... }:
let
inherit (lib.attrsets) attrValues;
inherit (lib.modules) mkIf;
cfg = config.modules.hardware.pipewire;
in
{
sound.enable = false;
hardware.pulseaudio.enable = false;
options.modules.hardware.pipewire = let
inherit (lib.options) mkEnableOption;
in
{
enable = mkEnableOption "modern audio support";
};
users.extraGroups.audio.members = [ "chris" ];
security.rtkit.enable = true;
services.pipewire = {
enable = true;
alsa = {
enable = true;
support32Bit = true;
config = mkIf cfg.enable {
user.packages = attrValues {
inherit (pkgs) easyeffects
};
security.rtkit.enable = true;
services.pipewire = {
enable = true;
wireplumber.enable = true;
pulse.enable = true;
# jack.enable = true;
alsa = {
enable = true;
support32Bit = true;
};
};
home.configFile = mkIf config.module.hardware.bluetooth.enable {
wireplumber-bluetooth = {
target = "wireplumber/bluetooth.lua.d/51-bluez-config.lua";
text = ''
bluez_monitor.properties = {
["bluez5.enable-sbc-xq"] = true,
["bluez5.enable-msbc"] = true,
["bluez5.enable-hw-volume"] = true,
["bluez5.headset-roles"] = "[ hsp_hs hsp_ag hfp_hf hfp_ag ]"
}
'';
};
wireplumber-disable-suspension = {
target = "wireplumber/main.lua.d/51-disable-suspension.lua";
text = ''
table.insert(alsa_monitor.rules, {
matches = {
{ -- Matches all sources.
{ "node.name", "matches", "alsa_input.*" },
},
{ -- Matches all sinks.
{ "node.name", "matches", "alsa_output.*" },
},
},
apply_properties = { ["session.suspend-timeout-seconds"] = 0 },
})
'';
};
};
pulse.enable = true;
jack.enable = true;
};
}

View file

@ -0,0 +1,39 @@
{ config, pkgs, ... }:
{
services.xserver.videoDrivers = [ "nvidia" ];
hardware = {
opengl = {
enable = true;
driSupport = true;
driSupport32Bit = true;
};
nvidia = {
modesetting.enable = true;
open = false;
nvidiaSettings = true;
powerManagement = {
enable = true;
finegrained = false;
};
package = let
rcu_patch = pkgs.fetchpatch {
url = "https://github.com/gentoo/gentoo/raw/c64caf53/x11-drivers/nvidia-drivers/files/nvidia-drivers-470.223.02-gpl-pfn_valid.patch";
hash = "sha256-eZiQQp2S/asE7MfGvfe6dA/kdCvek9SYa/FFGp24dVg=";
};
in config.boot.kernelPackages.nvidiaPackages.mkDriver {
version = "535.154.05";
sha256_64bit = "sha256-fpUGXKprgt6SYRDxSCemGXLrEsIA6GOinp+0eGbqqJg=";
sha256_aarch64 = "sha256-G0/GiObf/BZMkzzET8HQjdIcvCSqB1uhsinro2HLK9k=";
openSha256 = "sha256-wvRdHguGLxS0mR06P5Qi++pDJBCF8pJ8hr4T8O6TJIo=";
settingsSha256 = "sha256-9wqoDEWY4I7weWW05F4igj1Gj9wjHsREFMztfEmqm10=";
persistencedSha256 = "sha256-d0Q3Lk80JqkS1B54Mahu2yY/WocOqFFbZVBh+ToGhaE=";
patches = [ rcu_patch ];
};
};
};
}

View file

@ -0,0 +1,12 @@
{ config, options, lib, pkgs, ... }:
let
inherit (lib.modules) mkIf;
in
{
options.modules.virtualization = let
inherit (lib.options) mkEnableOption;
in
{
enable = mkEnableOption "enable virtualization";
};
}

View file

@ -0,0 +1,26 @@
{ config, options, lib, pkgs, ... }:
let
inherit (lib.modules) mkIf;
cfg = config.modules.virtualization.podman;
in
{
options.modules.virtualization.podman = let
inherit (lib.options) mkEnableOption;
in
{
enable = mkEnableOption "enable podman";
};
config = mkIf options.modules.virtualization.podman.enable {
virtualisation = {
containers.enable = true;
podman = {
enable = true;
dockerCompat = true;
defaultNetwork.settings.dns_enabled = true;
};
};
};
}