1
Fork 0
mirror of https://github.com/RGBCube/HTMNIX synced 2025-07-25 23:17:44 +00:00

Use getEnv to evaulate any file

This commit is contained in:
RGBCube 2024-02-28 10:34:02 +03:00
parent 730e3eb8f0
commit 5e91f5fa6f
No known key found for this signature in database
4 changed files with 45 additions and 1 deletions

9
.gitignore vendored Normal file
View file

@ -0,0 +1,9 @@
*
!site/
!.gitignore
!flake.lock
!*.nix
!*.sh

32
build.sh Executable file
View file

@ -0,0 +1,32 @@
#!/bin/sh
set -e # Fail fast.
rm -rf _site
# Creates all dirs needed.
for dir in $(find site -type d); do
mkdir -p "_$dir"
done
if [[ "$HTMNIX_LOCAL" == 1 ]]; then
FLAKE_REF=.
else
FLAKE_REF=github:RGBCube/HTMNIX
fi
for file in $(find site -type f); do
if [[ ! "$file" =~ ^_ ]]; then
if [[ "$file" =~ .nix$ ]]; then
echo "Processing file $file to _${file%.nix}.html..."
TARGET_FILE="$file" nix eval "$FLAKE_REF#result" --apply toString --raw > "_${file%.nix}.html"
echo "Done!"
else
echo "Copying file $file to _$file..."
cp "$file" "_$file"
echo "Done!"
fi
fi
done
echo "All done!"

View file

@ -74,6 +74,9 @@
};
};
result = builtins.scopedImport { inherit (self) raw __findFile; } ./html.nix;
result = let
targetFile = builtins.getEnv "TARGET_FILE";
targetFile' = if targetFile != "" then targetFile else "site/index.nix";
in builtins.scopedImport { inherit (self) raw __findFile; } ./${targetFile'};
};
}