How to change flags when building a cross newlib?


I’ve been trying to set up a shell.nix that has the build environment need to compile C projects for the msp430 architecture. Thanks to some help I got on Reddit, I have arrived at the below file which gets me pretty close:

with import <nixpkgs>{};

    nativeBuildInputs = [ meson pkgsCross.msp430.buildPackages.gcc mspdebug ];

The msp430 actually has two variants: msp430 and msp430x. With the above shell.nix, I can build and link a project successfully for something with the msp430x architecture. However, the part I actually want to target is the msp430 architecture. With the above, if I try to compile for an msp430 architecture target, I get link errors because newlib was built for msp430x.

Typically, msp430 vs msp430x is automatically determined when you set the -mmcu flag to the specific part number you are targeting, but it appears you can also set it manually as well by setting -mcpu. I think this means I need to get an -mcpu=msp430 flag to gcc when newlib is being built. Unfortunately, I’m really at a loss as to how to do this properly in nix. So far the closest I’ve gotten to working is this:

with import <nixpkgs>;

let newlib430 = pkgsCross.msp430.buildPackages.newlib // { platform.gcc.cpu = "msp430"; }; in
    nativeBuildInputs = [ meson pkgsCross.msp430.buildPackages.gcc newlib430 mspdebug ];

This seems to try and build newlib but fails because msp430-elf-ar is not found. Am I at least on the right track with any of this? What is the correct way to do this, or is it not possible with what is currently packaged in nixpkgs? If so, what do I have to write myself to get this to work?