-
Notifications
You must be signed in to change notification settings - Fork 784
Add: nix flakes support #2219
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
base: main
Are you sure you want to change the base?
Add: nix flakes support #2219
Changes from 5 commits
7873003
af956dd
c0a04f2
e2c58a8
74dbb5c
5a0c82c
d7a0041
04e7afc
a3b6ae8
e4a57ba
a570621
5b6564d
b24c2ee
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 = "OpenVAS — Open Vulnerability Assessment Scanner"; | ||
|
|
||
| inputs = { | ||
| nixpkgs.url = "github:NixOS/nixpkgs/nixos-25.11"; | ||
| flake-parts.url = "github:hercules-ci/flake-parts"; | ||
| crane = { | ||
| url = "github:ipetkov/crane"; | ||
| }; | ||
| fenix = { | ||
| url = "github:nix-community/fenix"; | ||
| inputs.nixpkgs.follows = "nixpkgs"; | ||
| }; | ||
| }; | ||
|
|
||
| outputs = | ||
| inputs@{ self, flake-parts, ... }: | ||
| flake-parts.lib.mkFlake { inherit inputs; } { | ||
| systems = [ | ||
| "x86_64-linux" | ||
| "aarch64-linux" | ||
| "x86_64-darwin" | ||
| "aarch64-darwin" | ||
| ]; | ||
|
|
||
| perSystem = | ||
| { system, pkgs, ... }: | ||
| let | ||
| rustToolchain = pkgs.fenix.fromToolchainFile { | ||
| dir = self + /rust; | ||
| sha256 = "sha256-gh/xTkxKHL4eiRXzWv8KP7vfjSk61Iq48x47BEDFgfk="; | ||
|
Contributor
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. we just use the toolchain so that we are not so often surprised by clippy and fmt changes and can do that when we have time. Since we don't validate clippy nor formatting via nix I don't think it is necessary to respect the toolchain definition?
Contributor
Author
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. Well, toolchain is loaded mainly because of the Rust version, so we can have it fixed. Clippy & formatting are extra tools, but not necessary. I can remove the toolchain usage but that means that Rust version will be set by fenix's input lock at flakes. |
||
| }; | ||
|
|
||
| craneLib = (inputs.crane.mkLib pkgs).overrideToolchain rustToolchain; | ||
| in | ||
| rec { | ||
| formatter = pkgs.nixfmt-rfc-style; | ||
|
|
||
| _module.args.pkgs = import inputs.nixpkgs { | ||
| inherit system; | ||
| overlays = [ inputs.fenix.overlays.default ]; | ||
| }; | ||
|
|
||
| packages = import ./nix/packages { | ||
| inherit pkgs craneLib; | ||
| src = self; | ||
| }; | ||
|
|
||
| apps = | ||
| let | ||
| mkApp = name: { | ||
| type = "app"; | ||
| program = "${packages.${name}}/bin/${name}"; | ||
| }; | ||
| in | ||
| { | ||
| openvasd = mkApp "openvasd"; | ||
| scannerctl = mkApp "scannerctl"; | ||
| feed-filter = mkApp "feed-filter"; | ||
| openvas = mkApp "openvas"; | ||
| }; | ||
|
|
||
| devShells.default = pkgs.mkShell { | ||
| inputsFrom = builtins.attrValues packages; | ||
| buildInputs = with pkgs; [ | ||
| cmake | ||
| gcc | ||
| pkg-config | ||
| bison | ||
| flex | ||
| doxygen | ||
| pandoc | ||
| glib | ||
| json-glib | ||
| libgcrypt | ||
| gpgme | ||
| libpcap | ||
| libssh | ||
| libksba | ||
| gnutls | ||
| curl | ||
| libbsd | ||
| krb5 | ||
| file | ||
| net-snmp | ||
| nmap | ||
| redis | ||
| rustToolchain | ||
| clang-tools | ||
| gdb | ||
| valgrind | ||
| ]; | ||
| }; | ||
| }; | ||
|
|
||
| flake.overlays.default = final: prev: { | ||
| inherit (self.packages.${final.system}) | ||
| gvm-libs | ||
| openvasd | ||
| scannerctl | ||
| feed-filter | ||
| scannerlib | ||
| openvas | ||
| ; | ||
| }; | ||
| }; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| { | ||
| pkgs, | ||
| craneLib, | ||
| src, | ||
| }: | ||
|
|
||
| let | ||
| inherit (pkgs) gvm-libs; | ||
|
|
||
| # Read scanner release version from CMakeLists.txt — upstream releases | ||
| # use this version for both the C scanner and the Rust binaries. | ||
| version = builtins.head ( | ||
| builtins.match ".*project[[:space:]]*\\([^)]*VERSION[[:space:]]+([0-9.]+).*" ( | ||
| builtins.readFile ./CMakeLists.txt | ||
| ) | ||
| ); | ||
|
|
||
| cargoToml = fromTOML (builtins.readFile (src + "/rust/Cargo.toml")); | ||
|
|
||
| # Each binary is its own derivation (buildDepsOnly shared, see scannerlib.nix). | ||
| rustOutputs = pkgs.callPackage ./scannerlib.nix { | ||
| inherit craneLib; | ||
| inherit gvm-libs; | ||
| inherit version; | ||
| pname = cargoToml.package.name; | ||
| src = src + "/rust"; | ||
| repoRoot = src; | ||
| }; | ||
|
|
||
| in | ||
| { | ||
| inherit gvm-libs; | ||
|
|
||
| inherit (rustOutputs) | ||
| openvasd | ||
| scannerctl | ||
| feed-filter | ||
| scannerlib | ||
| ; | ||
|
|
||
| openvas = pkgs.callPackage ./openvas.nix { | ||
| inherit src version; | ||
| inherit gvm-libs; | ||
| }; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| { | ||
| stdenv, | ||
| lib, | ||
| version, | ||
| autoPatchelfHook, | ||
| cmake, | ||
| pkg-config, | ||
| bison, | ||
| flex, | ||
| glib, | ||
| json-glib, | ||
| libgcrypt, | ||
| gpgme, | ||
| libpcap, | ||
| libssh, | ||
| libksba, | ||
| gnutls, | ||
| curl, | ||
| libbsd, | ||
| krb5, | ||
| file, | ||
| net-snmp, | ||
| nmap, | ||
| redis, | ||
| doxygen, | ||
| pandoc, | ||
| gvm-libs, | ||
| paho-mqtt-c, | ||
| src, | ||
| }: | ||
|
|
||
| stdenv.mkDerivation (finalAttrs: { | ||
| pname = "openvas"; | ||
| inherit version; | ||
|
|
||
| inherit src; | ||
|
|
||
| # Upstream builds with -Werror; nixpkgs GCC 14+ triggers a sign-compare | ||
| # warning in the NASL packet-forgery code. Strip it rather than adding a | ||
|
arch-fan marked this conversation as resolved.
Outdated
|
||
| # blanket -Wno-error= flag. | ||
| postPatch = '' | ||
| substituteInPlace CMakeLists.txt nasl/CMakeLists.txt src/CMakeLists.txt misc/CMakeLists.txt \ | ||
| --replace-warn "-Werror" "" | ||
| ''; | ||
|
|
||
| nativeBuildInputs = [ | ||
| autoPatchelfHook | ||
| cmake | ||
| pkg-config | ||
| bison | ||
| flex | ||
| doxygen | ||
| pandoc | ||
| ]; | ||
|
|
||
| buildInputs = [ | ||
| glib | ||
| json-glib | ||
| libgcrypt | ||
| gpgme | ||
| libpcap | ||
| libssh | ||
| libksba | ||
| gnutls | ||
| curl | ||
| libbsd | ||
| krb5 | ||
| file | ||
| net-snmp | ||
| nmap | ||
| redis | ||
| gvm-libs | ||
| paho-mqtt-c | ||
| ]; | ||
|
|
||
| # CMAKE_INSTALL_PREFIX=/usr sets the *runtime* prefix baked into the | ||
| # binary (so it looks for /etc/openvas/openvas.conf at runtime). | ||
| # DESTDIR=$out overlays the Nix store on top at build time, and | ||
| # autoPatchelfHook fixes RPATH since libs land in $out/usr/lib/. | ||
| cmakeFlags = [ "-DCMAKE_INSTALL_PREFIX=/usr" ]; | ||
|
|
||
| installPhase = '' | ||
| runHook preInstall | ||
| DESTDIR="$out" cmake --install . | ||
| mkdir -p "$out/bin" | ||
| ln -sf "$out/usr/sbin/openvas" "$out/bin/openvas" | ||
| runHook postInstall | ||
| ''; | ||
|
|
||
| meta = with lib; { | ||
| description = "Open Vulnerability Assessment Scanner"; | ||
| homepage = "https://github.com/greenbone/openvas"; | ||
| license = licenses.gpl2Plus; | ||
| platforms = platforms.linux ++ platforms.darwin; | ||
|
arch-fan marked this conversation as resolved.
Outdated
|
||
| mainProgram = "openvas"; | ||
| }; | ||
| }) | ||
Uh oh!
There was an error while loading. Please reload this page.