diff --git a/CHANGELOG.md b/CHANGELOG.md
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -5,6 +5,16 @@
 
 The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
 
+## 0.2.1.2 - 2022-03-07
+
+### Fixed
+
+ - Build with newer Nix versions 2.5, 2.6
+
+### Added
+
+ - Improved conditional code support with `cabal-pkg-config-version-hook`
+
 ## 0.2.1.1 - 2021-11-17
 
 ### Fixed
diff --git a/Setup.hs b/Setup.hs
new file mode 100644
--- /dev/null
+++ b/Setup.hs
@@ -0,0 +1,13 @@
+import Data.Function ((&))
+import Distribution.PkgConfigVersionHook as PV
+import Distribution.Simple
+
+main :: IO ()
+main =
+  defaultMainWithHooks $
+    simpleUserHooks
+      & PV.addHook
+        (PV.mkSettings "nix-store")
+          { PV.macroName = "NIX",
+            PV.flagPrefixName = "nix"
+          }
diff --git a/hercules-ci-cnix-store.cabal b/hercules-ci-cnix-store.cabal
--- a/hercules-ci-cnix-store.cabal
+++ b/hercules-ci-cnix-store.cabal
@@ -1,7 +1,7 @@
 cabal-version: 2.4
 
 name:           hercules-ci-cnix-store
-version:        0.2.1.1
+version:        0.2.1.2
 synopsis:       Haskell bindings for Nix's libstore
 category:       Nix
 homepage:       https://docs.hercules-ci.com
@@ -10,7 +10,7 @@
 maintainer:     info@hercules-ci.com
 copyright:      2018-2020 Hercules CI
 license:        Apache-2.0
-build-type:     Simple
+build-type:     Custom
 extra-source-files:
     CHANGELOG.md
     test/data/*.drv
@@ -48,6 +48,12 @@
     if os(darwin)
       ghc-options: -pgmc=clang++
 
+custom-setup
+  setup-depends:
+    base
+    , Cabal >= 2.2.0.0
+    , cabal-pkg-config-version-hook
+
 library
   import: cxx-opts
   exposed-modules:
@@ -65,20 +71,17 @@
       Hercules.CNix.Util
   include-dirs:
       include
+  pkgconfig-depends:
+      nix-store >= 2.3 && < 2.8
+    , nix-main >= 2.3 && < 2.8
   if flag(nix-2_4)
     include-dirs:
         compat-2.4/include
-    cpp-options:
-        -DNIX_2_4
-    pkgconfig-depends:
-        nix-store >= 2.4
-      , nix-main >= 2.4
+    cpp-options: -DNIX_2_4
+    cxx-options: -DNIX_2_4
   else
     include-dirs:
         compat-2.3/include
-    pkgconfig-depends:
-        nix-store >= 2.0 && <2.4
-      , nix-main >= 2.0 && <2.4
     cxx-sources:
         compat-2.3/derivation-output.cxx
         compat-2.3/path.cxx
diff --git a/src/Hercules/CNix.hs b/src/Hercules/CNix.hs
--- a/src/Hercules/CNix.hs
+++ b/src/Hercules/CNix.hs
@@ -37,8 +37,6 @@
 
 C.include "<nix/derivations.hh>"
 
-C.include "<nix/affinity.hh>"
-
 C.include "<nix/globals.hh>"
 
 C.include "hercules-ci-cnix/store.hxx"
diff --git a/src/Hercules/CNix/Store.hs b/src/Hercules/CNix/Store.hs
--- a/src/Hercules/CNix/Store.hs
+++ b/src/Hercules/CNix/Store.hs
@@ -65,8 +65,6 @@
 
 C.include "<nix/derivations.hh>"
 
-C.include "<nix/affinity.hh>"
-
 C.include "<nix/globals.hh>"
 
 C.include "<nix/path.hh>"
diff --git a/src/Hercules/CNix/Util.hs b/src/Hercules/CNix/Util.hs
--- a/src/Hercules/CNix/Util.hs
+++ b/src/Hercules/CNix/Util.hs
@@ -27,8 +27,6 @@
 
 C.include "<nix/config.h>"
 
-C.include "<nix/affinity.hh>"
-
 C.include "<nix/util.hh>"
 
 C.using "namespace nix"
