about summary refs log tree commit diff
path: root/external/default.nix
diff options
context:
space:
mode:
authorVincent Ambo <tazjin@google.com>2019-12-12T03·23+0000
committerVincent Ambo <mail@tazj.in>2019-12-13T00·39+0000
commitfb4dd761461de12ccbc276431ea8aa37dcefa9b0 (patch)
tree310c3067bc279d50f10ef2f5e07564e43b126942 /external/default.nix
parente60dfabc2122bbc29fc9832d1562826c08772442 (diff)
feat(external): Implement tool to analyse external dependencies
Adds a tool that can analyse dependencies that were not originally
meant to be built with buildGo.nix and return information that can be
used to construct appropriate Nix dependencies.

The tool will return information about package-local and foreign
dependencies separately to let Nix determine whether all required
dependencies are provided and to correctly link together sub-packages.

To avoid listing standard library imports in the dependencies, a list
of all packages in the standard library is generated statically to
allow for those to be filtered out during the analysis.

This tool is still work-in-progress.
Diffstat (limited to 'external/default.nix')
-rw-r--r--external/default.nix29
1 files changed, 29 insertions, 0 deletions
diff --git a/external/default.nix b/external/default.nix
new file mode 100644
index 000000000000..79d559c05498
--- /dev/null
+++ b/external/default.nix
@@ -0,0 +1,29 @@
+# Copyright 2019 Google LLC.
+# SPDX-License-Identifier: Apache-2.0
+{ runCommand, go, jq, ripgrep, program }:
+
+let
+  # Collect all non-vendored dependencies from the Go standard library
+  # into a file that can be used to filter them out when processing
+  # dependencies.
+  stdlibPackages = runCommand "stdlib-pkgs.json" {} ''
+    export GOPATH=/dev/null
+    ${go}/bin/go list all | \
+      ${ripgrep}/bin/rg -v 'vendor' | \
+      ${jq}/bin/jq -R '.' | \
+      ${jq}/bin/jq -c -s 'map({key: ., value: true}) | from_entries' \
+      > $out
+  '';
+
+  analyser = program {
+    name = "analyser";
+
+    srcs = [
+      ./main.go
+    ];
+
+    x_defs = {
+      "main.stdlibList" = "${stdlibPackages}";
+    };
+  };
+in analyser