dotfiles
My PC Dotfiles & Websitegit clone https://github.com/maydayv7/dotfiles
site/git/default.nix (2842B)
1{
2 lib,
3 pkgs,
4 site ? "https://git.maydayv7.dev",
5 sitename ? "maydayv7",
6 test ? false,
7}: let
8 stagit = pkgs.callPackage ./stagit {};
9 assets = pkgs.callPackage ./assets.nix {gitSite = site;};
10 buildCommands =
11 if test
12 then ''build_repo test "A long description just for testing" Me "$(pwd)"''
13 else
14 lib.concatMapStrings (repo: ''
15 build_repo ${lib.escapeShellArgs [repo.name repo.description repo.owner repo.url]}
16 '') (import ./repos.nix);
17in
18 pkgs.writeShellApplication {
19 name = "gitsite";
20 runtimeInputs = with pkgs; [
21 coreutils
22 git
23 stagit
24 (python3.withPackages (ps: [ps.fonttools ps.brotli ps.lxml]))
25 ];
26 text = ''
27 # Build Directory
28 OUTPUT_DIR=$(realpath -m "''${1:-./public}")
29 if [ -e "$OUTPUT_DIR" ]
30 then
31 echo "Output already exists: $OUTPUT_DIR. Choose an empty destination." >&2
32 exit 1
33 fi
34 mkdir -p "$(dirname "$OUTPUT_DIR")"
35 BUILD_ROOT=$(mktemp -d "$(dirname "$OUTPUT_DIR")/.stagit-build.XXXXXXXX")
36 trap 'rm -rf "$BUILD_ROOT"' EXIT
37 STAGING_DIR="$BUILD_ROOT/public"
38 export TZ=UTC
39 mkdir -p "$STAGING_DIR" "$BUILD_ROOT/repos"
40
41 build_repo() {
42 local name=$1 description=$2 owner=$3 url=$4
43 local repository="$BUILD_ROOT/repos/$name.git"
44 echo "Building $name..."
45
46 # Repository
47 git -c safe.directory="$url" -c safe.directory="$url/.git" \
48 -c http.lowSpeedLimit=1024 -c http.lowSpeedTime=60 clone --bare "$url" "$repository"
49 printf '%s\n' "$description" > "$repository/description"
50 printf '%s\n' "$owner" > "$repository/owner"
51 printf '%s\n' "$url" > "$repository/url"
52 mkdir -p "$STAGING_DIR/$name"
53 (cd "$STAGING_DIR/$name" && stagit -l 50 -n ${lib.escapeShellArg sitename} \
54 -u ${lib.escapeShellArg site}/"$name" "$repository")
55 }
56
57 if [ "$#" -gt 1 ]
58 then
59 LOCAL_REPO=$(realpath "$2")
60 build_repo "$(basename "$LOCAL_REPO" .git)" "Local preview" ${lib.escapeShellArg sitename} "$LOCAL_REPO"
61 else
62 ${buildCommands}
63 fi
64
65 stagit-index -n ${lib.escapeShellArg sitename} "$BUILD_ROOT/repos/"*.git > "$STAGING_DIR/index.html"
66 python3 ${./assemble.py} assemble "$STAGING_DIR" ${assets} --repositories "$BUILD_ROOT/repos"
67 cp -r ${assets}/. "$STAGING_DIR/"
68 chmod -R u+w "$STAGING_DIR"
69 rm "$STAGING_DIR/shell.html"
70 cp ${./_headers} "$STAGING_DIR/_headers"
71 python3 ${../scripts/optimize_fonts.py} "$STAGING_DIR" --source ${../static/fonts}
72 mv "$STAGING_DIR" "$OUTPUT_DIR"
73 echo "Built gitsite at $OUTPUT_DIR"
74 '';
75 meta = {
76 mainProgram = "gitsite";
77 description = "Build the gitsite";
78 license = lib.licenses.gpl3Only;
79 maintainers = ["maydayv7"];
80 };
81 }