Skip to content

Decycling the toolchain for NUR integration #196

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
SCOTT-HAMILTON opened this issue Apr 19, 2025 · 0 comments
Open

Decycling the toolchain for NUR integration #196

SCOTT-HAMILTON opened this issue Apr 19, 2025 · 0 comments

Comments

@SCOTT-HAMILTON
Copy link

Hello, I'm very interested in gomod2nix because it greatly simplifies the packaging process of go modules.

I'm using a nur repo to package my personal apps and I therefore wanted to add gomod2nix.buildGoApplication to my libs. Except that gomod2nix uses overlays...

And the reason behind this is (as I understand it) because of the following cyclic dependency: gomod2nix(the binary) depends on buildGoApplication which depends on gomod2nix.

Fortunately, the last dependency link is easy to break: buildGoApplication only depends on gomod2nix for its update script.

So I've used the following structure to add buildGoApplication to my nur libs:
lib/default.nix

{ pkgs }:

with pkgs.lib; let
  builder0 = pkgs.callPackage ./gomod2nix-no-cyclic-deps/builder { };
  gomod2nix0 = pkgs.callPackage ./gomod2nix-no-cyclic-deps { inherit (builder0) buildGoApplication; };
  builder1 = pkgs.callPackage ./gomod2nix/builder { gomod2nix = gomod2nix0; };
in {
  gomod2nix = { inherit (builder1)  buildGoApplication; };
}

gomod2nix is just a clone of this repo, and gomod2nix-no-cyclic-deps is a fork with the following patch:

--- a/builder/default.nix
+++ b/builder/default.nix
@@ -10,7 +10,6 @@
 , buildPackages
 , runtimeShell
 , writeScript
-, gomod2nix
 , rsync
 }:
 let
@@ -405,26 +404,6 @@ let
 
         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;
 
         inherit meta;

(I just deleted the updatescript).
This works but I wonder how this toolchain could be internalized into the project instead of me having to pull/rebase my patch every time it conflicts with upstream.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant