3 # Generates a Nix expression to fetch swiftpm dependencies, and a
4 # configurePhase snippet to prepare a working directory for swift-build.
9 stateFile
=".build/workspace-state.json"
10 if [[ ! -f "$stateFile" ]]; then
11 echo >&2 "Missing $stateFile. Run 'swift package resolve' first."
15 stateVersion
="$(jq .version $stateFile)"
16 if [[ $stateVersion -lt 5 ||
$stateVersion -gt 6 ]]; then
17 echo >&2 "Unsupported $stateFile version"
21 # Iterate dependencies and prefetch.
23 jq
-r '.object.dependencies[] | "\(.subpath) \(.packageRef.location) \(.state.checkoutState.revision)"' $stateFile \
24 |
while read -r name url
rev; do
25 echo >&2 "-- Fetching $name"
26 sha256
="$(nix-prefetch-git --fetch-submodules $url $rev | jq -r .sha256)"
28 \"$name\" = \"$sha256\";"
35 # Copy the workspace state, but clear 'artifacts'.
36 jq
'.object.artifacts = []' < $stateFile > nix
/workspace-state.json
37 # Build an expression for fetching sources, and preparing the working directory.
38 cat > nix
/default.nix
<< EOF
39 # This file was generated by swiftpm2nix.
41 workspaceStateFile = ./workspace-state.json;
45 echo >&2 "-- Generated ./nix"