feat(hardening): declare hardening module using 'nix-mineral'

This commit is contained in:
hektor committed 2026-11-08 13:41:38 +01:00
1 parent 209ab8ba30
commit e794e6c0e2
6 files changed
+200 -1

No files matched your search

Generated
+71 -1
View File
@@ -226,6 +226,20 @@
"type": "github"
}
},
"flake-compat_3": {
"locked": {
"lastModified": 1733328505,
"narHash": "sha256-NeCCThCEP3eCl2l/+27kNNK7QrwZB1IJCrXfrbv5oqU=",
"rev": "ff81ac966bb2cae68946d5ed5fc4994f96d0ffec",
"revCount": 69,
"type": "tarball",
"url": "https://api.flakehub.com/f/pinned/edolstra/flake-compat/1.1.0/01948eb7-9cba-704f-bbf3-3fa956735b52/source.tar.gz"
},
"original": {
"type": "tarball",
"url": "https://flakehub.com/f/edolstra/flake-compat/1.tar.gz"
}
},
"flake-parts": {
"inputs": {
"nixpkgs-lib": [
@@ -248,6 +262,24 @@
}
},
"flake-parts_2": {
"inputs": {
"nixpkgs-lib": "nixpkgs-lib"
},
"locked": {
"lastModified": 1778716662,
"narHash": "sha256-m1Yf0wZ8j1OHjTc2UwHwyQRSnNeSgLJOd7q5Y45hzi4=",
"owner": "hercules-ci",
"repo": "flake-parts",
"rev": "f7c1a2d347e4c52d5fb8d10cb4d94b5884e546fb",
"type": "github"
},
"original": {
"owner": "hercules-ci",
"repo": "flake-parts",
"type": "github"
}
},
"flake-parts_3": {
"inputs": {
"nixpkgs-lib": [
"stylix",
@@ -417,6 +449,28 @@
"type": "github"
}
},
"nix-mineral": {
"inputs": {
"flake-compat": "flake-compat_3",
"flake-parts": "flake-parts_2",
"nixpkgs": [
"nixpkgs"
]
},
"locked": {
"lastModified": 1792339378,
"narHash": "sha256-2GSp02yOdG9BSvb0c9SW1nsMnUpjR1/WBKskGz0D+8g=",
"owner": "cynicsketch",
"repo": "nix-mineral",
"rev": "bcd361bb18fccc4297d668aa5e0d5e4ebd4918ce",
"type": "github"
},
"original": {
"owner": "cynicsketch",
"repo": "nix-mineral",
"type": "github"
}
},
"nix-secrets": {
"flake": false,
"locked": {
@@ -503,6 +557,21 @@
"url": "https://channels.nixos.org/nixos-unstable/nixexprs.tar.xz"
}
},
"nixpkgs-lib": {
"locked": {
"lastModified": 1777168982,
"narHash": "sha256-GOkGPcboWE9BmGCRMLX3worL4EMnsnG8MyKmXNeYuhQ=",
"owner": "nix-community",
"repo": "nixpkgs.lib",
"rev": "f5901329dade4a6ea039af1433fb087bd9c1fe14",
"type": "github"
},
"original": {
"owner": "nix-community",
"repo": "nixpkgs.lib",
"type": "github"
}
},
"nixpkgs_2": {
"locked": {
"lastModified": 1792210252,
@@ -639,6 +708,7 @@
"git-hooks": "git-hooks",
"hecuba-services": "hecuba-services",
"home-manager": "home-manager",
"nix-mineral": "nix-mineral",
"nix-secrets": "nix-secrets",
"nixgl": "nixgl",
"nixos-hardware": "nixos-hardware",
@@ -714,7 +784,7 @@
"base16-helix": "base16-helix",
"base16-vim": "base16-vim",
"firefox-gnome-theme": "firefox-gnome-theme",
"flake-parts": "flake-parts_2",
"flake-parts": "flake-parts_3",
"gnome-shell": "gnome-shell",
"nixpkgs": [
"nixpkgs"
+4
View File
@@ -6,6 +6,10 @@
nixos-hardware = {
url = "github:NixOS/nixos-hardware/master";
};
nix-mineral = {
url = "github:cynicsketch/nix-mineral";
inputs.nixpkgs.follows = "nixpkgs";
};
disko = {
url = "github:nix-community/disko/latest";
inputs.nixpkgs.follows = "nixpkgs";
+1
View File
@@ -56,6 +56,7 @@ in
desktop.ly.enable = true;
docker.enable = true;
k8s.enable = true;
hardening.enable = true;
hcloud.enable = true;
networking = {
enable = true;
+1
View File
@@ -40,6 +40,7 @@ in
model = "arc-140t";
};
};
hardening.enable = true;
keyboard.enable = true;
localization.enable = true;
memory = {
+1
View File
@@ -24,6 +24,7 @@ in
hardware.facter.reportPath = ./facter.json;
docker.enable = true;
hardening.enable = true;
secrets.enable = true;
ssh.enable = true;
tailscale.enable = true;
+122
View File
@@ -0,0 +1,122 @@
{
inputs,
config,
lib,
...
}:
let
wakeOnLan = lib.any (iface: iface.wakeOnLan.enable) (lib.attrValues config.networking.interfaces);
randomMac = config.host.role == "laptop" && !wakeOnLan;
desktop = {
preset = [
"compatibility"
]
++ lib.optional config.gaming.enable "performance"; # prioritized (order matters) <https://github.com/cynicsketch/nix-mineral#configuring-options>
settings = {
debug.debugfs = true;
etc.harden-bluetooth = false;
};
};
profiles = {
inherit desktop;
laptop = lib.recursiveUpdate desktop {
preset = [
"compatibility"
"performance"
];
settings.kernel.iommu-passthrough = false;
};
server = {
preset = [
"compatibility"
"maximum" # prioritized (order matters) <https://github.com/cynicsketch/nix-mineral#configuring-options>
];
settings = {
debug.quiet-boot = false;
network = {
ipv6-tempaddr = false;
max-addresses = false;
neighbor-solicitations = false;
router-solicitations = false;
};
system = {
lower-address-mmap = false;
multilib = false;
yama = "admin-only";
};
};
extras = {
kernel.warn-panic = false;
system.secure-chrony = null;
network = {
tcp-window-scaling = true;
};
};
};
};
in
{
imports = [ inputs.nix-mineral.nixosModules.nix-mineral ];
options.hardening = {
enable = lib.mkOption {
default = false;
type = lib.types.bool;
};
profile = lib.mkOption {
default = if profiles ? ${config.host.role} then config.host.role else null;
type = lib.types.nullOr (lib.types.enum (lib.attrNames profiles));
};
};
config = lib.mkIf config.hardening.enable {
assertions = [
{
assertion = config.hardening.profile != null;
message = "no 'hardening.profile' for `${config.host.role}` host role";
}
];
boot.blacklistedKernelModules = [
"dccp"
"sctp"
"rds"
"tipc"
];
hardware.bluetooth.settings.General = lib.mkIf config.hardware.bluetooth.enable {
PairableTimeout = 30;
DiscoverableTimeout = 30;
TemporaryTimeout = 0;
};
networking.wireless.iwd.settings.General.AddressRandomization = lib.mkIf randomMac "network";
nix-mineral = lib.mkMerge [
{
enable = true;
filesystems.normal = {
"/tmp".enable = !config.boot.tmp.useTmpfs;
# only needed for FAT
"/boot".options.umask = lib.mkIf (
!lib.elem (config.fileSystems."/boot".fsType or null) [
"vfat"
"msdos"
"exfat"
]
) (lib.mkForce false);
};
settings = {
etc.harden-gitconfig = false;
kernel.cpu-mitigations = "smt-on";
network = {
ip-forwarding = config.virtualisation.docker.enable || config.services.k3s.enable;
random-mac = randomMac;
router-advertisements = "on";
tcp-sack = true;
};
};
}
(lib.optionalAttrs (config.hardening.profile != null) profiles.${config.hardening.profile})
];
};
}