#!/usr/bin/env bash

find $HOME/nixos-config -name "*.nix" | while read -r file; do
  imports=$(awk '
    /imports[[:space:]]*=/ {flag=1}
    flag {print}
    /\]/ && flag {flag=0}
    ' "$file" | grep -vE 'imports[[:space:]]*=' | grep -v '\[' | grep -v '\]' | sed 's/^[[:space:]]*//; s/[[:space:]]*$//')

    if [[ -n "$imports" ]]; then
      echo "$file imports:"
      echo "$imports" | sed 's/^/   |--- /'
      echo
    fi
done
