about summary refs log tree commit diff
path: root/nixpkgs/pkgs/development/tools/godot/3/mono/make-deps.nix
blob: e47a5a68d64ba43b449385ff0a3781ff76021d43 (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
47
48
49
50
51
52
53
54
55
56
57
58
59
{ godot3-mono, nuget-to-nix }:

godot3-mono.overrideAttrs (self: base: {
  pname = "godot3-mono-make-deps";

  nativeBuildInputs = base.nativeBuildInputs ++ [ nuget-to-nix ];

  nugetDeps = null;
  nugetSource = null;
  nugetConfig = null;

  shouldConfigureNuget = false;

  outputs = [ "out" ];
  buildPhase = " ";
  installPhase = ''echo "No output intended. Run make-deps.sh instead." > $out'';

  # This script is used to update the accompanying deps.nix file, a nix expression listing the
  # nuget packages that the godot-mono code depends on, along with their sha256 hashes. This
  # file is referenced by the godot-mono derivation and needs to be updated every time the
  # godot version is updated. The way it works is:
  #
  # 1) Creates and navigates to a temporary directory and then explicitly runs the unpack,
  # patch, and configure phases from the godot-mono derivation.
  # 2) Instead of building at this point, a nuget restore is performed, downloading all the
  # nuget dependencies of godot-mono into a local folder.
  # 3) Once these have been downloaded, the nuget-to-nix tool is used to generate a nix
  # expression listing the locally obtained nuget packages, along with their sha256 hashes.
  # 4) This nix expression is saved as deps.nix in the PWD.
  #
  # This process is impure, because it entails downloading files with unknown hashes, so it
  # is run manually by the maintainer within a nix-shell environment. Running the accompanying
  # make-deps.sh instead simplifies this.
  makeDeps = ''
    set -e
    outdir="$(pwd)"
    wrkdir="$(mktemp -d)"
    trap 'rm -rf -- "$wrkdir"' EXIT
    pushd "$wrkdir" > /dev/null
      unpackPhase
      cd source
      patchPhase
      configurePhase

      # Without RestorePackagesPath set, it restores packages to a temp directory. Specifying
      # a path ensures we have a place to run nuget-to-nix.
      nugetRestore() { dotnet msbuild -t:Restore -p:RestorePackagesPath=nugetPackages $1; }

      nugetRestore modules/mono/glue/GodotSharp/GodotSharp.sln
      nugetRestore modules/mono/editor/GodotTools/GodotTools.sln

      nuget-to-nix nugetPackages > "$outdir"/deps.nix
    popd > /dev/null
  '';

  meta = base.meta // {
    description = "Derivation with no output that exists to provide an environment for make-deps.sh";
  };
})