1
0
Fork 0
mirror of https://github.com/NixOS/nixpkgs.git synced 2025-06-18 23:50:07 +03:00
nixpkgs/pkgs/development/compilers/swift/swiftpm2nix/support.nix
Silvan Mosberger 4f0dadbf38 treewide: format all inactive Nix files
After final improvements to the official formatter implementation,
this commit now performs the first treewide reformat of Nix files using it.
This is part of the implementation of RFC 166.

Only "inactive" files are reformatted, meaning only files that
aren't being touched by any PR with activity in the past 2 months.
This is to avoid conflicts for PRs that might soon be merged.
Later we can do a full treewide reformat to get the rest,
which should not cause as many conflicts.

A CI check has already been running for some time to ensure that new and
already-formatted files are formatted, so the files being reformatted here
should also stay formatted.

This commit was automatically created and can be verified using

    nix-build a08b3a4d19.tar.gz \
      --argstr baseRev b32a094368
    result/bin/apply-formatting $NIXPKGS_PATH
2024-12-10 20:26:33 +01:00

78 lines
2 KiB
Nix

{
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
}
'';
};
}