# modules/features/pentest/options.nix — the toolkit's master switch and the# options no single category owns.## daemon.pentest.enable the whole toolkit (default false)# daemon.pentest.<category>.enable declared by each category itself# (_sets.nix), so adding a category# touches one file, not two# daemon.pentest.payloads.windowsArches which .exe variants to cross-build# daemon.pentest.htb.vpnDir where .ovpn profiles are looked for# daemon.pentest.htb.promptTarget show $TARGET in the prompt## Scope: authorised lab use (HackTheBox CPTS prep). Nothing here points at any# host; the operator supplies targets at runtime.{ inputs, lib, self, ... }:
{
# `daemon.pentest.enable = false` must be a usable state, not an eval error.# The spec gives the master switch `default = false`, so "off" is the normal# case for any other machine built from this flake. This check evaluates the# whole toolkit with the master switch off and fails if any assertion fires.# Under `config` because this module also declares `options`. config.perSystem= { pkgs, system, ... }:
letprobe= enable:
inputs.nixpkgs.lib.nixosSystem {
inherit system;
specialArgs= {
inherit inputs;
user="probe";
};
modules= [
self.nixosModules.pentest
{
daemon.pentest.enable= enable;
# Enough to make a nixosSystem evaluate. boot.loader.grub.devices= [ "nodev" ];
fileSystems."/"= { device="/dev/null"; fsType="ext4"; };
system.stateVersion="26.05";
nixpkgs.config.allowUnfree=true;
users.users.probe.isNormalUser=true;
}
];
};
failures= enable:
map (a: a.message) (builtins.filter (a: !a.assertion) (probe enable).config.assertions);
offFailures= failures false;
in {
checks.pentest-options-off=if offFailures != [ ] thenthrow'' daemon.pentest.enable = false must evaluate cleanly, but these assertions fired:${lib.concatMapStringsSep "\n" (m: " - "+ m) offFailures} ''else pkgs.runCommand "pentest-options-off-check" { } '' echo "daemon.pentest.enable = false evaluates with no failed assertions" > $out '';
};
# Each category file registers its package list here (_sets.nix), and# devshells.nix reads the merged result for the union shell and the# all-category collision check.## It lives under `flake.lib` rather than a top-level `flake.pentestPackages`# for two reasons: the option has to be DECLARED as an attribute set, or# flake-parts treats the whole thing as one freeform value and the second# category to define it fails with "defined multiple times"; and `lib` is an# output Nix recognises, so `nix flake check` does not warn about an unknown# flake output. options.flake= inputs.flake-parts.lib.mkSubmoduleOptions {
lib= lib.mkOption {
# A submodule, not a bare attrset: `pentestPackages` has to merge across# the category files, so it needs its own attrsOf option. The freeform# type keeps `flake.lib` open for anything else.type= lib.types.submoduleWith {
modules= [
{
freeformType= lib.types.lazyAttrsOf lib.types.raw;
options.pentestPackages= lib.mkOption {
type= lib.types.lazyAttrsOf lib.types.raw;
default= { };
description="Per-category `pkgs -> [package]` functions, by category name.";
};
}
];
};
default= { };
description="Flake-level helpers, including pentestPackages.";
};
};
# Under `config` because this module also declares `options` above. config.flake.nixosModules.pentest-options= { lib, config, user, ... }:
letcfg= config.daemon.pentest;
# Every category option declared by _sets.nix: an attrset carrying a# boolean `enable`. `htb` and `payloads.windowsArches` are not categories# and drop out of this filter on their own.categories= lib.filterAttrs (_: v: lib.isAttrs v && v ? enable && lib.isBool v.enable) cfg;
enabledWhileOff= lib.attrNames (lib.filterAttrs (_: v: v.enable) categories);
in {
options.daemon.pentest= {
enable= lib.mkEnableOption "the offensive security toolkit";
payloads.windowsArches= lib.mkOption {
type= lib.types.listOf (lib.types.enum [ "amd64""x86""arm64" ]);
default= [ "amd64""x86" ];
description="Windows architectures to cross-build payload binaries for.";
};
htb.vpnDir= lib.mkOption {
type= lib.types.str;
default="/home/${user}/.config/htb/vpn";
description='' Directory scanned for OpenVPN profiles by `htbvpn list`. Deliberately not Nix-managed: HTB profiles are per-account and rotate. '';
};
htb.promptTarget= lib.mkOption {
type= lib.types.bool;
default=true;
description="Show the current $TARGET in the shell prompt.";
};
};
config.assertions= [
{
assertion= cfg.enable ||enabledWhileOff== [ ];
message="daemon.pentest: ${lib.concatStringsSep ", " enabledWhileOff} "+"enabled while daemon.pentest.enable is false. Set daemon.pentest.enable = true.";
}
];
};
}