-
Notifications
You must be signed in to change notification settings - Fork 122
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Nix flake #234
Add Nix flake #234
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
{ | ||
description = "cwe_checker finds vulnerable patterns in binary executables"; | ||
|
||
inputs = { | ||
# use upstream once https://github.com/NixOS/nixpkgs/pull/140208 is accepted | ||
# nixpkgs.url = "nixpkgs/nixos-21.05"; | ||
nixpkgs.url = "github:ilkecan/nixpkgs/nixos-21.05"; | ||
flake-utils.url = "github:numtide/flake-utils"; | ||
nix-filter.url = "github:numtide/nix-filter"; | ||
|
||
fenix = { | ||
url = "github:nix-community/fenix"; | ||
inputs.nixpkgs.follows = "nixpkgs"; | ||
}; | ||
|
||
nix-utils = { | ||
url = "git+https://git.sr.ht/~ilkecan/nix-utils"; | ||
inputs.nixpkgs.follows = "nixpkgs"; | ||
}; | ||
}; | ||
|
||
outputs = { self, nixpkgs, flake-utils, ... }@inputs: | ||
let | ||
inherit (builtins) | ||
attrNames | ||
attrValues | ||
; | ||
inherit (nixpkgs.lib) | ||
getAttrs | ||
intersectLists | ||
; | ||
inherit (flake-utils.lib) | ||
defaultSystems | ||
eachSystem | ||
; | ||
nix-filter = inputs.nix-filter.lib; | ||
nix-utils = inputs.nix-utils.lib; | ||
inherit (nix-utils) | ||
createOverlays | ||
importCargoLock | ||
; | ||
|
||
# ghidra-bin.meta.platforms | ||
ghidraPlatforms = [ "x86_64-linux" "x86_64-darwin" ]; | ||
supportedSystems = intersectLists defaultSystems ghidraPlatforms; | ||
commonArgs = { | ||
version = (importCargoLock ./.).cwe_checker.version; | ||
homepage = "https://github.com/fkie-cad/cwe_checker"; | ||
downloadPage = "https://github.com/fkie-cad/cwe_checker/releases"; | ||
changelog = "https://raw.githubusercontent.com/fkie-cad/cwe_checker/master/CHANGES.md"; | ||
maintainers = [ | ||
{ | ||
email = "ilkecan@protonmail.com"; | ||
github = "ilkecan"; | ||
githubId = 40234257; | ||
name = "ilkecan bozdogan"; | ||
} | ||
]; | ||
platforms = supportedSystems; | ||
}; | ||
|
||
derivations = { | ||
cwe_checker = import ./nix/cwe_checker.nix commonArgs; | ||
cwe_checker_to_ida = import ./nix/cwe_checker_to_ida.nix commonArgs; | ||
}; | ||
in | ||
{ | ||
overlays = createOverlays derivations { | ||
inherit | ||
nix-filter | ||
nix-utils | ||
; | ||
}; | ||
overlay = self.overlays.cwe_checker; | ||
} // eachSystem supportedSystems (system: | ||
let | ||
pkgs = import nixpkgs { | ||
inherit system; | ||
overlays = attrValues self.overlays ++ [ | ||
inputs.fenix.overlay | ||
]; | ||
}; | ||
|
||
packageNames = attrNames derivations; | ||
in | ||
rec { | ||
checks = packages; | ||
|
||
packages = getAttrs packageNames pkgs; | ||
defaultPackage = packages.cwe_checker; | ||
|
||
hydraJobs = { | ||
build = packages; | ||
}; | ||
|
||
devShell = | ||
let | ||
packageList = attrValues packages; | ||
in | ||
pkgs.mkShell { | ||
packages = packageList ++ [ | ||
defaultPackage.rustToolchain.defaultToolchain | ||
]; | ||
inputsFrom = packageList; | ||
}; | ||
Comment on lines
+100
to
+105
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The development shell currently includes the packages provided by the flake and their inputs. It also includes the default profile of the stable channel. Other packages or bash code (aliases or function) can also be added here. |
||
}); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
{ version | ||
, changelog | ||
, downloadPage | ||
, homepage | ||
, maintainers | ||
, platforms | ||
}: | ||
{ lib | ||
, fenix | ||
, ghidra-bin | ||
, makeRustPlatform | ||
, makeWrapper | ||
, nix-filter | ||
, writeShellScript | ||
, ... | ||
}: | ||
|
||
let | ||
inherit (nix-filter) inDirectory; | ||
|
||
rustToolchain = fenix.stable; | ||
rustPlatform = makeRustPlatform { | ||
inherit (rustToolchain) cargo rustc; | ||
}; | ||
|
||
pname = "cwe_checker"; | ||
root = ./..; | ||
# Reading the files in the filtered directory is not possible right now. | ||
# Follow up on how https://github.com/NixOS/nix/pull/5163 will be resolved. | ||
mainProgram = pname; | ||
|
||
src = nix-filter { | ||
inherit root; | ||
name = pname; | ||
include = [ | ||
"Cargo.lock" | ||
"Cargo.toml" | ||
(inDirectory "src") | ||
(inDirectory "test") | ||
]; | ||
}; | ||
|
||
preRunScript = writeShellScript "preRunScript" '' | ||
config_dir="$HOME/.config/cwe_checker" | ||
config_json="$config_dir/config.json" | ||
if [[ ! -f $config_json ]]; then | ||
install --mode=644 -D ${toString src}/src/config.json $config_json | ||
fi | ||
|
||
ghidra_json="$config_dir/ghidra.json" | ||
if [[ ! -f $ghidra_json ]]; then | ||
echo '{ "ghidra_path": "${ghidra-bin}/lib/ghidra" }' > $ghidra_json | ||
fi | ||
''; | ||
in | ||
rustPlatform.buildRustPackage { | ||
inherit pname version src; | ||
|
||
cargoHash = "sha256-igAygYTIkV+gfBWVHGVspheTC19TilU3A3/MqSwhd90="; | ||
|
||
buildInputs = [ | ||
ghidra-bin.out | ||
]; | ||
|
||
nativeBuildInputs = [ | ||
makeWrapper.out | ||
]; | ||
|
||
patches = [ | ||
./patches/0001-use-env-variable-for-ghidra-plugin-path.patch | ||
]; | ||
|
||
postInstall = '' | ||
wrapProgram "$out/bin/${mainProgram}" \ | ||
--set CWE_CHECKER_GHIDRA_PLUGIN_PATH "${toString src}/src/ghidra" \ | ||
--run ${preRunScript} | ||
''; | ||
|
||
doInstallCheck = true; | ||
installCheckPhase = '' | ||
tmp=$(mktemp) | ||
HOME=$(mktemp -d) # because of the preRunScript | ||
$out/bin/${mainProgram} --version &> $tmp || (cat $tmp; exit 1) | ||
echo "OK" | ||
''; | ||
|
||
passthru = { | ||
inherit rustToolchain; | ||
ghidra_plugin = "${toString root}/ghidra_plugin/cwe_checker_ghidra_plugin.py"; | ||
}; | ||
|
||
meta = { | ||
description = "cwe_checker finds vulnerable patterns in binary executables"; | ||
longDescription = | ||
"cwe_checker is a suite of checks to detect common bug classes such as" + | ||
"use of dangerous functions and simple integer overflows. These bug" + | ||
"classes are formally known as Common Weakness Enumerations (CWEs). Its" + | ||
"main goal is to aid analysts to quickly find vulnerable code paths."; | ||
|
||
inherit homepage downloadPage changelog; | ||
|
||
license = lib.licenses.lgpl3Plus; | ||
inherit maintainers mainProgram platforms; | ||
}; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ghidra derivation in Nixpkgs only supports these two platforms. I think this is a limitation of Nixpkgs rather than upstream project. But since
cwe_checker
depends onghidra
, I could only support these two platforms.