NIX: flake.nix for development environment

This commit is contained in:
Andrew Haynes
2026-03-26 00:57:00 -04:00
parent bf591f0c1b
commit 65241c1d06
7 changed files with 92 additions and 8 deletions
+19
View File
@@ -0,0 +1,19 @@
#!/usr/bin/env bash
set -e
if [[ ! -d "/Users/andrew/personal/Projects/C/image_processor" ]]; then
echo "Cannot find source directory; Did you move it?"
echo "(Looking for "/Users/andrew/personal/Projects/C/image_processor")"
echo 'Cannot force reload with this script - use "direnv reload" manually and then try again'
exit 1
fi
# rebuild the cache forcefully
_nix_direnv_force_reload=1 direnv exec "/Users/andrew/personal/Projects/C/image_processor" true
# Update the mtime for .envrc.
# This will cause direnv to reload again - but without re-building.
touch "/Users/andrew/personal/Projects/C/image_processor/.envrc"
# Also update the timestamp of whatever profile_rc we have.
# This makes sure that we know we are up to date.
touch -r "/Users/andrew/personal/Projects/C/image_processor/.envrc" "/Users/andrew/personal/Projects/C/image_processor/.direnv"/*.rc
+1
View File
@@ -0,0 +1 @@
/nix/store/yy3zc65ij95wfnap3zqcr44kc4wzwlbq-nix-shell-env
+1
View File
@@ -0,0 +1 @@
use nix
+11 -4
View File
@@ -14,9 +14,10 @@ set(LIB_SOURCES
src/imgio.c
)
# find_package(PkgConfig REQUIRED)
find_library(TURBOJPEG_LIB NAMES turbojpeg REQUIRED)
find_path(TURBOJPEG_INCLUDE NAMES turbojpeg.h REQUIRED)
find_package(PkgConfig REQUIRED)
pkg_check_modules(TURBOJPEG REQUIRED IMPORTED_TARGET libturbojpeg)
# find_library(TURBOJPEG_LIB NAMES turbojpeg REQUIRED)
# find_path(TURBOJPEG_INCLUDE NAMES turbojpeg.h REQUIRED)
add_library(PROCESSOR STATIC ${LIB_SOURCES})
@@ -28,5 +29,11 @@ target_include_directories(PROCESSOR
${TURBOJPEG_INCLUDE}
)
target_link_libraries(PROCESSOR PUBLIC ${TURBOJPEG_LIB})
# target_link_libraries(PROCESSOR PUBLIC ${TURBOJPEG_LIB})
target_link_libraries(PROCESSOR PUBLIC PkgConfig::TURBOJPEG)
set_target_properties(PROCESSOR PROPERTIES EXPORT_NAME PROCESSOR)
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
add_executable(image_processor src/main.c) # Assuming you have a main.c
target_link_libraries(image_processor PRIVATE PROCESSOR)
endif()
+43
View File
@@ -0,0 +1,43 @@
{
description = "Image Processor API";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
};
outputs = {
self,
nixpkgs,
}: let
supportedSystems = ["aarch64-darwin" "x86_64-darwin" "x86_64-linux"];
forAllSystems = nixpkgs.lib.genAttrs supportedSystems;
pkgsFor = system: import nixpkgs {inherit system;};
in {
# This allows other flakes to "consume" this library
packages = forAllSystems (system: let
pkgs = pkgsFor system;
in {
default = pkgs.stdenv.mkDerivation {
pname = "image_processor";
version = "0.1.0";
src = ./.;
nativeBuildInputs = [pkgs.cmake pkgs.pkg-config];
buildInputs = [pkgs.libjpeg_turbo];
};
});
# This provides the dev environment for the API itself
devShells = forAllSystems (system: let
pkgs = pkgsFor system;
in {
default = pkgs.mkShell {
nativeBuildInputs = [pkgs.cmake pkgs.pkg-config];
buildInputs = [pkgs.libjpeg_turbo];
shellHook = ''
export CPATH="${pkgs.libjpeg_turbo.dev}/include:$CPATH"
echo "⚙️ Image Processor API Dev Shell"
'';
};
});
};
}
+14
View File
@@ -0,0 +1,14 @@
{pkgs ? import <nixpkgs> {}}:
pkgs.mkShell {
nativeBuildInputs = with pkgs; [
cmake
pkg-config
];
buildInputs = with pkgs; [
libjpeg_turbo
];
# This tells pkg-config where the Nix libraries are automatically
shellHook = ''
echo "Image Processor Dev Environment Loaded"
'';
}
+3 -4
View File
@@ -1,9 +1,8 @@
#include <stdlib.h>
#include <time.h>
#include "utils.h"
#include "filters.h"
#include "image/utils.h"
#include "image/filters.h"
// #include "transformations.h"
#include "imgio.h"
#include "image/imgio.h"
int
main()