Skip to content

Commit

Permalink
Add Nix flake
Browse files Browse the repository at this point in the history
Using it for CI is much more elegant than the current Ubuntu PPA
dumpster fire plus we can easily run it locally.
  • Loading branch information
vimpostor committed Nov 23, 2024
1 parent 5f835e0 commit 900388b
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 15 deletions.
19 changes: 5 additions & 14 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,10 @@ name: Continuous Integration
on: [push, pull_request]
jobs:
build:
strategy:
matrix:
cxx: [g++, clang++]
runs-on: ubuntu-latest
env:
CXX: ${{ matrix.cxx }}
steps:
- uses: actions/checkout@v3
- name: Install dependencies
run: sudo apt install -y libseccomp-dev && sudo add-apt-repository ppa:ubuntu-toolchain-r/test && sudo apt-get update && sudo apt-get -y install gcc-14 && sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-14 30
- name: Configure the project
run: cmake -B build -DCMAKE_BUILD_TYPE=Debug
- name: Build the project
run: cmake --build build
- name: Run tests
run: tests/run-tests.sh
- uses: actions/checkout@v4
- uses: cachix/install-nix-action@v27
with:
nix_path: nixpkgs=channel:nixos-unstable
- run: nix flake check --print-build-logs
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.21)
project(copycat)
project(copycat VERSION 0.1)

set(LIB_TARGET "${PROJECT_NAME}")
set(BIN_TARGET "${PROJECT_NAME}-bin")
Expand Down
45 changes: 45 additions & 0 deletions flake.lock

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

32 changes: 32 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
description = "A library for intercepting system calls";
inputs = {
quartz.url = "github:vimpostor/quartz";
};

outputs = { self, quartz }: quartz.lib.eachSystem (system:
let
pkgs = quartz.inputs.nixpkgs.legacyPackages.${system};
stdenvs = [ { name = "gcc"; pkg = pkgs.gcc14Stdenv; } { name = "clang"; pkg = pkgs.llvmPackages_18.stdenv; } ];
defaultStdenv = (builtins.head stdenvs).name;
makeStdenvPkg = env: env.mkDerivation {
pname = "copycat";
version = quartz.lib.cmakeProjectVersion ./CMakeLists.txt;

src = ./.;

nativeBuildInputs = with pkgs; [
cmake
libseccomp
];
};
in {
packages = {
default = self.outputs.packages.${system}.${defaultStdenv};
} // builtins.listToAttrs (map (x: { name = x.name; value = makeStdenvPkg x.pkg; }) stdenvs);
checks = {
format = pkgs.runCommand "format" { src = ./.; nativeBuildInputs = [ pkgs.clang-tools pkgs.git ]; } "mkdir $out && cd $src && find . -type f -path './*\\.[hc]pp' -exec clang-format -style=file --dry-run --Werror {} \\;";
} // builtins.listToAttrs (map (x: { name = "tests-" + x.name; value = (makeStdenvPkg x.pkg); }) stdenvs);
}
);
}

0 comments on commit 900388b

Please sign in to comment.