diff --git a/Cargo.lock b/Cargo.lock
index d518eb85..1362937a 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -83,6 +83,7 @@ dependencies = [
  "rustix",
  "strum",
  "strum_macros",
+ "system-deps",
  "udev",
  "uuid",
  "zeroize",
@@ -160,6 +161,16 @@ dependencies = [
  "nom",
 ]
 
+[[package]]
+name = "cfg-expr"
+version = "0.17.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d0890061c4d3223e7267f3bad2ec40b997d64faac1c2815a4a9d95018e2b9e9c"
+dependencies = [
+ "smallvec",
+ "target-lexicon",
+]
+
 [[package]]
 name = "cfg-if"
 version = "1.0.0"
@@ -248,6 +259,12 @@ dependencies = [
  "log",
 ]
 
+[[package]]
+name = "equivalent"
+version = "1.0.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5"
+
 [[package]]
 name = "errno"
 version = "0.2.8"
@@ -285,6 +302,12 @@ version = "0.3.1"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b"
 
+[[package]]
+name = "hashbrown"
+version = "0.15.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "1e087f84d4f86bf4b218b927129862374b72199ae7d8657835f1e89000eea4fb"
+
 [[package]]
 name = "heck"
 version = "0.5.0"
@@ -300,6 +323,16 @@ dependencies = [
  "windows-sys 0.52.0",
 ]
 
+[[package]]
+name = "indexmap"
+version = "2.6.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "707907fe3c25f5424cce2cb7e1cbcafee6bdbe735ca90ef77c29e84591e5b9da"
+dependencies = [
+ "equivalent",
+ "hashbrown",
+]
+
 [[package]]
 name = "is_terminal_polyfill"
 version = "1.70.1"
@@ -493,12 +526,47 @@ version = "1.0.17"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "955d28af4278de8121b7ebeb796b6a45735dc01436d898801014aced2773a3d6"
 
+[[package]]
+name = "serde"
+version = "1.0.210"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "c8e3592472072e6e22e0a54d5904d9febf8508f65fb8552499a1abc7d1078c3a"
+dependencies = [
+ "serde_derive",
+]
+
+[[package]]
+name = "serde_derive"
+version = "1.0.210"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn",
+]
+
+[[package]]
+name = "serde_spanned"
+version = "0.6.8"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "87607cb1398ed59d48732e575a4c28a7a8ebf2454b964fe3f224f2afc07909e1"
+dependencies = [
+ "serde",
+]
+
 [[package]]
 name = "shlex"
 version = "1.3.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64"
 
+[[package]]
+name = "smallvec"
+version = "1.13.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67"
+
 [[package]]
 name = "strsim"
 version = "0.11.1"
@@ -538,6 +606,25 @@ dependencies = [
  "unicode-ident",
 ]
 
+[[package]]
+name = "system-deps"
+version = "7.0.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "66d23aaf9f331227789a99e8de4c91bf46703add012bdfd45fdecdfb2975a005"
+dependencies = [
+ "cfg-expr",
+ "heck",
+ "pkg-config",
+ "toml",
+ "version-compare",
+]
+
+[[package]]
+name = "target-lexicon"
+version = "0.12.16"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "61c41af27dd6d1e27b1b16b489db798443478cef1f06a660c96db617ba5de3b1"
+
 [[package]]
 name = "terminal_size"
 version = "0.4.0"
@@ -548,6 +635,40 @@ dependencies = [
  "windows-sys 0.59.0",
 ]
 
+[[package]]
+name = "toml"
+version = "0.8.19"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a1ed1f98e3fdc28d6d910e6737ae6ab1a93bf1985935a1193e68f93eeb68d24e"
+dependencies = [
+ "serde",
+ "serde_spanned",
+ "toml_datetime",
+ "toml_edit",
+]
+
+[[package]]
+name = "toml_datetime"
+version = "0.6.8"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "0dd7358ecb8fc2f8d014bf86f6f638ce72ba252a2c3a2572f2a795f1d23efb41"
+dependencies = [
+ "serde",
+]
+
+[[package]]
+name = "toml_edit"
+version = "0.22.22"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "4ae48d6208a266e853d946088ed816055e556cc6028c5e8e2b84d9fa5dd7c7f5"
+dependencies = [
+ "indexmap",
+ "serde",
+ "serde_spanned",
+ "toml_datetime",
+ "winnow",
+]
+
 [[package]]
 name = "udev"
 version = "0.7.0"
@@ -577,6 +698,12 @@ version = "1.10.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "81dfa00651efa65069b0b6b651f4aaa31ba9e3c3ce0137aaad053604ee7e0314"
 
+[[package]]
+name = "version-compare"
+version = "0.2.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "852e951cb7832cb45cb1169900d19760cfa39b82bc0ea9c0e5a14ae88411c98b"
+
 [[package]]
 name = "which"
 version = "4.4.2"
