Purpose: Rewrite as flags instead of config.

This commit is contained in:
Dmitry Voronin 2025-01-04 08:44:19 +03:00
parent f260f5b6a2
commit add04e2075
Signed by: voronind
SSH key fingerprint: SHA256:3kBb4iV2ahufEBNq+vFbUe4QYfHt98DHQjN7QaptY9k
16 changed files with 125 additions and 179 deletions

View file

@ -57,6 +57,30 @@ in
(lib.mkIf cfg.hotspotTtlBypass { boot.kernel.sysctl."net.ipv4.ip_default_ttl" = 65; })
(lib.mkIf cfg.latest { boot.kernelPackages = pkgsUnstable.linuxPackages_latest; })
(lib.mkIf cfg.router {
boot.kernel.sysctl = {
# Allow spoofing.
"net.ipv4.conf.all.rp_filter" = lib.mkForce 0;
"net.ipv4.conf.default.rp_filter" = lib.mkForce 0;
# Forward packets.
"net.ipv4.ip_forward" = lib.mkForce 1;
"net.ipv6.conf.all.forwarding" = lib.mkForce 1;
"net.ipv4.conf.all.src_valid_mark" = lib.mkForce 1;
# Allow redirects.
"net.ipv4.conf.all.accept_redirects" = lib.mkForce 1;
"net.ipv6.conf.all.accept_redirects" = lib.mkForce 1;
# Send ICMP.
"net.ipv4.conf.all.send_redirects" = lib.mkForce 1;
# Accept IP source route packets.
"net.ipv4.conf.all.accept_source_route" = lib.mkForce 1;
"net.ipv6.conf.all.accept_source_route" = lib.mkForce 1;
};
})
]
);
}

View file

@ -35,6 +35,11 @@ let
in
{
config = lib.mkIf cfg.enable {
services = {
tlp.enable = true;
upower.enable = true;
};
environment.systemPackages = [ script ];
systemd = {
services.powersave-cpu = {

View file

@ -1,148 +0,0 @@
{ config, lib, ... }:
let
cfg = config.module.purpose;
in
{
config = lib.mkMerge [
(lib.mkIf cfg.creative {
module = {
tablet.enable = true;
package.creative = true;
};
})
(lib.mkIf cfg.desktop {
module = {
keyd.enable = true;
sway.enable = true;
kernel = {
enable = true;
latest = true;
};
package = {
common = true;
core = true;
desktop = true;
};
};
})
(lib.mkIf cfg.disown {
module = {
autoupdate.enable = true;
kernel = {
enable = true;
hardening = true;
};
};
})
(lib.mkIf cfg.gaming { module.package.gaming = true; })
(lib.mkIf cfg.laptop {
services.tlp.enable = true; # Automatic powersaving based on Pluged/AC states.
services.upower.enable = true;
module = {
keyd.enable = true;
sway.enable = true;
wallpaper.video = false;
kernel = {
enable = true;
hardening = true;
latest = true;
};
package = {
common = true;
core = true;
desktop = true;
};
};
})
(lib.mkIf cfg.live {
module = {
keyd.enable = true;
sway.enable = true;
kernel.enable = true;
wallpaper.video = false;
package = {
common = true;
core = true;
creative = true;
desktop = true;
dev = true;
extra = true;
gaming = true;
};
};
})
(lib.mkIf cfg.phone { })
(lib.mkIf cfg.router {
module = {
kernel = {
enable = true;
hardening = true;
};
package = {
common = true;
core = true;
};
};
# De-harden some stuff.
boot.kernel.sysctl = {
# Allow spoofing.
"net.ipv4.conf.all.rp_filter" = lib.mkForce 0;
"net.ipv4.conf.default.rp_filter" = lib.mkForce 0;
# Forward packets.
"net.ipv4.ip_forward" = lib.mkForce 1;
"net.ipv6.conf.all.forwarding" = lib.mkForce 1;
"net.ipv4.conf.all.src_valid_mark" = lib.mkForce 1;
# Allow redirects.
"net.ipv4.conf.all.accept_redirects" = lib.mkForce 1;
"net.ipv6.conf.all.accept_redirects" = lib.mkForce 1;
# Send ICMP.
"net.ipv4.conf.all.send_redirects" = lib.mkForce 1;
# Accept IP source route packets.
"net.ipv4.conf.all.accept_source_route" = lib.mkForce 1;
"net.ipv6.conf.all.accept_source_route" = lib.mkForce 1;
};
})
(lib.mkIf cfg.server {
module = {
wallpaper.video = false;
kernel = {
enable = true;
hardening = true;
};
package = {
common = true;
core = true;
};
};
})
(lib.mkIf cfg.work {
module = {
distrobox.enable = true;
package.dev = true;
virtmanager.enable = true;
docker = {
enable = true;
autostart = false;
rootless = false;
};
kernel = {
enable = true;
hardening = true;
};
};
})
];
}

View file

@ -21,6 +21,18 @@
};
module = {
purpose.live = true;
keyd.enable = true;
sway.enable = true;
kernel.enable = true;
wallpaper.video = false;
package = {
common = true;
core = true;
creative = true;
desktop = true;
dev = true;
extra = true;
gaming = true;
};
};
}

View file

@ -1,4 +1,7 @@
{ lib, ... }:
{ lib, config, ... }:
let
purpose = config.module.purpose;
in
{
options.module.autoupdate.enable = lib.mkEnableOption "the system auto-updates.";
options.module.autoupdate.enable = lib.mkEnableOption "the system auto-updates." // { default = purpose.disown; };
}

View file

@ -1,4 +1,7 @@
{ lib, ... }:
{ lib, config, ... }:
let
purpose = config.module.purpose;
in
{
options.module.distrobox.enable = lib.mkEnableOption "the distrobox.";
options.module.distrobox.enable = lib.mkEnableOption "the distrobox." // { default = purpose.work; };
}

View file

@ -1,7 +1,10 @@
{ lib, ... }:
{ lib, config, ... }:
let
purpose = config.module.purpose;
in
{
options.module.docker = {
enable = lib.mkEnableOption "the docker.";
enable = lib.mkEnableOption "the docker." // { default = purpose.work; };
rootless = lib.mkOption {
default = false;
type = lib.types.bool;

View file

@ -1,9 +1,14 @@
{ lib, ... }:
{ lib, config, ... }:
let
purpose = config.module.purpose;
in
{
options.module.kernel = {
enable = lib.mkEnableOption "the kernel tweaks.";
enable = lib.mkEnableOption "the kernel tweaks." // {
default = with purpose; desktop || disown || laptop || router || server || work;
};
hardening = lib.mkOption {
default = false;
default = with purpose; disown || laptop || router || server || work;
type = lib.types.bool;
};
hotspotTtlBypass = lib.mkOption {
@ -11,7 +16,11 @@
type = lib.types.bool;
};
latest = lib.mkOption {
default = false;
default = with purpose; desktop || laptop || gaming;
type = lib.types.bool;
};
router = lib.mkOption {
default = purpose.router;
type = lib.types.bool;
};
};

View file

@ -1,4 +1,9 @@
{ lib, ... }:
{ lib, config, ... }:
let
purpose = config.module.purpose;
in
{
options.module.keyd.enable = lib.mkEnableOption "the keyboard remaps.";
options.module.keyd.enable = lib.mkEnableOption "the keyboard remaps." // {
default = with purpose; desktop || laptop;
};
}

View file

@ -6,13 +6,15 @@ let
in
{
options.module.ollama = {
enable = lib.mkEnableOption "the local LLM server." // { default = purpose.work && purpose.desktop; };
enable = lib.mkEnableOption "the local LLM server." // {
default = purpose.work;
};
models = lib.mkOption {
default = [ cfg.primaryModel ];
type = with lib.types; listOf str;
};
primaryModel = lib.mkOption {
default = "llama3.3";
default = "llama3.2";
type = lib.types.str;
};
};

View file

@ -1,12 +1,27 @@
{ lib, ... }:
{ lib, config, ... }:
let
purpose = config.module.purpose;
in
{
options.module.package = {
common = lib.mkEnableOption "Common Apps.";
core = lib.mkEnableOption "Core apps.";
creative = lib.mkEnableOption "Creative Apps.";
desktop = lib.mkEnableOption "Desktop Apps.";
dev = lib.mkEnableOption "Dev Apps.";
core = lib.mkEnableOption "Core apps." // {
default = true;
};
common = lib.mkEnableOption "Common Apps." // {
default = with purpose; desktop || laptop;
};
creative = lib.mkEnableOption "Creative Apps." // {
default = purpose.creative;
};
desktop = lib.mkEnableOption "Desktop Apps." // {
default = with purpose; desktop || laptop;
};
dev = lib.mkEnableOption "Dev Apps." // {
default = purpose.work;
};
gaming = lib.mkEnableOption "Gaming Apps." // {
default = purpose.gaming;
};
extra = lib.mkEnableOption "Extra Apps.";
gaming = lib.mkEnableOption "Gaming Apps.";
};
}

