query
On this page

makeStaticBinaries

pkgs.makeStaticBinaries

Docs pulled from | This Revision | 10 minutes ago


binaries.


Noogle detected

Implementation

The following is the current implementation of this function.

makeStaticBinaries =
    stdenv0:
    stdenv0.override (
      old:
      {
        mkDerivationFromStdenv = withOldMkDerivation old (
          stdenv: mkDerivationSuper: args:
          if stdenv.hostPlatform.isDarwin then
            throw "Cannot build fully static binaries on Darwin/macOS"
          else
            (mkDerivationSuper args).overrideAttrs (
              args:
              if args ? env.NIX_CFLAGS_LINK then
                {
                  env = args.env // {
                    NIX_CFLAGS_LINK = toString args.env.NIX_CFLAGS_LINK + " -static";
                  };
                }
              else
                {
                  NIX_CFLAGS_LINK = toString (args.NIX_CFLAGS_LINK or "") + " -static";
                }
                // lib.optionalAttrs (!(args.dontAddStaticConfigureFlags or false)) {
                  configureFlags = (args.configureFlags or [ ]) ++ [
                    "--disable-shared" # brrr...
                  ];
                  cmakeFlags = (args.cmakeFlags or [ ]) ++ [ "-DCMAKE_SKIP_INSTALL_RPATH=On" ];
                }
            )
        );
      }
      // lib.optionalAttrs (stdenv0.hostPlatform.libc == "glibc") {
        extraBuildInputs = (old.extraBuildInputs or [ ]) ++ [
          pkgs.glibc.static
        ];
      }
    );