Skip to content
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 #1970

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ In order to optimize support effort,
brew install cmake ninja openssl@3 wget doxygen graphviz astyle valgrind
pip3 install pytest pytest-xdist pyyaml

Using Nix:

nix develop

Note that, if you want liboqs to use OpenSSL for various symmetric crypto algorithms (AES, SHA-2, etc.) then you must have OpenSSL installed (version 3.x recommended; EOL version 1.1.1 also still possible).

2. Get the source:
Expand Down
61 changes: 61 additions & 0 deletions flake.lock

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

87 changes: 87 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.05";
flake-utils.url = "github:numtide/flake-utils";
};
outputs = {
self,
nixpkgs,
flake-utils,
}:
flake-utils.lib.eachDefaultSystem (system: let
name = "liboqs";
src = ./.;
pkgs = nixpkgs.legacyPackages.${system};

# Function to create compiler-specific package sets
mkPackageSet = compiler: let
# Override the stdenv to use the specified compiler
stdenv =
if compiler == "clang"
then pkgs.clangStdenv
else pkgs.stdenv;

mkLib = shared:
stdenv.mkDerivation {
inherit name src;
nativeBuildInputs = with pkgs;
[cmake ninja doxygen pkg-config graphviz]
++ (
if compiler == "clang"
then [pkgs.clang]
else [pkgs.gcc]
);

buildInputs = with pkgs; [openssl];

cmakeFlags = [
"-GNinja"
"-DOQS_DIST_BUILD=ON"
"-DOQS_BUILD_ONLY_LIB=ON"
"-DBUILD_SHARED_LIBS=${
if shared
then "ON"
else "OFF"
}"
"-DCMAKE_INSTALL_LIBDIR=lib"
"-DCMAKE_INSTALL_INCLUDEDIR=include"
"-DCMAKE_INSTALL_PREFIX=${placeholder "out"}"
"-DCMAKE_INSTALL_FULL_LIBDIR=${placeholder "out"}/lib"
"-DCMAKE_INSTALL_FULL_INCLUDEDIR=${placeholder "out"}/include"
];
};
in {
shared = mkLib true;
static = mkLib false;
};

# Create development shell for specified compiler
mkDevShell = compiler: let
packageSet = mkPackageSet compiler;
in
pkgs.mkShell {
inherit (packageSet.shared) nativeBuildInputs buildInputs;

# astyle formats C source code and alejandra formats nix source code
packages = with pkgs; [astyle alejandra];

shellHook = ''
export CMAKE_EXPORT_COMPILE_COMMANDS=1
echo "Using ${compiler} toolchain"
'';
};
in {
packages = {
default = (mkPackageSet "gcc").shared; # default is gcc shared
gcc = mkPackageSet "gcc";
clang = mkPackageSet "clang";
};

# Development shells
devShells = {
default = mkDevShell "gcc";
gcc = mkDevShell "gcc";
clang = mkDevShell "clang";
};
});
}
Loading