many improvements

This commit is contained in:
2025-07-17 18:10:37 +02:00
parent 0a731ef17f
commit 82e26ee498
58 changed files with 1970 additions and 1005 deletions

7
modules/nixos/agenix.nix Normal file
View File

@@ -0,0 +1,7 @@
{ config, pkgs, lib, inputs, ... }:
{
# agenix client
environment.systemPackages = [
inputs.agenix.packages."${system}".default
];
}

88
modules/nixos/backup.nix Normal file
View File

@@ -0,0 +1,88 @@
{pkgs, lib, ...}:
let
snapshotsDir = "/snapshots/home";
in
{
environment.systemPackages = with pkgs; [
restic
btrbk
libnotify
];
# btrbk systemd service and timer for daily home snapshots
systemd.services.btrbk-home-snapshot = {
description = "Create daily btrbk snapshot of the home subvolume";
serviceConfig = {
Type = "oneshot";
User = "remy";
ExecStartPre = "${lib.getExe pkgs.libnotify} \"Backup\" \"Creating BTRBK snapshot of /home.\"";
# run the btrbk command as superuser
ExecStart = "+${lib.getExe pkgs.btrbk} -c /etc/btrbk/home.conf run";
Environment = "DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus"; # ensure the notification is sent to the correct display
ExecStartPost = "${lib.getExe pkgs.libnotify} \"Backup\" \"Snapshot of /home created successfully.\"";
};
};
systemd.timers.btrbk-home-snapshot = {
enable = true;
description = "Daily timer for btrbk home snapshot";
wantedBy = [ "timers.target" ];
timerConfig = {
OnCalendar = "*-*-* 12:00";
Persistent = true; # ensures missed runs are triggered after resume
};
};
# ensure the target directory exists
systemd.tmpfiles.settings = {
"btrbk snapshots" = {
"${snapshotsDir}" = {
d = {
group = "root";
user = "root";
mode = "0770";
};
};
};
};
# btrbk config for home snapshots
environment.etc."btrbk/home.conf".text = ''
timestamp_format long
# keep snapshots for 2 days independently of the call
snapshot_preserve_min 2d
# retain daily snapshots for 14 days
snapshot_preserve 14d
subvolume /home
snapshot_dir ${snapshotsDir}
'';
# Now create a restic backup off the newest btrbk snapshot
systemd.services.restic-backup-latest-snapshot = {
description = "Backup home subvolume using restic";
serviceConfig = {
Type = "oneshot";
ExecStart = "${lib.getExe pkgs.restic} -r /home/snapshots/restic-backup backup /home/snapshots/home-$(date +%Y-%m-%d_%H-%M-%S)";
# send a notification when the service is done
ExecStartPost = "su remy -c 'notify-send \"Restic Backup\" \"Home backup created successfully.\"'";
};
};
# # the udev rule:
# services.udev.extraRules = ''
# ACTION=="add", SUBSYSTEM=="block", ENV{ID_FS_LABEL}=="backup-restic", TAG+="systemd", ENV{SYSTEMD_WANTS}="backup-restic.service"
# '';
# # the systemd service:
# systemd.services.backup-restic = {
# description = "Backup using restic (triggered when USB drive is plugged in)";
# after = [ "local-fs.target" ];
# wantedBy = [ "multi-user.target" ];
# serviceConfig = {
# Type = "oneshot";
# # TODO: adapt command
# ExecStart = "${lib.getExe pkgs.restic} backup /home/username";
# };
# };
}

View File

@@ -7,7 +7,23 @@
{
environment.systemPackages = [
pkgs.bluez
# bluez-qt
# gnome.gnome-control-center
pkgs.gnome-bluetooth
];
services.dbus.packages = with pkgs; [
gnome-bluetooth
bluez
];
users.users.remy.extraGroups = [
"networkmanager"
];
hardware.bluetooth = {
enable = true;
# powerOnBoot = true;

View File

@@ -14,7 +14,7 @@ in
# Use hyprland as the main desktop environment but use gdm as desktop manager
programs.hyprland = {
enable = true;
xwayland.enable = false;
xwayland.enable = true;
};
@@ -26,10 +26,23 @@ in
enable = true;
wayland = true;
};
services.gvfs.enable = true;
security.pam.services.hyprlock = {};
security.pam.services.gdm.enableGnomeKeyring = true;
# Enable RTKit for real-time audio processing, ...
# improving audio performance and reducing dropouts.
security.rtkit.enable = true;
# Enable D-Bus for inter-process communication
services.dbus.enable = true;
programs.dconf.enable = true;
};
}

View File

@@ -0,0 +1,11 @@
{ config, pkgs, ... }:
{
# Configure console keymap
console.keyMap = "de";
i18n.defaultLocale = "en_US.UTF-8";
# i18n.supportedLocales = [ "en_US.UTF-8" "de_DE.UTF-8" ];
time.timeZone = "Europe/Berlin";
}

View File

