NixDaemon

NixOS pentest workstation as one flake — IceBreaker's successor
git clone https://git.daemon-sec.xyz/NixDaemon.git
Log | Files | Refs | README

wrap.sh (803B)


      1 #!/usr/bin/env bash
      2 # scripts/wrap.sh FILE ATTR — turn a plain NixOS / home-manager module file
      3 # into a flake-parts module that exports it under ATTR, in place:
      4 #
      5 #   # leading comment block, kept as is
      6 #   { ... }:
      7 #   {
      8 #     ATTR =
      9 #       <the original module, indented by two spaces>;
     10 #   }
     11 #
     12 # The split is at the first line that is neither a `#` comment nor blank, so
     13 # the file's header comment stays at the top where editors and readers expect it.
     14 set -euo pipefail
     15 file=$1
     16 attr=$2
     17 tmp=$(mktemp)
     18 awk -v attr="$attr" '
     19   !body && ($0 ~ /^#/ || $0 ~ /^[[:space:]]*$/) { print; next }
     20   !body { body = 1; print "{ ... }:"; print "{"; print "  " attr " =" }
     21   body { if ($0 ~ /^[[:space:]]*$/) print ""; else print "  " $0 }
     22   END { print "  ;"; print "}" }
     23 ' "$file" > "$tmp"
     24 mv "$tmp" "$file"