aboutsummaryrefslogtreecommitdiff
path: root/srcds-pkgs/mkdepot.nix
blob: f9b0f54fe79135d0fe94c96a5ba04f0faa81914a (plain)
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
{ lib, runCommand, fetchDepotFile }:
{ name
, caches
, postScript ? ""
}:
with lib;
let
  emitStep = { FileName, Flags, Chunks, ... }@file:
    if bitAnd Flags 64 != 0 || Chunks == [] then ''
      mkdir -p $out/'${FileName}'
    '' else let drv = fetchDepotFile file; in ''
      mkdir -p $out/'${drv.passthru.dirname}'
      ln -s '${drv}' $out/'${FileName}'
    '';
  emitManifest = cache: with cache.passthru; let
    sillyPathComponent = if lib.versionAtLeast depotdownloader.version "3.1.0" then
      "manifest_"
    else
      ".DepotDownloader/";
    json = "${cache}/${sillyPathComponent}${toString depot}_${manifest}.json";
    mkStep = file: emitStep (file // { inherit cache; });
  in concatMapStrings mkStep (importJSON json).Files;
in runCommand name {} ''
  ${concatMapStringsSep "\n" emitManifest caches}
  ${postScript}
''