From 875628a0978937d708ce9365c9cc2061f39b0bca Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Thu, 12 Dec 2019 23:26:08 +0000 Subject: feat(external): Switch between packages & programs automatically --- external/default.nix | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) (limited to 'external/default.nix') diff --git a/external/default.nix b/external/default.nix index a065ab3331aa..5854d4f0277f 100644 --- a/external/default.nix +++ b/external/default.nix @@ -3,7 +3,7 @@ { pkgs, program, package }: let - inherit (builtins) foldl'fromJSON head readFile replaceStrings tail throw; + inherit (builtins) elemAt foldl' fromJSON head length readFile replaceStrings tail throw; inherit (pkgs) lib runCommand go jq ripgrep; pathToName = p: replaceStrings ["/"] ["_"] (toString p); @@ -36,14 +36,24 @@ let if path == [] then { gopkg = value; } else { "${head path}" = mkset (tail path) value; }; - toPackage = self: src: path: entry: package { - name = pathToName entry.name entry.name; - path = lib.concatStringsSep "/" ([ path ] ++ entry.locator); - srcs = map (f: src + ("/" + f)) entry.files; - deps = map (d: lib.attrByPath (d ++ [ "gopkg" ]) ( - throw "missing local dependency '${lib.concatStringsSep "." d}' in '${path}'" - ) self) entry.localDeps; - }; + last = l: elemAt l ((length l) - 1); + + toPackage = self: src: path: entry: + let + args = { + srcs = map (f: src + ("/" + f)) entry.files; + deps = map (d: lib.attrByPath (d ++ [ "gopkg" ]) ( + throw "missing local dependency '${lib.concatStringsSep "." d}' in '${path}'" + ) self) entry.localDeps; + }; + libArgs = args // { + name = pathToName entry.name; + path = lib.concatStringsSep "/" ([ path ] ++ entry.locator); + }; + binArgs = args // { + name = last ([ path ] ++ entry.locator); + }; + in if entry.isCommand then (program binArgs) else (package libArgs); in { src, path, deps ? [] }: let name = pathToName path; -- cgit 1.4.1