This commit is contained in:
Andrew Haynes
2026-03-26 11:09:34 -04:00
parent 9b8a883e68
commit 0a1d1c4607
+12 -15
View File
@@ -1,5 +1,5 @@
{ {
description = "A C library with a clean API"; description = "Image Processor C API";
inputs = { inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
@@ -9,37 +9,34 @@
self, self,
nixpkgs, nixpkgs,
}: let }: let
# Support for multiple systems (Linux and macOS)
supportedSystems = ["x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin"]; supportedSystems = ["x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin"];
forAllSystems = nixpkgs.lib.genAttrs supportedSystems; forAllSystems = nixpkgs.lib.genAttrs supportedSystems;
pkgsFor = system: import nixpkgs {inherit system;};
in { in {
# This is the actual library package
packages = forAllSystems (system: let packages = forAllSystems (system: let
pkgs = pkgsFor system; pkgs = import nixpkgs {inherit system;};
in { in {
default = pkgs.stdenv.mkDerivation { default = pkgs.stdenv.mkDerivation {
pname = "my-c-api"; pname = "image-processor";
version = "0.1.0"; version = "0.1.0";
src = ./.; src = ./.; # Since the flake is in the repo, we use local source
# Add dependencies here # nativeBuildInputs are tools needed at build time (like CMake)
nativeBuildInputs = [pkgs.cmake pkgs.pkg-config];
# buildInputs are libraries your API depends on (e.g., libpng, opencv)
buildInputs = []; buildInputs = [];
nativeBuildInputs = [pkgs.pkg-config];
# Nix expects a standard 'make install' by default. # Nix automatically runs: cmakeConfigurePhase, buildPhase, installPhase
# Ensure your Makefile handles $(DESTDIR)$(PREFIX) correctly. # You just need to ensure your CMakeLists.txt has 'install()' targets.
installFlags = ["PREFIX=$(out)"];
}; };
}); });
# This provides 'nix develop' for you to work on the API itself
devShells = forAllSystems (system: let devShells = forAllSystems (system: let
pkgs = pkgsFor system; pkgs = import nixpkgs {inherit system;};
in { in {
default = pkgs.mkShell { default = pkgs.mkShell {
inputsFrom = [self.packages.${system}.default]; inputsFrom = [self.packages.${system}.default];
packages = with pkgs; [gdb valgrind clang-tools]; packages = [pkgs.gdb];
}; };
}); });
}; };