1{ lib
2, stdenv
3, fetchFromGitHub
4, kernel ? null
5, libelf
6, nasm
7, python3
8, withDriver ? false
9}:
10
11python3.pkgs.buildPythonApplication rec {
12 pname = "chipsec";
13 version = "1.8.1";
14
15 disabled = !stdenv.isLinux;
16
17 src = fetchFromGitHub {
18 owner = "chipsec";
19 repo = "chipsec";
20 rev = version;
21 hash = "sha256-bK8wlwhP0pi8rOs8ysbSZ+0aZOaX4mckfH/p4OLGnes=";
22 };
23
24 patches = lib.optionals withDriver [ ./ko-path.diff ./compile-ko.diff ];
25
26 KSRC = lib.optionalString withDriver "${kernel.dev}/lib/modules/${kernel.modDirVersion}/build";
27
28 nativeBuildInputs = [
29 libelf
30 nasm
31 ];
32
33 checkInputs = with python3.pkgs; [
34 distro
35 pytestCheckHook
36 ];
37
38 preBuild = lib.optionalString withDriver ''
39 export CHIPSEC_BUILD_LIB=$(mktemp -d)
40 mkdir -p $CHIPSEC_BUILD_LIB/chipsec/helper/linux
41 '';
42
43 preInstall = lib.optionalString withDriver ''
44 mkdir -p $out/${python3.pkgs.python.sitePackages}/drivers/linux
45 mv $CHIPSEC_BUILD_LIB/chipsec/helper/linux/chipsec.ko \
46 $out/${python3.pkgs.python.sitePackages}/drivers/linux/chipsec.ko
47 '';
48
49 setupPyBuildFlags = [
50 "--build-lib=$CHIPSEC_BUILD_LIB"
51 ] ++ lib.optionals (!withDriver) [
52 "--skip-driver"
53 ];
54
55 pythonImportsCheck = [
56 "chipsec"
57 ];
58
59 meta = with lib; {
60 description = "Platform Security Assessment Framework";
61 longDescription = ''
62 CHIPSEC is a framework for analyzing the security of PC platforms
63 including hardware, system firmware (BIOS/UEFI), and platform components.
64 It includes a security test suite, tools for accessing various low level
65 interfaces, and forensic capabilities. It can be run on Windows, Linux,
66 Mac OS X and UEFI shell.
67 '';
68 license = licenses.gpl2Only;
69 homepage = "https://github.com/chipsec/chipsec";
70 maintainers = with maintainers; [ johnazoidberg ];
71 platforms = [ "x86_64-linux" ] ++ lib.optional (!withDriver) "x86_64-darwin";
72 };
73}