aboutsummaryrefslogtreecommitdiff
path: root/default.nix
blob: a31eb4c6b3e6675560591f8bdcd23fc15cddc6a1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
{ pkgs, package-resolved }:
let
  resolved-deps =
    (builtins.fromJSON (builtins.readFile package-resolved)).object.pins;
in {
  env = {
    checkouts = let
      make-checkout = { package, repositoryURL, state, ... }:
        let
          repo = builtins.fetchGit {
            url = repositoryURL;
            ref = "master";
            rev = state.revision;
          };
        in pkgs.runCommand "download-${pkgs.stdenv.lib.toLower package}" { } ''
          mkdir $out
          ln -s ${repo} $out/${package}
        '';
    in pkgs.symlinkJoin {
      name = "swift2nix-checkouts";
      paths = map make-checkout resolved-deps;
    };
    dependencies-state-json = let
      dep-to-object = { package, repositoryURL, state, ... }: {
        basedOn = null;
        packageRef = {
          identity = pkgs.stdenv.lib.toLower package;
          isLocal = false;
          name = package;
          path = repositoryURL;
        };
        state = {
          checkoutState = state;
          name = "checkout";
        };
        subpath = package;
      };
      dependencies-state = {
        object = { dependencies = map dep-to-object resolved-deps; };
        version = 2;
      };
    in pkgs.runCommand "build-swift-pm-dependencies-state-json" { } ''
      echo '${builtins.toJSON dependencies-state}' | ${pkgs.jq}/bin/jq > $out
    '';
  };
}