View file

@ -1,12 +1,11 @@
{ lib, ... }:
{
options.module.purpose = {
creative = lib.mkEnableOption "creativity modules.";
creative = lib.mkEnableOption "creative modules.";
desktop = lib.mkEnableOption "desktop modules.";
disown = lib.mkEnableOption "modules for machines not used by me.";
gaming = lib.mkEnableOption "gaming modules.";
laptop = lib.mkEnableOption "laptop modules.";
live = lib.mkEnableOption "live modules.";
phone = lib.mkEnableOption "phone modules.";
router = lib.mkEnableOption "router modules.";
server = lib.mkEnableOption "server modules.";

View file

@ -1,7 +1,12 @@
{ lib, ... }:
{ lib, config, ... }:
let
purpose = config.module.purpose;
in
{
options.module.sway = {
enable = lib.mkEnableOption "the Sway WM.";
enable = lib.mkEnableOption "the Sway WM." // {
default = with purpose; desktop || laptop;
};
extraConfig = lib.mkOption {
default = [ ];
type = with lib.types; listOf str;

View file

@ -1,4 +1,9 @@
{ lib, ... }:
{ lib, config, ... }:
let
purpose = config.module.purpose;
in
{
options.module.tablet.enable = lib.mkEnableOption "the support for tables.";
options.module.tablet.enable = lib.mkEnableOption "the support for tables." // {
default = purpose.creative;
};
}

View file

@ -1,4 +1,7 @@
{ lib, ... }:
{ lib, config, ... }:
let
purpose = config.module.purpose;
in
{
options.module.virtmanager.enable = lib.mkEnableOption "the VM support.";
options.module.virtmanager.enable = lib.mkEnableOption "the VM support." // { default = purpose.work; };
}

View file

@ -7,6 +7,7 @@
}:
let
cfg = config.module.wallpaper;
purpose = config.module.purpose;
url = "https://cloud.voronind.com/public.php/dav/files/dG9E9sCNaXyPToH/dark-winter-forest-road-moewalls-com.mp4";
sha256 = "sha256-jCa8bVspeOsAMcUne3DQS+g8rj0byHCA9WQWHXNLccI=";
@ -43,7 +44,7 @@ in
type = lib.types.path;
};
video = lib.mkOption {
default = video;
default = video && purpose.desktop;
type = lib.types.bool;
};
videoPath = lib.mkOption {