2009-05-27 22:27:54 +02:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
prog=$0
|
|
|
|
|
|
|
|
usage(){
|
|
|
|
echo 1>&2 "
|
|
|
|
$prog module-dir
|
|
|
|
|
2009-05-28 01:45:31 +02:00
|
|
|
This script generates the \`module-list.nix' index file inside the
|
2009-05-28 01:12:54 +02:00
|
|
|
module directory.
|
2009-05-27 22:27:54 +02:00
|
|
|
"
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
: ${NIXPKGS=/etc/nixos/nixpkgs}
|
|
|
|
|
|
|
|
is_module(){
|
|
|
|
local file=$1
|
|
|
|
echo "
|
|
|
|
let
|
|
|
|
appIfFun = f: x: if builtins.isFunction f then f x else f;
|
|
|
|
in
|
|
|
|
builtins.isAttrs (
|
|
|
|
appIfFun (import $file) {
|
|
|
|
pkgs = (import $NIXPKGS) {};
|
|
|
|
config = {};
|
|
|
|
dummy = 42;
|
|
|
|
}
|
|
|
|
)
|
|
|
|
" | nix-instantiate - --eval-only
|
|
|
|
}
|
|
|
|
|
2009-06-11 19:59:47 +02:00
|
|
|
find_mask(){
|
|
|
|
local maskfile="$1"
|
|
|
|
if test -r "${maskfile}"; then
|
|
|
|
cat "${maskfile}"
|
|
|
|
echo
|
|
|
|
echo "./module-list.nix"
|
|
|
|
else
|
|
|
|
echo "./module-list.nix"
|
|
|
|
fi | \
|
|
|
|
sed -ne 's/[ ]*#.*//; /^[ ]*$/ d; s/\(.*\)/-wholename '"'\1'"' -or /p' | tr -d '\n'
|
|
|
|
}
|
|
|
|
|
2009-05-27 22:27:54 +02:00
|
|
|
generate_index(){
|
|
|
|
local path="$1"
|
|
|
|
cd "$path"
|
|
|
|
echo -n "$path: " 1>&2
|
2009-05-28 01:14:38 +02:00
|
|
|
{ echo "[ # This file has been generated by $(basename $prog)";
|
2009-06-11 19:59:47 +02:00
|
|
|
for file in : $(eval find ./ $(find_mask ./module-list.mask) -type f -name "'*.nix'" -print | sort); do
|
2009-05-27 22:27:54 +02:00
|
|
|
[ "$file" = ':' ] && continue;
|
|
|
|
echo -n . 1>&2
|
|
|
|
if test "$(is_module "$file" 2> /dev/null)" = "Bool(True)"; then
|
|
|
|
echo " $file"
|
|
|
|
else
|
|
|
|
echo "##### $file"
|
2009-06-11 19:59:47 +02:00
|
|
|
is_module "$file" 2>&1 | sed "s/^/# /; s,$(pwd),.,"
|
2009-05-27 22:27:54 +02:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
echo ']';
|
|
|
|
} > ./module-list.nix
|
|
|
|
echo 1>&2
|
|
|
|
cd - > /dev/null
|
|
|
|
}
|
|
|
|
|
|
|
|
[ $# -eq 1 ] || usage;
|
|
|
|
|
|
|
|
generate_index "$1"
|