-
Notifications
You must be signed in to change notification settings - Fork 505
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
base: main
Are you sure you want to change the base?
Add Nix flake #1970
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
name: "Nix Flake Check" | ||
on: | ||
pull_request: | ||
push: | ||
jobs: | ||
tests: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
Check warning Code scanning / Scorecard Pinned-Dependencies Medium
score is 8: GitHub-owned GitHubAction not pinned by hash
Click Remediation section below to solve this issue |
||
- uses: cachix/install-nix-action@v27 | ||
Check warning Code scanning / Scorecard Pinned-Dependencies Medium
score is 8: third-party GitHubAction not pinned by hash
Click Remediation section below to solve this issue |
||
with: | ||
github_access_token: ${{ secrets.GITHUB_TOKEN }} | ||
- run: nix build # check that the build runs | ||
- run: nix flake check # check for accurate syntax |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,3 +37,6 @@ __pycache__ | |
.CMake/a.out | ||
compile_commands.json | ||
|
||
# Generated by Nix flake | ||
result/ | ||
|
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,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"; | ||
}; | ||
}); | ||
} |
Check failure
Code scanning / Scorecard
Token-Permissions High
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.
Hmm, this is a fair point - let me address this.