push sheeet
Some checks failed
Periodic Merges (6h) / master → staging-nixos (push) Failing after 12m50s
Periodic Merges (6h) / master → staging-next (push) Failing after 12m54s
Periodic Merges (24h) / merge-base(master,staging) → haskell-updates (push) Failing after 11m54s
Periodic Merges (6h) / staging-next → staging (push) Failing after 12m13s
Periodic Merges (24h) / staging-next-25.05 → staging-25.05 (push) Failing after 13m24s
Periodic Merges (24h) / release-25.05 → staging-next-25.05 (push) Failing after 14m28s

This commit is contained in:
Dark Steveneq
2025-10-09 14:15:47 +02:00
commit 646b892680
49168 changed files with 5897842 additions and 0 deletions

View File

@@ -0,0 +1,38 @@
{
lib,
stdenv,
callPackage,
makeWrapper,
jq,
nurl,
}:
stdenv.mkDerivation {
name = "swiftpm2nix";
nativeBuildInputs = [ makeWrapper ];
dontUnpack = true;
installPhase = ''
install -vD ${./swiftpm2nix.sh} $out/bin/swiftpm2nix
wrapProgram $out/bin/$name \
--prefix PATH : ${
lib.makeBinPath [
jq
nurl
]
} \
'';
preferLocalBuild = true;
passthru = callPackage ./support.nix { };
meta = {
description = "Generate a Nix expression to fetch swiftpm dependencies";
mainProgram = "swiftpm2nix";
teams = [ lib.teams.swift ];
platforms = lib.platforms.all;
};
}

View File

@@ -0,0 +1,77 @@
{
lib,
fetchgit,
formats,
}:
let
inherit (lib)
concatStrings
listToAttrs
makeOverridable
mapAttrsToList
nameValuePair
;
json = formats.json { };
in
rec {
# Derive a pin file from workspace state.
mkPinFile =
workspaceState:
assert workspaceState.version >= 5 && workspaceState.version <= 6;
json.generate "Package.resolved" {
version = 1;
object.pins = map (dep: {
package = dep.packageRef.name;
repositoryURL = dep.packageRef.location;
state = dep.state.checkoutState;
}) workspaceState.object.dependencies;
};
# Make packaging helpers from swiftpm2nix generated output.
helpers =
generated:
let
inherit (import generated) workspaceStateFile hashes;
workspaceState = lib.importJSON workspaceStateFile;
pinFile = mkPinFile workspaceState;
in
rec {
# Create fetch expressions for dependencies.
sources = listToAttrs (
map (
dep:
nameValuePair dep.subpath (fetchgit {
url = dep.packageRef.location;
rev = dep.state.checkoutState.revision;
sha256 = hashes.${dep.subpath};
fetchSubmodules = true;
})
) workspaceState.object.dependencies
);
# Configure phase snippet for use in packaging.
configure = ''
mkdir -p .build/checkouts
ln -sf ${pinFile} ./Package.resolved
install -m 0600 ${workspaceStateFile} ./.build/workspace-state.json
''
+ concatStrings (
mapAttrsToList (name: src: ''
ln -s '${src}' '.build/checkouts/${name}'
'') sources
)
+ ''
# Helper that makes a swiftpm dependency mutable by copying the source.
swiftpmMakeMutable() {
local orig="$(readlink .build/checkouts/$1)"
rm .build/checkouts/$1
cp -r "$orig" .build/checkouts/$1
chmod -R u+w .build/checkouts/$1
}
'';
};
}

View File

@@ -0,0 +1,45 @@
#!/usr/bin/env bash
# Generates a Nix expression to fetch swiftpm dependencies, and a
# configurePhase snippet to prepare a working directory for swift-build.
set -eu -o pipefail
shopt -s lastpipe
stateFile=".build/workspace-state.json"
if [[ ! -f "$stateFile" ]]; then
echo >&2 "Missing $stateFile. Run 'swift package resolve' first."
exit 1
fi
stateVersion="$(jq .version $stateFile)"
if [[ $stateVersion -lt 5 || $stateVersion -gt 6 ]]; then
echo >&2 "Unsupported $stateFile version"
exit 1
fi
# Iterate dependencies and prefetch.
hashes=""
jq -r '.object.dependencies[] | "\(.subpath) \(.packageRef.location) \(.state.checkoutState.revision)"' $stateFile \
| while read -r name url rev; do
echo >&2 "-- Fetching $name"
hash="$(nurl "$url" "$rev" --json --submodules=true --fetcher=fetchgit | jq -r .args.hash)"
hashes+="
\"$name\" = \"$hash\";"
echo >&2
done
hashes+=$'\n'" "
# Generate output.
mkdir -p nix
# Copy the workspace state, but clear 'artifacts'.
jq '.object.artifacts = []' < $stateFile > nix/workspace-state.json
# Build an expression for fetching sources, and preparing the working directory.
cat > nix/default.nix << EOF
# This file was generated by swiftpm2nix.
{
workspaceStateFile = ./workspace-state.json;
hashes = {$hashes};
}
EOF
echo >&2 "-- Generated ./nix"