A First-Principles-Driven Life

Posts tagged "solidity":

07 Jul 2023

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:

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 = [
  in {
    devShell.x86_64-linux = with pkgs; mkShell {
      buildInputs = [
        (solc.mkDefault pkgs solc_0_8_19)


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!

Tags: nix solidity
Other posts
Creative Commons License
A First-Principles-Driven Life by Miao, ZhiCheng is licensed under a Creative Commons Attribution 3.0 License.