From c4917504942645119dc2fbe407dfb237790d1b86 Mon Sep 17 00:00:00 2001 From: Christoph Urlacher Date: Mon, 12 Jan 2026 23:26:06 +0100 Subject: [PATCH] nixos: add wip FAIL* package derivation to flake.nix --- flake.lock | 119 +------------------- flake.nix | 315 ++++++++++++++++++++++++++++------------------------- 2 files changed, 167 insertions(+), 267 deletions(-) diff --git a/flake.lock b/flake.lock index 42161fca..0a3e7603 100644 --- a/flake.lock +++ b/flake.lock @@ -1,66 +1,5 @@ { "nodes": { - "clj-nix": { - "inputs": { - "devshell": "devshell", - "nix-fetcher-data": "nix-fetcher-data", - "nixpkgs": [ - "nixpkgs" - ] - }, - "locked": { - "lastModified": 1767127926, - "narHash": "sha256-x7ySkkTG3dPi6jMhkPVten3pQCIzllRzcFqJ/tRQSFY=", - "owner": "jlesquembre", - "repo": "clj-nix", - "rev": "86c0312e9abcc46e3b4168c1b8ac1daebad5ddb6", - "type": "github" - }, - "original": { - "owner": "jlesquembre", - "repo": "clj-nix", - "type": "github" - } - }, - "devshell": { - "inputs": { - "nixpkgs": [ - "clj-nix", - "nixpkgs" - ] - }, - "locked": { - "lastModified": 1741473158, - "narHash": "sha256-kWNaq6wQUbUMlPgw8Y+9/9wP0F8SHkjy24/mN3UAppg=", - "owner": "numtide", - "repo": "devshell", - "rev": "7c9e793ebe66bcba8292989a68c0419b737a22a0", - "type": "github" - }, - "original": { - "owner": "numtide", - "repo": "devshell", - "type": "github" - } - }, - "flake-parts": { - "inputs": { - "nixpkgs-lib": "nixpkgs-lib" - }, - "locked": { - "lastModified": 1719745305, - "narHash": "sha256-xwgjVUpqSviudEkpQnioeez1Uo2wzrsMaJKJClh+Bls=", - "owner": "hercules-ci", - "repo": "flake-parts", - "rev": "c3c5ecc05edc7dafba779c6c1a61cd08ac6583e9", - "type": "github" - }, - "original": { - "owner": "hercules-ci", - "repo": "flake-parts", - "type": "github" - } - }, "flake-utils": { "inputs": { "systems": "systems" @@ -79,28 +18,6 @@ "type": "github" } }, - "nix-fetcher-data": { - "inputs": { - "flake-parts": "flake-parts", - "nixpkgs": [ - "clj-nix", - "nixpkgs" - ] - }, - "locked": { - "lastModified": 1728229178, - "narHash": "sha256-p5Fx880uBYstIsbaDYN7sECJT11oHxZQKtHgMAVblWA=", - "owner": "jlesquembre", - "repo": "nix-fetcher-data", - "rev": "f3a73c34d28db49ef90fd7872a142bfe93120e55", - "type": "github" - }, - "original": { - "owner": "jlesquembre", - "repo": "nix-fetcher-data", - "type": "github" - } - }, "nixpkgs": { "locked": { "lastModified": 1768032153, @@ -115,44 +32,10 @@ "type": "indirect" } }, - "nixpkgs-lib": { - "locked": { - "lastModified": 1717284937, - "narHash": "sha256-lIbdfCsf8LMFloheeE6N31+BMIeixqyQWbSr2vk79EQ=", - "type": "tarball", - "url": "https://github.com/NixOS/nixpkgs/archive/eb9ceca17df2ea50a250b6b27f7bf6ab0186f198.tar.gz" - }, - "original": { - "type": "tarball", - "url": "https://github.com/NixOS/nixpkgs/archive/eb9ceca17df2ea50a250b6b27f7bf6ab0186f198.tar.gz" - } - }, "root": { "inputs": { - "clj-nix": "clj-nix", "flake-utils": "flake-utils", - "nixpkgs": "nixpkgs", - "rust-overlay": "rust-overlay" - } - }, - "rust-overlay": { - "inputs": { - "nixpkgs": [ - "nixpkgs" - ] - }, - "locked": { - "lastModified": 1768100056, - "narHash": "sha256-2GWCrsoWIuEXrzdKR2DPnoDhA5SqW7CGNO+Absni054=", - "owner": "oxalica", - "repo": "rust-overlay", - "rev": "71a69fd633552550de7cb05cc149e4a99ff6f3b6", - "type": "github" - }, - "original": { - "owner": "oxalica", - "repo": "rust-overlay", - "type": "github" + "nixpkgs": "nixpkgs" } }, "systems": { diff --git a/flake.nix b/flake.nix index c3fa63da..9b69ff98 100644 --- a/flake.nix +++ b/flake.nix @@ -1,32 +1,22 @@ rec { - description = ""; + description = "FAIL* - Fault Injection Leveraged"; inputs = { nixpkgs.url = "nixpkgs"; # Use nixpkgs from system registry flake-utils.url = "github:numtide/flake-utils"; - - rust-overlay.url = "github:oxalica/rust-overlay"; - rust-overlay.inputs.nixpkgs.follows = "nixpkgs"; - - clj-nix.url = "github:jlesquembre/clj-nix"; - clj-nix.inputs.nixpkgs.follows = "nixpkgs"; }; outputs = { self, nixpkgs, flake-utils, - rust-overlay, - clj-nix, }: # Create a shell (and possibly package) for each possible system, not only x86_64-linux flake-utils.lib.eachDefaultSystem (system: let pkgs = import nixpkgs { inherit system; config.allowUnfree = true; - overlays = [ - rust-overlay.overlays.default - ]; + overlays = []; }; inherit (pkgs) lib stdenv; @@ -34,57 +24,28 @@ rec { # Define custom dependencies # =========================================================================================== - # Python package example - # typed-ffmpeg = pkgs.python313Packages.buildPythonPackage rec { - # pname = "typed_ffmpeg"; - # version = "3.6"; - # - # src = pkgs.python313Packages.fetchPypi { - # inherit pname version; - # hash = "sha256-YPspq/lqI/jx/9FCQntmQPw4lrPIsdxtHTUg0F0QbrM="; - # }; - # - # pyproject = true; - # build-system = [ - # pkgs.python313Packages.setuptools - # pkgs.python313Packages.setuptools-scm - # ]; - # }; - - # python = pkgs.python313.withPackages (p: - # with p; [ - # # numpy - # # matplotlib - # # typed-ffmpeg - # # pyside6 - # ]); - - # rust = pkgs.rust-bin.stable.latest.default.override { - # extensions = ["rust-src"]; # Include the Rust stdlib source (for IntelliJ) - # }; - # 64 bit C/C++ compilers that don't collide (use the same libc) - # bintools = pkgs.wrapBintoolsWith { - # bintools = pkgs.bintools.bintools; # Unwrapped bintools - # libc = pkgs.glibc; - # }; - # gcc = pkgs.hiPrio (pkgs.wrapCCWith { - # cc = pkgs.gcc.cc; # Unwrapped gcc - # libc = pkgs.glibc; - # bintools = bintools; - # }); - # clang = pkgs.wrapCCWith { - # cc = pkgs.clang.cc; # Unwrapped clang - # libc = pkgs.glibc; - # bintools = bintools; - # }; + bintools = pkgs.wrapBintoolsWith { + bintools = pkgs.bintools.bintools; # Unwrapped bintools + libc = pkgs.glibc; + }; + gcc = lib.hiPrio (pkgs.wrapCCWith { + cc = pkgs.gcc.cc; # Unwrapped gcc + libc = pkgs.glibc; + bintools = bintools; + }); + clang = pkgs.wrapCCWith { + cc = pkgs.clang.cc; # Unwrapped clang + libc = pkgs.glibc; + bintools = bintools; + }; # Multilib C/C++ compilers that don't collide (use the same libc) # bintools_multilib = pkgs.wrapBintoolsWith { # bintools = pkgs.bintools.bintools; # Unwrapped bintools # libc = pkgs.glibc_multi; # }; - # gcc_multilib = pkgs.hiPrio (pkgs.wrapCCWith { + # gcc_multilib = lib.hiPrio (pkgs.wrapCCWith { # cc = pkgs.gcc.cc; # Unwrapped gcc # libc = pkgs.glibc_multi; # bintools = bintools_multilib; @@ -95,6 +56,84 @@ rec { # bintools = bintools_multilib; # }; + aspectcxx = stdenv.mkDerivation rec { + pname = "aspectcxx"; + version = "1.2"; + + src = pkgs.fetchurl { + url = "http://www.aspectc.org/releases/${version}/ac-bin-linux-x86-64bit-${version}.tar.gz"; + sha256 = "sha256-8wOrPYC99E3aV5/Js2EBI4V/OoD9y10fYZt8ikPtvt4="; # 1.2 + # sha256 = "sha256-gmqoZFkPvs60b6yuMHNtYvuGJXGnbwAYEiyXxp/fmPI="; # 2.0 + # sha256 = "sha256-+rEflemXNwn4XZZwSOqCsr6/KFGV8wxW6PeXzHHUK0o="; # 2.5 + }; + + nativeBuildInputs = [ + pkgs.autoPatchelfHook + ]; + + unpackPhase = '' + tar xvzf $src + ''; + + installPhase = '' + mkdir -p $out/bin + cp aspectc++/ac++ $out/bin/ + cp aspectc++/ag++ $out/bin/ + ''; + }; + + libpcl = stdenv.mkDerivation rec { + pname = "libpcl"; + version = "1.12-2"; + + src = pkgs.fetchurl { + url = "https://launchpadlibrarian.net/521269537/libpcl1_1.12-2_amd64.deb"; + sha256 = "sha256-GL3mjPAccAtRMAJPnDMCHiDf6xNvGi4oUWylOIqBjP0="; + }; + + nativeBuildInputs = with pkgs; [ + dpkg + autoPatchelfHook + ]; + + unpackPhase = '' + dpkg-deb -x $src . + ''; + + installPhase = '' + mkdir -p $out + cp -r usr/* $out/ + ''; + }; + + libpcl-dev = stdenv.mkDerivation rec { + pname = "libpcl-dev"; + version = "1.12-2"; + + src = pkgs.fetchurl { + url = "https://launchpadlibrarian.net/521269536/libpcl1-dev_${version}_amd64.deb"; + sha256 = "sha256-Z1wP0K8hfV1f9ypee9XIx6H0JOTidhtXDBe82mlRaOg="; + }; + + nativeBuildInputs = with pkgs; [ + dpkg + autoPatchelfHook + ]; + + unpackPhase = '' + dpkg-deb -x $src . + ''; + + installPhase = '' + mkdir -p $out + cp -r usr/* $out/ + + # Hacky bullshit + cp ${libpcl}/lib/x86_64-linux-gnu/libpcl.so.1.0.11 $out/lib/x86_64-linux-gnu/libpcl.so.1.0.11 + rm $out/share/doc/libpcl1-dev/changelog.Debian.gz + ''; + }; + # =========================================================================================== # Specify dependencies # https://nixos.org/manual/nixpkgs/stable/#ssec-stdenv-dependencies-overview @@ -107,37 +146,16 @@ rec { # - Interpreters needed by patchShebangs for build scripts (with the --build flag), which can be the case for e.g. perl nativeBuildInputs = with pkgs; [ # Languages: - # python - # rust - # bintools - # gcc + bintools + gcc # clang - # bintools_multilib - # gcc_multilib - # clang_multilib - # clojure - # jdk + aspectcxx # C/C++: - # gdb - # valgrind gnumake - # cmake - # pkg-config - - # Clojure: - # leiningen - # clj-nix.packages.${system}.deps-lock - - # Java: - # gradle - - # Python: - # hatch - # py-spy - - # Qt: - # qt6.wrapQtAppsHook # For the shellHook + cmake + pkg-config + doxygen ]; # Add dependencies to buildInputs if they will end up copied or linked into the final output or otherwise used at runtime: @@ -145,50 +163,77 @@ rec { # - Interpreters needed by patchShebangs for scripts which are installed, which can be the case for e.g. perl buildInputs = with pkgs; [ # C/C++: - # boost - # sfml + libpcl-dev + libiberty + libelf + libdwarf + boost - # Qt: - # qt6.qtbase - # qt6.full + llvmPackages_18.llvm + mariadb-connector-c + fontconfig + zlib + capstone + protobuf + binutils + + # No clue what I need from those + xorg.libX11 + xorg.libXext + xorg.libXrender + xorg.libXrandr + xorg.libXinerama + xorg.libXcursor + xorg.libXi + xorg.libXfixes ]; # =========================================================================================== # Define buildable + installable packages # =========================================================================================== - # package = stdenv.mkDerivation { - # inherit nativeBuildInputs buildInputs; - # pname = ""; - # version = "1.0.0"; - # src = ./.; - # - # installPhase = '' - # mkdir -p $out/bin - # mv ./BINARY $out/bin - # ''; - # }; - # package = clj-nix.lib.mkCljApp { - # inherit pkgs; - # modules = [ - # # Option list: https://jlesquembre.github.io/clj-nix/options/ - # { - # name = ""; - # version = "1.0.0"; - # main-ns = ""; - # projectSrc = ./.; - # withLeiningen = true; - # buildCommand = "lein uberjar"; # Requires "withLeiningen = true;" - # jdk = pkgs.jdk; # Default is pkgs.jdk_headless - # # customJdk.enable = true; - # # nativeImage.enable = true; - # } - # ]; - # }; + package = stdenv.mkDerivation { + inherit nativeBuildInputs buildInputs; + pname = "fail"; + version = "1.0.1"; + src = ./.; + + enableParallelBuilding = true; + + cmakeFlags = [ + # Our CMake is too new :( Try it anyway, can still downgrade later... + "-DCMAKE_POLICY_VERSION_MINIMUM=3.5" + + # AspectC++ + # "-DCMAKE_AGPP_FLAGS=--c_compiler${clang}/bin/clang++" + "-DCMAKE_AGPP_FLAGS=-D__NO_MATH_INLINES" + # "-DCMAKE_AGPP_FLAGS=--c_compiler${clang}/bin/clang++ -D__NO_MATH_INLINES -D__STRICT_ANSI__" + + # Tell CMake where the libs are + "-DLibIberty_INCLUDE_DIRS=${pkgs.libiberty}/include" + "-DLibIberty_LIBRARIES=${pkgs.libiberty}/lib/libiberty.a" + + "-DLIBELF_INCLUDE_DIRS=${pkgs.libelf}/include" + "-DLIBELF_LIBRARIES=${pkgs.libelf}/lib/libelf.a" + + "-DLIBDWARF_INCLUDE_DIRS=${pkgs.libdwarf}/include" + "-DLIBDWARF_LIBRARIES=${pkgs.libdwarf}/lib/libdwarf.a" + + "-DCAPSTONE_INCLUDE_DIR=${pkgs.capstone}/include" + "-DCAPSTONE_LIBRARY=${pkgs.capstone}/lib/libcapstone.a" + + "-DLIBPCL_LIBRARIES=${libpcl-dev}/lib/libpcl.a" + ]; + + installPhase = '' + mkdir -p $out/bin + mv ./fail $out/bin/ + ''; + }; in rec { # Provide package for "nix build" - # defaultPackage = package; - # defaultApp = flake-utils.lib.mkApp { - # drv = defaultPackage; - # }; + defaultPackage = package; + defaultApp = flake-utils.lib.mkApp { + drv = defaultPackage; + }; # Provide environment for "nix develop" devShell = pkgs.mkShell { @@ -199,9 +244,6 @@ rec { # Define environment variables # ========================================================================================= - # Rust stdlib source: - # RUST_SRC_PATH = "${rust}/lib/rustlib/src/rust/library"; - # Custom dynamic libraries: # LD_LIBRARY_PATH = builtins.concatStringsSep ":" [ # # Rust Bevy GUI app: @@ -219,13 +261,7 @@ rec { # ]; # Dynamic libraries from buildinputs: - # LD_LIBRARY_PATH = nixpkgs.lib.makeLibraryPath buildInputs; - - # QT imports to use with "qmlls -E" - # QML_IMPORT_PATH = "${pkgs.qt6.full}/lib/qt-6/qml"; - - # Set PYTHONPATH - # PYTHONPATH = "."; + LD_LIBRARY_PATH = nixpkgs.lib.makeLibraryPath buildInputs; # Set matplotlib backend # MPLBACKEND = "TkAgg"; @@ -280,22 +316,11 @@ rec { # Determine the project root, used e.g. in cmake scripts set -g -x FLAKE_PROJECT_ROOT (git rev-parse --show-toplevel) - # Rust Bevy: - # abbr -a build-release-windows "CARGO_FEATURE_PURE=1 cargo xwin build --release --target x86_64-pc-windows-msvc" - # C/C++: # abbr -a cmake-debug "${cmakeDebug}" # abbr -a cmake-release "${cmakeRelease}" # abbr -a build-debug "${buildDebug}" # abbr -a build-release "${buildRelease}" - - # Clojure: - # abbr -a clojure-deps "deps-lock --lein" - - # Python: - # abbr -a run "python ./app/main.py" - # abbr -a profile "py-spy record -o profile.svg -- python ./app/main.py && firefox profile.svg" - # abbr -a ptop "py-spy top -- python ./app/main.py" ''; in builtins.concatStringsSep "\n" [ @@ -303,14 +328,6 @@ rec { '' exec "$(type -p fish)" -C "source ${initProjectShell} && abbr -a menu '${pkgs.bat}/bin/bat "${initProjectShell}"'" '' - - # Qt: Launch into wrapped fish shell - # https://nixos.org/manual/nixpkgs/stable/#sec-language-qt - # '' - # fishdir=$(mktemp -d) - # makeWrapper "$(type -p fish)" "$fishdir/fish" "''${qtWrapperArgs[@]}" - # exec "$fishdir/fish" -C "source ${initProjectShell} && abbr -a menu '${pkgs.bat}/bin/bat "${initProjectShell}"'" - # '' ]; }; });