#! /bin/sh
# list-module-imports : nix-file -> lines nix-file
set -euf

if echo "$1" | grep -q ^/; then
  :
else
  set -- "./$1"
fi

imports=$(nix-instantiate \
    -I secrets=secrets \
    --strict \
    --json \
    --eval \
    -E \
    "with builtins; with import ./lib/modules.nix; map toString (list-imports $1)")

echo "$imports" \
  | jq -r .[]