@@ -693,6 +820,15 @@ version = "0.52.6"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec"
 
+[[package]]
+name = "winnow"
+version = "0.6.20"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "36c1fec1a2bb5866f07c25f68c26e565c4c200aebb96d7e55710c19d3e8ac49b"
+dependencies = [
+ "memchr",
+]
+
 [[package]]
 name = "zeroize"
 version = "1.8.1"
diff --git a/Cargo.toml b/Cargo.toml
index 54b6ec35..7ae1b2df 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -33,5 +33,21 @@ owo-colors = "4"
 version = "0.10"
 default-features = false
 
+[build-dependencies]
+system-deps = "7"
+
+[package.metadata.system-deps]
+# libaio is missing a pkg-config file
+blkid = "2.40.1"
+fuse3 = { version = "3.14", feature = "fuse" }
+libkeyutils = "1.6.3"
+liblz4 = "1.9.4"
+libsodium = "1.0.18"
+libudev = "252"
+liburcu = "0.13"
+libzstd = "1.5.4"
+uuid = "2.40.1"
+zlib = "1.2.13"
+
 [profile.release]
 strip = "none"
diff --git a/build.rs b/build.rs
index 25f4f5be..b0cbd05f 100644
--- a/build.rs
+++ b/build.rs
@@ -3,19 +3,8 @@ fn main() {
     println!("cargo:rerun-if-changed=libbcachefs.a");
     println!("cargo:rustc-link-lib=static:+whole-archive=bcachefs");
 
-    println!("cargo:rustc-link-lib=urcu");
-    println!("cargo:rustc-link-lib=zstd");
-    println!("cargo:rustc-link-lib=blkid");
-    println!("cargo:rustc-link-lib=uuid");
-    println!("cargo:rustc-link-lib=sodium");
-    println!("cargo:rustc-link-lib=z");
-    println!("cargo:rustc-link-lib=lz4");
-    println!("cargo:rustc-link-lib=zstd");
-    println!("cargo:rustc-link-lib=udev");
-    println!("cargo:rustc-link-lib=keyutils");
+    // libaio is missing a pkg-config file
     println!("cargo:rustc-link-lib=aio");
 
-    if std::env::var("BCACHEFS_FUSE").is_ok() {
-        println!("cargo:rustc-link-lib=fuse3");
-    }
+    system_deps::Config::new().probe().unwrap();
 }
diff --git a/debian/control b/debian/control
index 9e5ff022..865aab34 100644
--- a/debian/control
+++ b/debian/control
@@ -14,7 +14,6 @@ Build-Depends: debhelper-compat (= 13),
                libblkid-dev,
                libkeyutils-dev,
                liblz4-dev,
-               libscrypt-dev,
                libsodium-dev,
                libudev-dev,
                liburcu-dev,
diff --git a/flake.nix b/flake.nix
index 1200a3b9..c83a3b8b 100644
--- a/flake.nix
+++ b/flake.nix
@@ -55,9 +55,20 @@
           inherit (lib.lists) findFirst;
           inherit (lib.strings) hasPrefix removePrefix substring;
 
+          myOverlays = [
+            (import rust-overlay)
+            (_: prev: {
+              util-linux = prev.util-linux.override {
+                ncursesSupport = false;
+                nlsSupport = false;
+                pamSupport = false;
+                systemdSupport = false;
+              };
+            })
+          ];
           pkgs = import nixpkgs {
             inherit system;
-            overlays = [ (import rust-overlay) ];
+            overlays = myOverlays;
           };
 
           cargoToml = builtins.fromTOML (builtins.readFile ./Cargo.toml);
@@ -89,6 +100,7 @@
               libuuid,
               lz4,
               udev,
+              util-linux,
               zlib,
               zstd,
             }:
@@ -139,6 +151,7 @@
                   libuuid
                   lz4
                   udev
+                  util-linux
                   zlib
                   zstd
                 ];
@@ -194,7 +207,7 @@
                   localSystem = system;
                   pkgs' = import nixpkgs {
                     inherit crossSystem localSystem;
-                    overlays = [ (import rust-overlay) ];
+                    overlays = myOverlays;
                   };
 
                   common = pkgs'.callPackage mkCommon { inherit crane; };
@@ -229,7 +242,7 @@
             common.args
             // {
               inherit (common) cargoArtifacts;
-              cargoClippyExtraArgs = "--all-targets --all-features -- --deny warnings";
+              cargoClippyExtraArgs = "--all-targets -- --deny warnings";
             }
           );
 
@@ -263,7 +276,7 @@
               // {
                 pname = "msrv";
                 inherit (common) cargoArtifacts;
-                cargoClippyExtraArgs = "--all-targets --all-features -- --deny warnings";
+                cargoClippyExtraArgs = "--all-targets -- --deny warnings";
               }
             );