# modules/features/pentest/_aliases.nix — reach a toolkit's `.py` scripts by # bare name, without taking a name a real tool already owns. # # impacket installs 70 example scripts as `secretsdump.py`, `psexec.py`, # `GetUserSPNs.py`. Muscle memory from Kali wants both `secretsdump.py` and # `secretsdump`, so this symlinks the suffix away — except that impacket also # ships `split.py`, `ping.py`, `net.py`, `reg.py`, `services.py`, `attrib.py` # and `smbclient.py`. Stripping those blindly is not a style question: # environment.systemPackages merges every package into one profile with # buildEnv, so `impacket-aliases/bin/net` and `samba/bin/net` is a hard # collision and the whole system stops building. Before this guard existed the # probe in python.nix failed exactly there. # # So: the `-` alias is always made, and the bare one only when no # package in `reservedFrom` (plus `extraReserved`) already owns that name. The # reserved set is read from those packages' bin/ at build time, so it tracks # what is really installed instead of a list that rots. # # secretsdump.py -> secretsdump, impacket-secretsdump (free) # net.py -> impacket-net (samba owns `net`) # # $out/collisions records every name that was held back, so `pentest-cheat` and # a future reviewer can see what moved and why. { lib, pkgs }: { package, prefix, reservedFrom ? [ ], extraReserved ? [ ], }: pkgs.runCommand "${prefix}-aliases" { meta.description = "suffix-free aliases for ${package.pname or prefix}, collision-guarded"; } '' mkdir -p $out/bin : > $out/collisions reserved=$( { for d in ${lib.escapeShellArgs (map (p: "${p}/bin") reservedFrom)}; do [ -d "$d" ] && ls -1 "$d" done ${lib.optionalString (extraReserved != [ ]) ''printf '%s\n' ${lib.escapeShellArgs extraReserved}''} } | sort -u ) is_reserved() { printf '%s\n' "$reserved" | grep -qxF "$1"; } for f in ${package}/bin/*.py; do [ -e "$f" ] || continue base=$(basename "$f" .py) # Always reachable under the prefix, whatever happens to the bare name. ln -s "$f" "$out/bin/${prefix}-$base" if is_reserved "$base"; then echo "$base (held back: a real tool owns this name) -> ${prefix}-$base" >> $out/collisions else ln -s "$f" "$out/bin/$base" fi done # Belt and braces: assert no bare alias is a reserved name, so a future # change to the logic above fails here rather than at system-rebuild time. for b in $out/bin/*; do n=$(basename "$b") case "$n" in ${prefix}-*) continue ;; esac if is_reserved "$n"; then echo "${prefix}-aliases: bare alias '$n' shadows a real tool" >&2 exit 1 fi done echo "${prefix}-aliases: $(ls -1 $out/bin | wc -l) aliases, $(wc -l < $out/collisions) held back" ''