Skip to content

Commit

Permalink
Merge pull request #143 from crytic/nix
Browse files Browse the repository at this point in the history
Add Nix support
  • Loading branch information
bsamuels453 authored Jan 6, 2025
2 parents 891ca30 + b4fa347 commit 225d2ee
Show file tree
Hide file tree
Showing 6 changed files with 220 additions and 3 deletions.
6 changes: 4 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,16 @@

# Dependency directories (remove the comment below to include it)
# vendor/
*node_modules/

# Goland project dir
.idea/

*node_modules/

# Medusa binary
medusa

# Medusa docs
docs/book

# Build results
result
10 changes: 10 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,16 @@ To run

- Ensure JSON keys are `camelCase` rather than `snake_case`, where possible.

### Nix considerations

- If any dependencies are added or removed, the `vendorHash` property in ./flake.nix will need to be updated. To do so, run `nix build`. If it works, you're good to go. If a change is required, you'll see an error that looks like the following. Replace the `specified` value of `vendorHash` in the medusa package of flake.nix with what nix actually `got`.

```
error: hash mismatch in fixed-output derivation '/nix/store/sfgmkr563pzyxzllpmwxdbdxgrav8y1p-medusa-0.1.8-go-modules.drv':
specified: sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=
got: sha256-12Xkg5dzA83HQ2gMngXoLgu1c9KGSL6ly5Qz/o8U++8=
```

## License

The license for this software can be found [here](./LICENSE).
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ The master branch can be installed using the following command:
brew install --HEAD medusa
```

For more information on building from source or obtaining binaries for Windows and Linux, please refer to the [installation guide](./docs/src/getting_started/installation.md).
For more information on building from source, using nix, or obtaining binaries for Windows and Linux, please refer to the [installation guide](./docs/src/getting_started/installation.md).

## Contributing

Expand Down
21 changes: 21 additions & 0 deletions docs/src/getting_started/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,27 @@ Run the following command to install `medusa`:
brew install medusa
```

## Installing with Nix

### Prerequisites

Make sure nix is installed and that `nix-command` and `flake` features are enabled. The [Determinate Systems nix-installer](https://determinate.systems/nix-installer/) will automatically enable these features and is the recommended approach. If nix is already installed without these features enabled, run the following commands.

```
mkdir -p ~/.config/nix
echo 'experimental-features = nix-command flakes' > ~/.config/nix/nix.conf
```

### Build `medusa`

`nix build` will build medusa and wire up independent copies of required dependencies. The resulting binary can be found at `./result/bin/medusa`

### Install `medusa`

After building, you can add the build result to your PATH using nix profiles by running the following command:

`nix profile install ./result`

## Building from source

### Prerequisites
Expand Down
60 changes: 60 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

124 changes: 124 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
{
description = "Medusa smart-contract fuzzer";

inputs = {
nixpkgs.url = "nixpkgs/nixos-24.11";
flake-utils.url = "github:numtide/flake-utils";
};

outputs = { self, nixpkgs, flake-utils }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs { inherit system; config.allowUnfree = true; };
pyCommon = {
format = "pyproject";
nativeBuildInputs = with pkgs.python3Packages; [ pythonRelaxDepsHook ];
pythonRelaxDeps = true;
doCheck = false;
};
in
rec {

packages = rec {

solc-select = pkgs.python3Packages.buildPythonPackage (pyCommon // {
pname = "solc-select";
version = "1.0.4";
src = builtins.fetchGit {
url = "https://github.com/crytic/solc-select.git";
rev = "8072a3394bdc960c0f652fb72e928a7eae3631da";
};
propagatedBuildInputs = with pkgs.python3Packages; [
packaging
setuptools
pycryptodome
];
});

crytic-compile = pkgs.python3Packages.buildPythonPackage (pyCommon // rec {
pname = "crytic-compile";
version = "0.3.7";
src = builtins.fetchGit {
url = "https://github.com/crytic/crytic-compile.git";
rev = "20df04f37af723eaa7fa56dc2c80169776f3bc4d";
};
propagatedBuildInputs = with pkgs.python3Packages; [
cbor2
pycryptodome
setuptools
packages.solc-select
];
});

slither = pkgs.python3Packages.buildPythonPackage (pyCommon // rec {
pname = "slither";
version = "0.10.4";
format = "pyproject";
src = builtins.fetchGit {
url = "https://github.com/crytic/slither.git";
rev = "aeeb2d368802844733671e35200b30b5f5bdcf5c";
};
nativeBuildInputs = with pkgs.python3Packages; [ pythonRelaxDepsHook ];
pythonRelaxDeps = true;
doCheck = false;
propagatedBuildInputs = with pkgs.python3Packages; [
packaging
prettytable
pycryptodome
packages.crytic-compile
web3
];
});

medusa = pkgs.buildGoModule {
pname = "medusa";
version = "0.1.8"; # from cmd/root.go
src = ./.;
vendorHash = "sha256-12Xkg5dzA83HQ2gMngXoLgu1c9KGSL6ly5Qz/o8U++8=";
nativeBuildInputs = [
packages.crytic-compile
pkgs.solc
pkgs.nodejs
];
doCheck = false; # tests require `npm install` which can't run in hermetic build env
};

default = medusa;

};

apps = {
default = {
type = "app";
program = "${self.packages.${system}.medusa}/bin/medusa";
};
};

devShells = {
default = pkgs.mkShell {
buildInputs = with pkgs; [
packages.medusa
bashInteractive
# runtime dependencies
packages.crytic-compile
packages.slither
solc
# test dependencies
nodejs
# go development
go
gotools
go-tools
gopls
go-outline
gopkgs
gocode-gomod
godef
golint
];
};
};

}
);
}

0 comments on commit 225d2ee

Please sign in to comment.