summaryrefslogtreecommitdiffstats
path: root/lib/nix-thin-edge-builder/writeCargoToml.nix
blob: 91dc22889559ef327ab23bf7843c50387e7a53e2 (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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
{ craneLib, components, pkgs }:

let
  edition = "2021";
  applyOverrides = replacements: pkg: pkgs.runCommand "apply-${pkg.name}" { } ''
    cp -R ${pkg.src}/* .
    rm Cargo.toml
    cat ${pkg.src}/Cargo.toml ${pkgs.lib.concatMapStrings (r: '' | sed 's|${r.localPath}|"${r.src}"|' '') replacements} > Cargo.toml
    cp -R ./ $out
  '';
  apiOnlyPatchCrates = [
    { localPath = "\".*/tedge_api\""; src = ../../crates/core/tedge_api; }
  ];
  allPatchCrates = apiOnlyPatchCrates ++ [
    { localPath = "\".*/tedge_lib\""; src = localCrates.tedge_lib.path; }
    { localPath = "\".*/tedge_core\""; src = localCrates.tedge_core.path; }
  ];
  localCrates = {
    tedge_api = { path = ../../crates/core/tedge_api; };
    tedge_core = { path = applyOverrides apiOnlyPatchCrates { name = "tedge_core"; src = ../../crates/core/tedge_core; }; };
    tedge_lib = { path = applyOverrides apiOnlyPatchCrates { name = "tedge_lib"; src = ../../crates/core/tedge_lib; }; };
    tedge-cli = {
      default-features = false;
      path = applyOverrides allPatchCrates { name = "tedge-cli"; src = ../../tedge; };
    };
  };

  defaultDependencies = {
    clap = { version = "3"; features = [ "derive" "cargo" "suggestions" ]; };
    toml = "0.5.8";
    tokio = { version = "1"; features = [ "fs" "macros" "rt-multi-thread" "signal" ]; };
    miette = { version = "4.7"; features = [ "fancy" ]; };
    cfg-if = "1";
    tracing = "0.1";
    tracing-subscriber = { version = "0.3.11"; features = [ "env-filter" ]; };
    tracing-chrome = "0.6";
    tracing-tracy = "0.9";
    cfg_table = "1.0.0";
    nu-ansi-term = "0.45.1";
    pretty = { version = "0.11.3"; features = [ "termcolor" ]; };
    termcolor = "1.1.3";
    termimad = "0.20.1";
    term_size = "0.3.2";
    owo-colors = "3.4.0";
    textwrap = "0.15.0";
  } // localCrates;

  componentDependencies =
    let
      mkDep = component: {
        name = component.name;
        value = {
          path = applyOverrides allPatchCrates component;
        };
      };
    in
    builtins.listToAttrs (builtins.map mkDep components);
in

craneLib.writeTOML "Cargo.toml" {
  package = {
    name = "thin-edge";
    version = "0.1.0";
    edition = "2021";
  };

  dependencies = defaultDependencies // componentDependencies;
}