A Solidity Compilers Collection in Nix
I have written solc.nix
for a while, this article is a summary of it.
It is a collection of solidity compilers as nix expressions. While most solidity development toolchains (foundry,
truffle, hardhat, etc.) have their bespoke mechanisms of downloading solidity compiler (solc
) binaries, there are
situations you would want not to rely on them:
- In a CI environment, you provide the compiler during setup instead of letting toolchains download them again.
- You have a development process that does not have the
solc
resolution mechanism. - You are juggling with multiple versions of solidity compilers.
- You are using NixOS or the "Nix package manager".
If any of these cases apply to you, you should consider using solc.nix
. Here are some tips on how.
Install Nix
Here is a write-up of why I think you should use Nix.
The fastest way to have it installed on your system is to follow the official instruction.
Once installed, you are good to go!
Using Nix Shell
If you just wanted to have some version of solc
ad-hoc, you just need one simple line:
$ nix shell github:hellwolf/solc.nix#solc_0_4_26 github:hellwolf/solc.nix#solc_0_8_19
Then you will have two different solc
binary available for you:
$ solc-0.4.26 --version solc, the solidity compiler commandline interface Version: 0.4.26+commit.4563c3fc.Linux.g++ $ solc-0.8.19 --version solc, the solidity compiler commandline interface Version: 0.8.19+commit.7dd6d404.Linux.g++
Using Nix Flake
If you want a deeper integration of it, you should consider using Nix Flake, here is an example of how to have multiple
solc
installed and one of them as the default one:
{ inputs = { solc = { url = "github:hellwolf/solc.nix"; inputs.nixpkgs.follows = "nixpkgs"; }; }; outputs = { self, nixpkgs, solc }: let pkgs = import nixpkgs { system = "x86_64-linux"; overlays = [ solc.overlay ]; }; in { devShell.x86_64-linux = with pkgs; mkShell { buildInputs = [ solc_0_4_26 solc_0_7_6 solc_0_8_19 (solc.mkDefault pkgs solc_0_8_19) ]; }; }; }
Contribute
If you find this tool useful, please follow up at the git repo, contribute to keep this up to date, and share with people you might think it can help them too!