mirror of
https://github.com/tweag/gomod2nix.git
synced 2024-11-09 20:19:08 +00:00
refactor: Move replace commands computation to mkVendorEnv
It should be shared between shell envs and packages.
This commit is contained in:
parent
197bc13f6a
commit
85eaf382e6
1 changed files with 25 additions and 17 deletions
|
@ -59,8 +59,30 @@ let
|
||||||
impureEnvVars = lib.fetchers.proxyImpureEnvVars ++ [ "GOPROXY" ];
|
impureEnvVars = lib.fetchers.proxyImpureEnvVars ++ [ "GOPROXY" ];
|
||||||
};
|
};
|
||||||
|
|
||||||
mkVendorEnv = { go, modulesStruct, localReplaceCommands ? [ ], defaultPackage ? "" }:
|
mkVendorEnv =
|
||||||
|
{ go
|
||||||
|
, modulesStruct
|
||||||
|
, localReplaceCommands ? [ ]
|
||||||
|
, defaultPackage ? ""
|
||||||
|
, goMod
|
||||||
|
, pwd
|
||||||
|
}:
|
||||||
let
|
let
|
||||||
|
localReplaceCommands =
|
||||||
|
let
|
||||||
|
localReplaceAttrs = lib.filterAttrs (n: v: lib.hasAttr "path" v) goMod.replace;
|
||||||
|
commands = (
|
||||||
|
lib.mapAttrsToList
|
||||||
|
(name: value: (
|
||||||
|
''
|
||||||
|
mkdir -p $(dirname vendor/${name})
|
||||||
|
ln -s ${pwd + "/${value.path}"} vendor/${name}
|
||||||
|
''
|
||||||
|
))
|
||||||
|
localReplaceAttrs);
|
||||||
|
in
|
||||||
|
if goMod != null then commands else [ ];
|
||||||
|
|
||||||
sources = lib.mapAttrs
|
sources = lib.mapAttrs
|
||||||
(goPackagePath: meta: fetchGoModule {
|
(goPackagePath: meta: fetchGoModule {
|
||||||
goPackagePath = meta.replaced or goPackagePath;
|
goPackagePath = meta.replaced or goPackagePath;
|
||||||
|
@ -132,7 +154,7 @@ let
|
||||||
go = selectGo attrs goMod;
|
go = selectGo attrs goMod;
|
||||||
|
|
||||||
vendorEnv = mkVendorEnv {
|
vendorEnv = mkVendorEnv {
|
||||||
inherit go modulesStruct;
|
inherit go modulesStruct pwd goMod;
|
||||||
};
|
};
|
||||||
|
|
||||||
in
|
in
|
||||||
|
@ -197,20 +219,6 @@ let
|
||||||
if pwd != null && lib.pathExists goModPath
|
if pwd != null && lib.pathExists goModPath
|
||||||
then parseGoMod (builtins.readFile goModPath)
|
then parseGoMod (builtins.readFile goModPath)
|
||||||
else null;
|
else null;
|
||||||
localReplaceCommands =
|
|
||||||
let
|
|
||||||
localReplaceAttrs = lib.filterAttrs (n: v: lib.hasAttr "path" v) goMod.replace;
|
|
||||||
commands = (
|
|
||||||
lib.mapAttrsToList
|
|
||||||
(name: value: (
|
|
||||||
''
|
|
||||||
mkdir -p $(dirname vendor/${name})
|
|
||||||
ln -s ${pwd + "/${value.path}"} vendor/${name}
|
|
||||||
''
|
|
||||||
))
|
|
||||||
localReplaceAttrs);
|
|
||||||
in
|
|
||||||
if goMod != null then commands else [ ];
|
|
||||||
|
|
||||||
go = selectGo attrs goMod;
|
go = selectGo attrs goMod;
|
||||||
|
|
||||||
|
@ -219,7 +227,7 @@ let
|
||||||
defaultPackage = modulesStruct.goPackagePath or "";
|
defaultPackage = modulesStruct.goPackagePath or "";
|
||||||
|
|
||||||
vendorEnv = mkVendorEnv {
|
vendorEnv = mkVendorEnv {
|
||||||
inherit go modulesStruct localReplaceCommands defaultPackage;
|
inherit go modulesStruct defaultPackage goMod pwd;
|
||||||
};
|
};
|
||||||
|
|
||||||
in
|
in
|
||||||
|
|
Loading…
Reference in a new issue