From 900388b49f815a2723c108699440eaa908b23109 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Magnus=20Gro=C3=9F?= Date: Sat, 23 Nov 2024 12:34:56 +0100 Subject: [PATCH] Add Nix flake Using it for CI is much more elegant than the current Ubuntu PPA dumpster fire plus we can easily run it locally. --- .github/workflows/ci.yml | 19 +++++------------ CMakeLists.txt | 2 +- flake.lock | 45 ++++++++++++++++++++++++++++++++++++++++ flake.nix | 32 ++++++++++++++++++++++++++++ 4 files changed, 83 insertions(+), 15 deletions(-) create mode 100644 flake.lock create mode 100644 flake.nix diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index cebc53e..dc1f62f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 diff --git a/CMakeLists.txt b/CMakeLists.txt index 5ef86de..8d5e1f3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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") diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..a69044d --- /dev/null +++ b/flake.lock @@ -0,0 +1,45 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1731139594, + "narHash": "sha256-IigrKK3vYRpUu+HEjPL/phrfh7Ox881er1UEsZvw9Q4=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "76612b17c0ce71689921ca12d9ffdc9c23ce40b2", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "quartz": { + "inputs": { + "nixpkgs": "nixpkgs" + }, + "locked": { + "lastModified": 1731874527, + "narHash": "sha256-nW8217HOB/bDVrAsuEfntkf5EkC5EJO6qL2818jB12s=", + "owner": "vimpostor", + "repo": "quartz", + "rev": "921e7c763416b38ae754a6f0afc223b328cdecac", + "type": "github" + }, + "original": { + "owner": "vimpostor", + "repo": "quartz", + "type": "github" + } + }, + "root": { + "inputs": { + "quartz": "quartz" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..cf7e14e --- /dev/null +++ b/flake.nix @@ -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); + } + ); +}