Skip to content

Commit

Permalink
Merge pull request #82 from adisbladis/passthru-updatescript
Browse files Browse the repository at this point in the history
Add passthru.updateScript when package is fully auto generated
  • Loading branch information
adisbladis authored Aug 24, 2022
2 parents 1e03e4a + fe39840 commit 098fb7f
Showing 1 changed file with 29 additions and 2 deletions.
31 changes: 29 additions & 2 deletions builder/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
, cacert
, pkgs
, pkgsBuildBuild
, runtimeShell
, writeScript
, gomod2nix
}:
let

Expand Down Expand Up @@ -238,13 +241,15 @@ let
inherit go modulesStruct defaultPackage goMod pwd;
};

pname = attrs.pname or baseNameOf defaultPackage;

in
warnIf (buildFlags != "" || buildFlagsArray != "")
"Use the `ldflags` and/or `tags` attributes instead of `buildFlags`/`buildFlagsArray`"
stdenv.mkDerivation
(optionalAttrs (defaultPackage != "")
{
pname = attrs.pname or baseNameOf defaultPackage;
inherit pname;
version = stripVersion (modulesStruct.mod.${defaultPackage}).version;
src = vendorEnv.passthru.sources.${defaultPackage};
} // optionalAttrs (hasAttr "subPackages" modulesStruct) {
Expand Down Expand Up @@ -393,7 +398,29 @@ let

disallowedReferences = optional (!allowGoReference) go;

passthru = { inherit go vendorEnv; } // passthru;
passthru = {
inherit go vendorEnv;
} // optionalAttrs (hasAttr "goPackagePath" modulesStruct) {

updateScript =
let
generatorArgs =
if hasAttr "subPackages" modulesStruct
then
concatStringsSep " "
(
map (subPackage: modulesStruct.goPackagePath + "/" + subPackage) modulesStruct.subPackages
)
else modulesStruct.goPackagePath;

in
writeScript "${pname}-updater" ''
#!${runtimeShell}
${optionalString (pwd != null) "cd ${toString pwd}"}
exec ${gomod2nix}/bin/gomod2nix generate ${generatorArgs}
'';

} // passthru;

meta = { platforms = go.meta.platforms or platforms.all; } // meta;
});
Expand Down

0 comments on commit 098fb7f

Please sign in to comment.