aboutsummaryrefslogtreecommitdiff
path: root/srcds-pkgs/fetchdepotfile.nix
blob: 6af2507db471b7e7752cf75a4ab5217456945160 (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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# as nice as it would be to just put the file in its expected directory
# structure and symlinkJoin them together at the end, creating that structure
# sacrifices the use of steam's hashes -- nix hashing isn't hierarchical
# or anything, just "archive everything and hash it like another flat file".
{ lib, runCommand
, depotdownloader, cacert
}:
{ FileName, FileHash, Flags, cache, ... }:
with lib;
assert !hasPrefix "/" FileName;
let
  dirname = dirOf FileName;
  basename = baseNameOf FileName;
  src = runCommand basename {
    inherit (cache.passthru) app depot manifest;
    inherit basename dirname FileName;
    cache = "${cache}";

    passthru = { inherit dirname basename; };
    nativeBuildInputs = [ depotdownloader cacert ];
    outputHashMode = "flat";
    outputHashAlgo = "sha1";
    outputHash = FileHash;
  } ''
    export HOME=$PWD
    cp -r $cache/.DepotDownloader ./
    chmod -R 777 .DepotDownloader
    DepotDownloader \
      -app $app -depot $depot -manifest $manifest \
      -filelist <(echo "$FileName") -dir .

    mv $FileName $out
    chmod -x $out
  '';
# nix refuses to flat hash executables lol
in if bitAnd Flags 32 != 0 then
  runCommand src.name {
    inherit src;
    inherit (src) passthru;
  } ''
    cp $src $out
    chmod +x $out
  ''
else src