Disabling SSE and SSE2 instruction in a devshell

Hi :slight_smile:

I am trying to compile llama.cpp without any SIMD instructions. I’m building llama.cpp from their flake.nix devshell which gets rid of most platform specific instruction sets (like AVX and others). However, SSE and SSE2 remain even when building in the devshell and using the -mno-sse and -mno-sse2 flags. I’m pretty sure it’s because the dependencies (glibc and others) still contain both SSE and SSE2.

I ran:

  1. nix develop
  2. cmake -B build -DCMAKE_BUILD_TYPE=Debug
  3. cmake --build build

Is there a way to add these flags to stdenv so that everything is compiled without them? Or is there another way to do this?

Thank you so much for your help!

PS: I use elfx86exts to check the instruction sets used.
PPS: I’m on an Ubuntu 18.04, with an Intel CPU

What about something like this?

$ cat shell.nix 
{ }:

let
  nixpkgs = builtins.getFlake "github:nixos/nixpkgs";
  pkgs = import nixpkgs {
    config.replaceStdenv = { pkgs }:
      (pkgs.stdenvAdapters.withCFlags "-mno-sse -mno-sse2" pkgs.stdenv);
  };
in pkgs.mkShell { packages = with pkgs; [ hello ]; }

Do you have a block of code we can use as a reference?

1 Like

I’m using the devshell defined here

{ inputs, ... }:

{
  perSystem =
    {
      config,
      lib,
      system,
      ...
    }:
    {
      devShells =
        let
          pkgs = import inputs.nixpkgs { inherit system; };
          stdenv = pkgs.stdenv;
          scripts = config.packages.python-scripts;
        in
        lib.pipe (config.packages) [
          (lib.concatMapAttrs (
            name: package: {
              ${name} = pkgs.mkShell {
                name = "${name}";
                inputsFrom = [ package ];
                shellHook = ''
                  echo "Entering ${name} devShell"
                '';
              };
              "${name}-extra" =
                if (name == "python-scripts") then
                  null
                else
                  pkgs.mkShell {
                    name = "${name}-extra";
                    inputsFrom = [
                      package
                      scripts
                    ];
                    # Extra packages that *may* be used by some scripts
                    packages = [
                        pkgs.python3Packages.tiktoken
                    ];
                    shellHook = ''
                      echo "Entering ${name} devShell"
                      addToSearchPath "LD_LIBRARY_PATH" "${lib.getLib stdenv.cc.cc}/lib"
                    '';
                  };
            }
          ))
          (lib.filterAttrs (name: value: value != null))
        ];
    };
}

And, what happens if you define that stdenv like defined above in the earlier code sample?

Works great, thank you!