@@ -1,7 +1,35 @@
{lib, ...}:{
networking.networkmanager.enable = true;
networking.networkmanager.wifi.powersave = lib.mkDefault true;
users.users.remy.extraGroups = [
"networkmanager"
];
}
{
lib,
config,
...
}:
let
cfg = config.nix-config.networking;
in
{
options = {
nix-config.networking.hostName = lib.mkOption {
type = lib.types.str;
default = "nixos";
};
};
config = {
networking.hostName = cfg.hostName;
networking.networkmanager.enable = true;
networking.networkmanager.wifi.powersave = lib.mkDefault true;
users.users.${config.nix-config.userName}.extraGroups = [
"networkmanager"
];
services.avahi.enable = true;
services.avahi.openFirewall = true;
# networking.firewall = {
# enable = false;
# };
};
}

View File

@@ -6,7 +6,7 @@
}:
{
# Needs to be explicitly set to false...
hardware.pulseaudio.enable = false;
services.pulseaudio.enable = false;
# OR
services.pipewire = {
enable = true;

View File

@@ -5,25 +5,53 @@
...
}:
{
services.tlp = {
enable = true;
settings = {
CPU_SCALING_GOVERNOR_ON_BAT = "powersave";
CPU_SCALING_GOVERNOR_ON_AC = "performance";
CPU_ENERGY_PERF_POLICY_ON_BAT = "power";
CPU_ENERGY_PERF_POLICY_ON_AC = "performance";
CPU_MIN_PERF_ON_AC = 0;
CPU_MAX_PERF_ON_AC = 100;
CPU_MIN_PERF_ON_BAT = 0;
CPU_MAX_PERF_ON_BAT = 50;
options.nix-config = {
power = {
batteryThresholds = lib.mkOption {
type = lib.types.listOf lib.types.int;
default = [ 60 80 ];
description = "Battery charge thresholds for power management.";
};
};
};
config = {
services.tlp = {
enable = true;
settings = {
# processor chooses frequencies itself
CPU_DRIVER_OPMODE_ON_AC = "active";
CPU_DRIVER_OPMODE_ON_BAT = "active";
# governor dictates global behavior of the CPU
CPU_SCALING_GOVERNOR_ON_BAT = "powersave";
CPU_SCALING_GOVERNOR_ON_AC = "performance";
# energy performance policy (EPP) sets the energy/performance balance
CPU_ENERGY_PERF_POLICY_ON_BAT = "balance_power";
CPU_ENERGY_PERF_POLICY_ON_AC = "performance";
# CPU_MIN_PERF_ON_AC = 0;
# CPU_MAX_PERF_ON_AC = 100;
# CPU_MIN_PERF_ON_BAT = 0;
# CPU_MAX_PERF_ON_BAT = 50;
# enable battery charge thresholds on the default battery
STOP_CHARGE_THRESH_BAT0 = 1;
# services.superfreq = {
# STOP_CHARGE_THRESH_BAT0 = 80;
# CPU_BOOST_ON_AC = 1;
# CPU_BOOST_ON_BAT = 0;
# CPU_HWP_DYN_BOOST_ON_AC = 1;
# CPU_HWP_DYN_BOOST_ON_BAT = 0;
};
};
# services.watt = {
# enable = true;
# settings = {
# charger = {
@@ -32,6 +60,15 @@
# epp = "performance";
# epb = "balance_performance";
# platform_profile = "performance";
# enable_auto_turbo = true;
# # Custom thresholds for auto turbo management
# turbo_auto_settings = {
# load_threshold_high = 70.0;
# load_threshold_low = 30.0;
# temp_threshold_high = 75.0;
# initial_turbo_state = false; # whether turbo should be initially enabled (false = disabled)
# };
# };
# battery = {
@@ -40,8 +77,15 @@
# epp = "power";
# epb = "balance_power";
# platform_profile = "low-power";
# min_freq_mhz = 800;
# max_freq_mhz = 2500;
# enable_auto_turbo = true;
# # Custom thresholds for auto turbo management
# turbo_auto_settings = {
# load_threshold_high = 80.0;
# load_threshold_low = 40.0;
# temp_threshold_high = 65.0;
# initial_turbo_state = false; # whether turbo should be initially enabled (false = disabled)
# };
# };
@@ -51,18 +95,21 @@
# min_poll_interval_sec = 1;
# max_poll_interval_sec = 30;
# throttle_on_battery = true;
# stats_file_path = "/var/run/watt-stats";
# };
# battery_charge_thresholds = [50 90];
# # battery_charge_thresholds = [50 90];
# };
# # logind.lidSwitchExternalPower = "ignore"; # prevent lid switch from triggering a suspend
# };
systemd.sleep.extraConfig = ''
AllowSuspend=yes
AllowHibernation=yes
AllowHybridSleep=yes
AllowSuspendThenHibernate=yes
'';
systemd.sleep.extraConfig = ''
AllowSuspend=yes
AllowHibernation=yes
AllowHybridSleep=yes
AllowSuspendThenHibernate=yes
'';
};
}

27
modules/nixos/user.nix Normal file
View File

@@ -0,0 +1,27 @@
{
lib,
config,
...
}:
let
cfg = config.nix-config;
in
{
options = {
nix-config.userName = lib.mkOption {
type = lib.types.str;
default = "remy";
};
};
config = {
users.users.${cfg.userName} = {
isNormalUser = true;
extraGroups = [
"wheel" # Enable sudo for the user.
# other groups are added as needed, eg. networkmanager
];
};
};
}