-
Notifications
You must be signed in to change notification settings - Fork 521
/
Copy pathflake.nix
94 lines (84 loc) · 2.72 KB
/
flake.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
{
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;
# for whatever reason, trying to 'fix' the CMake file causes a failure
dontFixCmake = true;
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 {
formatter = pkgs.alejandra;
packages = {
default = (mkPackageSet "gcc").shared; # default is gcc shared
gcc-shared = (mkPackageSet "gcc").shared;
clang-shared = (mkPackageSet "clang").shared;
gcc-static = (mkPackageSet "gcc").static;
clang-static = (mkPackageSet "clang").static;
};
# Development shells
devShells = {
default = mkDevShell "gcc";
gcc = mkDevShell "gcc";
clang = mkDevShell "clang";
};
});
}