{ description = "A C library with a clean API"; inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; }; outputs = { self, nixpkgs, }: let # Support for multiple systems (Linux and macOS) supportedSystems = ["x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin"]; forAllSystems = nixpkgs.lib.genAttrs supportedSystems; pkgsFor = system: import nixpkgs {inherit system;}; in { # This is the actual library package packages = forAllSystems (system: let pkgs = pkgsFor system; in { default = pkgs.stdenv.mkDerivation { pname = "my-c-api"; version = "0.1.0"; src = ./.; # Add dependencies here buildInputs = []; nativeBuildInputs = [pkgs.pkg-config]; # Nix expects a standard 'make install' by default. # Ensure your Makefile handles $(DESTDIR)$(PREFIX) correctly. installFlags = ["PREFIX=$(out)"]; }; }); # This provides 'nix develop' for you to work on the API itself devShells = forAllSystems (system: let pkgs = pkgsFor system; in { default = pkgs.mkShell { inputsFrom = [self.packages.${system}.default]; packages = with pkgs; [gdb valgrind clang-tools]; }; }); }; }