Nix-ld 32bit: Merging defaults to generated attrsets

Hi,

I’ve been trying to make a nix-ld NixOS module that supports 32-bit systems

I have ran into the issue that I cannot merge a default list of values the way t is previously done (by providing a config.programs.nix-ld.libraries), because that would need to do it for each of the systems in attrValues config.programs.nix-ld.systems, which then creates an infinite loop (see my comment on PR)

Just putting the value into the option’s default isn’t very useful, because it isn’t merged, so is thrown away as soon as the user tries to specify additional libraries.

I have thought of a few poor options

  1. Merge defaults when building the pkgs.buildEnv { name = "ld-library-path"; ...} package. Issue is that these defaults then are not visible or overridable.
    nix-ld-libraries =
      system: cfg:
      cfg.pkgs.buildEnv {
        name = "ld-library-path";
        pathsToLink = [ "/lib" ];
        paths = map lib.getLib (cfg.libraries ++ defaultLibraries);
        # TODO make glibc here configurable?
        postBuild = ''
          ln -s ${cfg.pkgs.stdenv.cc.bintools.dynamicLinker} $out/${share-path system}/lib/ld.so
        '';
        extraPrefix = "/${share-path system}";
        ignoreCollisions = true;
      };
    
  2. Have a config.programs.nix-ld.defaultLibraries, a list of strings. Then as above, merge when building the library path package. Defaults now visible but need to be strings not packages. Maybe this is as good as we can do.
    nix-ld-libraries =
      system: cfg':
      cfg'.pkgs.buildEnv {
        name = "ld-library-path";
        pathsToLink = [ "/lib" ];
        paths = map lib.getLib (
          cfg'.libraries ++
          (builtins.map (name: cfg'.pkgs.${name}) cfg.defaultLibraries)
        );
        # TODO make glibc here configurable?
        postBuild = ''
          ln -s ${cfg'.pkgs.stdenv.cc.bintools.dynamicLinker} $out/${share-path system}/lib/ld.so
        '';
        extraPrefix = "/${share-path system}";
        ignoreCollisions = true;
      };
    

Any better options?

Thank you,
Robert