Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pam-sys crate won't build; ENOENT on #include <security/pam_appl.h> #326

Open
Goorzhel opened this issue May 14, 2023 · 16 comments
Open

pam-sys crate won't build; ENOENT on #include <security/pam_appl.h> #326

Goorzhel opened this issue May 14, 2023 · 16 comments
Labels
question Further information is requested

Comments

@Goorzhel
Copy link

Goorzhel commented May 14, 2023

I'm working on a program (here's its flake) that transitively depends on pam-sys, which generates FFI bindings to PAM headers.

I can't get cargo to see those headers, though:

nix log /nix/store/jcg61291wl1fqwg66fc4gkazq9h9x39a-crate-pam-sys-1.0.0-alpha4.drv
nix log /nix/store/jcg61291wl1fqwg66fc4gkazq9h9x39a-crate-pam-sys-1.0.0-alpha4.drv
@nix { "action": "setPhase", "phase": "unpackPhase" }
unpacking sources
unpacking source archive /nix/store/cqjv2093az8izx225ldh3i0z5jfsy46n-pam-sys-1.0.0-alpha4.tar.gz
source root is pam-sys-1.0.0-alpha4
@nix { "action": "setPhase", "phase": "patchPhase" }
patching sources
@nix { "action": "setPhase", "phase": "configurePhase" }
configuring
@nix { "action": "setPhase", "phase": "buildPhase" }
building
   Compiling pam-sys v1.0.0-alpha4 (/build/pam-sys-1.0.0-alpha4)
error: failed to run custom build command for `pam-sys v1.0.0-alpha4 (/build/pam-sys-1.0.0-alpha4)`

Caused by:
  process didn't exit successfully: `/build/pam-sys-1.0.0-alpha4/target/release/build/pam-sys-40eef1e91fcf77fb/build-script-build` (exit status: 101)
  --- stdout
  cargo:rustc-link-lib=pam
  cargo:rustc-link-lib=pam_misc
  cargo:rerun-if-changed=wrapper.h

  --- stderr
  wrapper.h:1:10: fatal error: 'security/pam_appl.h' file not found
  wrapper.h:1:10: fatal error: 'security/pam_appl.h' file not found, err: true
  thread 'main' panicked at 'Unable to generate bindings: ()', build.rs:69:10
  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

With a shell in the build environment, I can see cargo (gcc?) probing $PWD for the header, but nowhere else.

❯ nix develop -i /nix/store/jcg61291wl1fqwg66fc4gkazq9h9x39a-crate-pam-sys-1.0.0-alpha4.drv
bash-5.1$ fd -e gz -d1 -tf pam-sys /nix/store
/nix/store/cqjv2093az8izx225ldh3i0z5jfsy46n-pam-sys-1.0.0-alpha4.tar.gz
bash-5.1$ tar xaf $(!!)
bash-5.1$ cd pam-sys-1.0.0-alpha4
bash-5.1$ runHook preConfigure
bash-5.1$ runHook findCrate
bash-5.1$ runHook configureCargo
bash-5.1$ runHook postConfigure
bash-5.1$ runHook overrideCargoManifest
bash-5.1$ runHook setBuildEnv
bash-5.1$ strace -vtttfo ./wtf /nix/store/7il125cr19fza1h0fxzszmsyc8dss248-rust-minimal-1.61.0/bin/cargo build --release --target x86_64-unknown-linux-gnu
bash-5.1$ grep -C2 'security' /tmp/wtf # note: 7 is the FD to `./wrapper.h`
2091558 1684041693.194523 mprotect(0x7fdee8064000, 4096, PROT_READ|PROT_WRITE) = 0
2091558 1684041693.194559 newfstatat(7, "", {st_dev=makedev(0xfe, 0x2), st_ino=3803605, st_mode=S_IFREG|0644, st_nlink=1, st_uid=1000, st_gid=100, st_blksize=4096, st_blocks=8, st_size=450, st_atime=1684038730 /* 2023-05-13T21:32:10.953759728-0700 */, st_atime_nsec=953759728, st_mtime=123456789 /* 1973-11-29T13:33:09-0800 */, st_mtime_nsec=0, st_ctime=1684038505 /* 2023-05-13T21:28:25.447578322-0700 */, st_ctime_nsec=447578322}, AT_EMPTY_PATH) = 0
2091558 1684041693.194620 pread64(7, "#include <security/pam_appl.h>\n\n"..., 450, 0) = 450
2091558 1684041693.194653 rt_sigprocmask(SIG_SETMASK, ~[RTMIN RT_1], [], 8) = 0
2091558 1684041693.194686 close(7)      = 0
--
2091558 1684041693.196291 mprotect(0x7fdee8092000, 4096, PROT_READ|PROT_WRITE) = 0
2091558 1684041693.196351 mprotect(0x7fdee8093000, 4096, PROT_READ|PROT_WRITE) = 0
2091558 1684041693.196384 newfstatat(AT_FDCWD, "./security", 0x7fdeeea70cf0, 0) = -1 ENOENT (No such file or directory)
2091558 1684041693.196430 mprotect(0x7fdee8094000, 4096, PROT_READ|PROT_WRITE) = 0
2091558 1684041693.196533 write(2, "wrapper.h:1:10: fatal error: 'se"..., 66) = 66

Which is weird, because I can see the include flag for linux-pam in the environment:

bash-5.1$ env | grep linux-pam.*include
NIX_CFLAGS_COMPILE_FOR_BUILD= -isystem /nix/store/0zl79km49n4s0037ks1v6qyvq3d7k5my-jq-1.6-dev/include -isystem /nix/store/0zl79km49n4s0037ks1v6qyvq3d7k5my-jq-1.6-dev/include -isystem /nix/store/vzqny68wq33dcg4hkdala51n5vqhpnwc-python3-3.9.12/include -isystem /nix/store/vzqny68wq33dcg4hkdala51n5vqhpnwc-python3-3.9.12/include -isystem /nix/store/iiw5159gj8iq5cwmsxz7pzx6fg2gjw5k-clang-11.1.0-dev/include -isystem /nix/store/iiw5159gj8iq5cwmsxz7pzx6fg2gjw5k-clang-11.1.0-dev/include -isystem /nix/store/491im6imqwa9ssfixsy9wvrvi17bqmdr-linux-pam-1.5.2/include -isystem /nix/store/491im6imqwa9ssfixsy9wvrvi17bqmdr-linux-pam-1.5.2/include -isystem /nix/store/0zl79km49n4s0037ks1v6qyvq3d7k5my-jq-1.6-dev/include -isystem /nix/store/0zl79km49n4s0037ks1v6qyvq3d7k5my-jq-1.6-dev/include -isystem /nix/store/vzqny68wq33dcg4hkdala51n5vqhpnwc-python3-3.9.12/include -isystem /nix/store/vzqny68wq33dcg4hkdala51n5vqhpnwc-python3-3.9.12/include -isystem /nix/store/iiw5159gj8iq5cwmsxz7pzx6fg2gjw5k-clang-11.1.0-dev/include -isystem /nix/store/iiw5159gj8iq5cwmsxz7pzx6fg2gjw5k-clang-11.1.0-dev/include -isystem /nix/store/491im6imqwa9ssfixsy9wvrvi17bqmdr-linux-pam-1.5.2/include -isystem /nix/store/491im6imqwa9ssfixsy9wvrvi17bqmdr-linux-pam-1.5.2/include -isystem /nix/store/0zl79km49n4s0037ks1v6qyvq3d7k5my-jq-1.6-dev/include -isystem /nix/store/0zl79km49n4s0037ks1v6qyvq3d7k5my-jq-1.6-dev/include -isystem /nix/store/vzqny68wq33dcg4hkdala51n5vqhpnwc-python3-3.9.12/include -isystem /nix/store/vzqny68wq33dcg4hkdala51n5vqhpnwc-python3-3.9.12/include -isystem /nix/store/iiw5159gj8iq5cwmsxz7pzx6fg2gjw5k-clang-11.1.0-dev/include -isystem /nix/store/iiw5159gj8iq5cwmsxz7pzx6fg2gjw5k-clang-11.1.0-dev/include -isystem /nix/store/491im6imqwa9ssfixsy9wvrvi17bqmdr-linux-pam-1.5.2/include -isystem /nix/store/491im6imqwa9ssfixsy9wvrvi17bqmdr-linux-pam-1.5.2/include
NIX_CFLAGS_COMPILE= -frandom-seed=gd8cxblafh -isystem /nix/store/0zl79km49n4s0037ks1v6qyvq3d7k5my-jq-1.6-dev/include -isystem /nix/store/vzqny68wq33dcg4hkdala51n5vqhpnwc-python3-3.9.12/include -isystem /nix/store/iiw5159gj8iq5cwmsxz7pzx6fg2gjw5k-clang-11.1.0-dev/include -isystem /nix/store/491im6imqwa9ssfixsy9wvrvi17bqmdr-linux-pam-1.5.2/include -isystem /nix/store/0zl79km49n4s0037ks1v6qyvq3d7k5my-jq-1.6-dev/include -isystem /nix/store/vzqny68wq33dcg4hkdala51n5vqhpnwc-python3-3.9.12/include -isystem /nix/store/iiw5159gj8iq5cwmsxz7pzx6fg2gjw5k-clang-11.1.0-dev/include -isystem /nix/store/491im6imqwa9ssfixsy9wvrvi17bqmdr-linux-pam-1.5.2/include

Forgive me if I've missed something basic. My C is rusty.

@psionic-k
Copy link
Member

See the existing overrides that include darwin components. Looks like you need:

pkgs.darwin.apple_sdk.frameworks.Security as well in your propagatedBuildInputs

@psionic-k psionic-k added the question Further information is requested label Oct 15, 2023
@Goorzhel
Copy link
Author

Doesn't that apply only if the hostPlatform is Darwin, though?

Mine's Linux
❯ git show
<snip>
diff --git a/flake.nix b/flake.nix
index 6941b70..b5cf669 100644
--- a/flake.nix
+++ b/flake.nix
@@ -28 +28,4 @@
-                    propagatedBuildInputs = old.propagatedBuildInputs ++ [pkgs.linux-pam];
+                    propagatedBuildInputs = old.propagatedBuildInputs ++ [
+                      pkgs.linux-pam
+                      pkgs.darwin.apple_sdk.frameworks.Security
+                    ];
❯ NIXPKGS_ALLOW_UNSUPPORTED_SYSTEM=1 nix build --impure
error: builder for '/nix/store/1shfifdm8mjhinmlfgrxr3g0mvbxmdvm-crate-pam-sys-1.0.0-alpha4.drv' failed with exit code 101;
       last 10 log lines:
       >           gcc: error: unrecognized command-line option '-iframework'
       >           gcc: error: unrecognized command-line option '-iframework'
       >           gcc: error: unrecognized command-line option '-iframework'
       >
       >
       >
       > error: aborting due to previous error
       >
       >
       > error: could not compile `pam-sys` due to 2 previous errors
       For full logs, run 'nix log /nix/store/1shfifdm8mjhinmlfgrxr3g0mvbxmdvm-crate-pam-sys-1.0.0-alpha4.drv'.
error: 1 dependencies of derivation '/nix/store/qi6v0i9r73fxgj7q16y4j6b1c7wpk14p-crate-pam-0.7.0.drv' failed to build
error: 1 dependencies of derivation '/nix/store/84wsqc5sxq24l5rl77vydks3wp807ws8-crate-radm-0.6.4.drv' failed to build

@psionic-k
Copy link
Member

Sorry, it was late and I was just scanning through and saw appl lol.

pam_appl.h is the missing file.

The usual way this gets picked up is pkgconfig and some hooks that set the include flags for all the dependencies.

Sometimes you need to switch outputs to get the right files. Check outputs to see if there's a dev output.

nix repl expr='(import <nixpkgs> {}).pkgs.pam.outputs'
# [ "out" "doc" "man" ]

Nope, standard.

Skipping ahead, the outPath include/security directory does contain pam_appl.h

Can you get me the output for nix show-derivation? Let's look at what all is there. The env output just before the build hook should also be interesting. When pkg-config's hook runs, it adds a bunch of flags for gcc.

@psionic-k
Copy link
Member

Was Clang in that flake before?

@Goorzhel
Copy link
Author

Was Clang in that flake before?

I uh...I don't remember why I put that there. If I take it out, I get the same error.

But if I take out `LIBCLANG_PATH` too, I get

thread 'main' panicked at 'Unable to find libclang: "couldn't find any valid shared libraries matching: ['libclang.so', 'libclang-*.so', 'libclang.so.*', 'libclang-*.so.*'], set the LIBCLANG_PATH environment variable to a path where one of these files can be found (invalid: [])"', src/lib.rs:2144:31

Anyway:

nix derivation show
{
  "/nix/store/8zz95fl5vndfs86ihxwi4pzk9y04yhmi-crate-radm-0.6.4.drv": {
    "args": [
      "-e",
      "/nix/store/9krlzvny65gdc8s7kpb6lkx8cd02c25b-default-builder.sh"
    ],
    "builder": "/nix/store/0d3wgx8x6dxdb2cpnq105z23hah07z7l-bash-5.1-p16/bin/bash",
    "env": {
      "NIX_DEBUG": "0",
      "bin": "/nix/store/05djdwln3sp3hji36zjicc4kq1h301dp-crate-radm-0.6.4-bin",
      "buildDependencies": "",
      "buildInputs": "/nix/store/wdnlaiy90km40nhv533s731ksijrbkv4-crate-anyhow-1.0.58 /nix/store/g0bgkj6pm0rq715zkaf0gg99aj8h8h0w-crate-chvt-0.2.0 /nix/store/xk80icxhg2kbb27cky996lkhcacaac82-crate-clap-3.2.10 /nix/store/z330gndhcz0v17askpag7ihiwsa7vpal-crate-configparser-3.0.0 /nix/store/rrv1izl6jz41hmxy399p02g82jd87d9p-crate-console-0.15.0 /nix/store/0rsaygdh4sgpn56c5pin4912pa7n3lg8-crate-log-0.4.17 /nix/store/90q13rvflwrz8094mc52jcqbj8llhz6b-crate-nix-0.24.1 /nix/store/x7pv4frr363npz6is3klhi37bbdf3azn-crate-pam-0.7.0 /nix/store/xsdrhrv0d59sd69dlf849ry7swc2hprg-crate-pwd-1.4.0 /nix/store/rn8j5hkhiy6rb3nrqlgk8nfnys8msgyx-crate-simplelog-0.12.0 /nix/store/ysrf8ay7kk4r76fk6992a9j2dgs3ylhd-crate-syslog-6.0.1 /nix/store/rx5y9626hvwgzyrlvil3sc997vs8q9ar-crate-xdg-2.4.1",
      "buildPhase": "runHook overrideCargoManifest\nrunHook setBuildEnv\nrunHook runCargo\n",
      "builder": "/nix/store/0d3wgx8x6dxdb2cpnq105z23hah07z7l-bash-5.1-p16/bin/bash",
      "configureCargo": "mkdir -p .cargo\ncat > .cargo/config <<'EOF'\n[target.\"x86_64-unknown-linux-gnu\"]\nlinker = \"/nix/store/r7r10qvsqlnvbzjkjinvscjlahqbxifl-gcc-wrapper-11.3.0/bin/cc\"\n\nEOF\n",
      "configureFlags": "",
      "configurePhase": "runHook preConfigure\nrunHook findCrate\nrunHook configureCargo\nrunHook postConfigure\n",
      "dependencies": "anyhow /nix/store/wdnlaiy90km40nhv533s731ksijrbkv4-crate-anyhow-1.0.58 chvt /nix/store/g0bgkj6pm0rq715zkaf0gg99aj8h8h0w-crate-chvt-0.2.0 clap /nix/store/xk80icxhg2kbb27cky996lkhcacaac82-crate-clap-3.2.10 configparser /nix/store/z330gndhcz0v17askpag7ihiwsa7vpal-crate-configparser-3.0.0 console /nix/store/rrv1izl6jz41hmxy399p02g82jd87d9p-crate-console-0.15.0 log /nix/store/0rsaygdh4sgpn56c5pin4912pa7n3lg8-crate-log-0.4.17 nix /nix/store/90q13rvflwrz8094mc52jcqbj8llhz6b-crate-nix-0.24.1 pam /nix/store/x7pv4frr363npz6is3klhi37bbdf3azn-crate-pam-0.7.0 pwd /nix/store/xsdrhrv0d59sd69dlf849ry7swc2hprg-crate-pwd-1.4.0 simplelog /nix/store/rn8j5hkhiy6rb3nrqlgk8nfnys8msgyx-crate-simplelog-0.12.0 syslog /nix/store/ysrf8ay7kk4r76fk6992a9j2dgs3ylhd-crate-syslog-6.0.1 xdg /nix/store/rx5y9626hvwgzyrlvil3sc997vs8q9ar-crate-xdg-2.4.1",
      "depsBuildBuild": "/nix/store/r7r10qvsqlnvbzjkjinvscjlahqbxifl-gcc-wrapper-11.3.0 /nix/store/0zl79km49n4s0037ks1v6qyvq3d7k5my-jq-1.6-dev /nix/store/zgmikgwi2h57ynmzbihrhkfa6p59wxhs-remarshal-0.14.0",
      "depsBuildBuildPropagated": "",
      "depsBuildTarget": "",
      "depsBuildTargetPropagated": "",
      "depsHostHost": "",
      "depsHostHostPropagated": "",
      "depsTargetTarget": "",
      "depsTargetTargetPropagated": "",
      "devDependencies": "",
      "doCheck": "",
      "doInstallCheck": "",
      "extraRustcBuildFlags": "",
      "extraRustcLinkFlags": "",
      "findCrate": ". /nix/store/vfkaxc70kdq6jiiyk4l1awb6gsjhcfwg-mkcrate-utils.sh\nmanifest_path=$(cargoRelativeManifest radm)\nmanifest_dir=${manifest_path%Cargo.toml}\n\nif [ $manifest_path != \"Cargo.toml\" ]; then\n  shopt -s globstar\n  mv Cargo.toml Cargo.toml.workspace\n  if [[ -d .cargo ]]; then\n    mv .cargo .cargo.workspace\n  fi\n  cd \"$manifest_dir\"\nfi\n",
      "installPhase": "runHook preInstall\nmkdir -p $out/lib\ncargo_links=\"$(remarshal -if toml -of json Cargo.original.toml | jq -r '.package.links | select(. != null)')\"\nif (( MINOR_RUSTC_VERSION < 41 )); then\n  install_crate x86_64-unknown-linux-gnu release\nelse\n  install_crate2 x86_64-unknown-linux-gnu\nfi\nrunHook postInstall\n",
      "manifestPatch": "{\"features\":{},\"profile\":{\"release\":null}}",
      "name": "crate-radm-0.6.4",
      "nativeBuildInputs": "/nix/store/7il125cr19fza1h0fxzszmsyc8dss248-rust-minimal-1.61.0",
      "out": "/nix/store/mbr2yj9wbqq5h3ijr2ripcznalfkf62d-crate-radm-0.6.4",
      "outputs": "out bin",
      "overrideCargoManifest": "echo \"[[package]]\" > Cargo.lock\necho name = \\\"radm\\\" >> Cargo.lock\necho version = \\\"0.6.4\\\" >> Cargo.lock\nregistry=\"unknown\"\nif [ \"$registry\" != \"unknown\" ]; then\n  echo source = \\\"registry+${registry}\\\" >> Cargo.lock\nfi\nmv Cargo.toml Cargo.original.toml\n# Remarshal was failing on table names of the form:\n# [key.\"cfg(foo = \\\"a\\\", bar = \\\"b\\\"))\".path]\n# The regex to find or deconstruct these strings must find, in order,\n# these components: open bracket, open quote, open escaped quote, and\n# their closing pairs.  Because each quoted path can contain multiple\n# quote escape pairs, a loop is employed to match the first quote escape,\n# which the sed will replace with a single quote equivalent until all\n# escaped quote pairs are replaced.  The grep regex is identical to the\n# sed regex but does not destructure the match into groups for\n# restructuring in the replacement.\nwhile grep '\\[[^\"]*\"[^\\\\\"]*\\\\\"[^\\\\\"]*\\\\\"[^\"]*[^]]*\\]' Cargo.original.toml; do\n  sed -i -r 's/\\[([^\"]*)\"([^\\\\\"]*)\\\\\"([^\\\\\"]*)\\\\\"([^\"]*)\"([^]]*)\\]/[\\1\"\\2'\"'\"'\\3'\"'\"'\\4\"\\5]/g' Cargo.original.toml\ndone;\nremarshal -if toml -of json Cargo.original.toml \\\n  | jq \"{ package: .package\n        , lib: .lib\n        , bin: .bin\n        , test: .test\n        , example: .example\n        , bench: (if \\\"$registry\\\" == \\\"unknown\\\" then .bench else null end)\n        } | with_entries(select( .value != null ))\n        + $manifestPatch\" \\\n  | jq \"del(.[][] | nulls)\" \\\n  | remarshal -if json -of toml > Cargo.toml\n",
      "patches": "",
      "propagatedBuildInputs": "/nix/store/491im6imqwa9ssfixsy9wvrvi17bqmdr-linux-pam-1.5.2",
      "propagatedNativeBuildInputs": "",
      "runCargo": "(\n  set -euo pipefail\n  if (( NIX_DEBUG >= 1 )); then\n    set -x\n  fi\n  env \\\n    \"CC_x86_64-unknown-linux-gnu\"=\"/nix/store/r7r10qvsqlnvbzjkjinvscjlahqbxifl-gcc-wrapper-11.3.0/bin/cc\" \\\n    \"CXX_x86_64-unknown-linux-gnu\"=\"/nix/store/r7r10qvsqlnvbzjkjinvscjlahqbxifl-gcc-wrapper-11.3.0/bin/c++\" \\\n    \"CC_x86_64-unknown-linux-gnu\"=\"/nix/store/r7r10qvsqlnvbzjkjinvscjlahqbxifl-gcc-wrapper-11.3.0/bin/cc\" \\\n    \"CXX_x86_64-unknown-linux-gnu\"=\"/nix/store/r7r10qvsqlnvbzjkjinvscjlahqbxifl-gcc-wrapper-11.3.0/bin/c++\" \\\n    \"${depKeys[@]}\" \\\n    /nix/store/7il125cr19fza1h0fxzszmsyc8dss248-rust-minimal-1.61.0/bin/cargo build $CARGO_VERBOSE --release --target x86_64-unknown-linux-gnu  \\\n   --no-default-features \\\n  --message-format json-diagnostic-rendered-ansi | tee .cargo-build-output \\\n  1> >(jq 'select(.message != null) .message.rendered' -r)\n\n)\n",
      "setBuildEnv": "CARGO_BUILD_INCREMENTAL=0  #builds inside nix sandbox use nix caching, not cargo target caching\nMINOR_RUSTC_VERSION=\"$(/nix/store/7il125cr19fza1h0fxzszmsyc8dss248-rust-minimal-1.61.0/bin/rustc --version | cut -d . -f 2)\"\n\nif (( MINOR_RUSTC_VERSION < 41 )); then\n  isProcMacro=\"$(\n    remarshal -if toml -of json Cargo.original.toml \\\n    | jq -r 'if .lib.\"proc-macro\" or .lib.\"proc_macro\" then \"1\" else \"\" end' \\\n  )\"\nfi\n\ncrateName=\"$(\n  remarshal -if toml -of json Cargo.original.toml \\\n  | jq -r 'if .lib.\"name\" then .lib.\"name\" else \"radm\" end' \\\n)\"\n\n. /nix/store/vfkaxc70kdq6jiiyk4l1awb6gsjhcfwg-mkcrate-utils.sh\n\nexport CARGO_VERBOSE=`cargoVerbosityLevel $NIX_DEBUG`\nexport NIX_RUST_METADATA=`extractHash $out`\nexport CARGO_HOME=`pwd`/.cargo\n\nmkdir -p deps build_deps\nlinkFlags=(`makeExternCrateFlags $dependencies $devDependencies | sort -u`)\nbuildLinkFlags=(`makeExternCrateFlags $buildDependencies | sort -u`)\nlinkExternCrateToDeps `realpath deps` $dependencies $devDependencies\nlinkExternCrateToDeps `realpath build_deps` $buildDependencies\n\nexport NIX_RUST_LINK_FLAGS=\"${linkFlags[@]} -L dependency=$(realpath deps) $extraRustcLinkFlags\"\nexport NIX_RUST_BUILD_FLAGS=\"${buildLinkFlags[@]} -L dependency=$(realpath build_deps) $extraRustcBuildFlags\"\nexport RUSTC=/nix/store/g2i8vx373kspf84md7m6pp5jlprmdq2a-rustc/bin/rustc\nexport RUSTDOC=/nix/store/r0gliyrmg12c6il7b3qc4bw9y4b2v7k8-rustdoc/bin/rustdoc\n\ndepKeys=(`loadDepKeys $dependencies`)\n\nif (( NIX_DEBUG >= 1 )); then\n  echo $NIX_RUST_LINK_FLAGS\n  echo $NIX_RUST_BUILD_FLAGS\n  for key in ${depKeys[@]}; do\n    echo $key\n  done\nfi\n",
      "src": "/nix/store/d44qdkn0xbkli5q0y7lgldsqzs13myif-qyh2wv6cr06dazvffss5m1x7xr1x50z7-source",
      "stdenv": "/nix/store/28hqpbwpzvpff7ldbhxdhzcpdc34lgsa-stdenv-linux",
      "strictDeps": "",
      "system": "x86_64-linux",
      "version": "0.6.4"
    },
    "inputDrvs": {
      "/nix/store/0brl0ddif6445nkilzhkxhc5xfpm75nc-crate-pwd-1.4.0.drv": [
        "out"
      ],
      "/nix/store/3w3vd1n6xlnf3wq5f6bvb9n9wpfivfhs-jq-1.6.drv": [
        "dev"
      ],
      "/nix/store/42pr7zqjf0y29v19q1wxn6hs5gdl5car-bash-5.1-p16.drv": [
        "out"
      ],
      "/nix/store/5ddrfrpp4r7w6hps9bd3jvmjibkcl4bj-crate-configparser-3.0.0.drv": [
        "out"
      ],
      "/nix/store/5p0dbm3m8i36az506pb62x4wqnqxinv9-crate-clap-3.2.10.drv": [
        "out"
      ],
      "/nix/store/76hm66f1p02xa0yrqz633bzak9q011j9-remarshal-0.14.0.drv": [
        "out"
      ],
      "/nix/store/8s61mgdqvs2mjnvwirnq463if035gaxv-crate-console-0.15.0.drv": [
        "out"
      ],
      "/nix/store/9yjwifcv2xsl23al11bhdxi8jx8fw4ri-crate-anyhow-1.0.58.drv": [
        "out"
      ],
      "/nix/store/bl5y9zix1vsdiq6q0lxypggsahb65np5-gcc-wrapper-11.3.0.drv": [
        "out"
      ],
      "/nix/store/bphwihx90plfz0aw0jwjdx81d2sak5gx-crate-pam-0.7.0.drv": [
        "out"
      ],
      "/nix/store/ddmyhp06jqy8bxj715zwsmbcnzvx8iax-stdenv-linux.drv": [
        "out"
      ],
      "/nix/store/id4fw7vp79m0s5x33pld8xsan9r56ri0-crate-simplelog-0.12.0.drv": [
        "out"
      ],
      "/nix/store/kysgzlm0wyalil2vqgyw8dhl4471xp4p-rustc.drv": [
        "out"
      ],
      "/nix/store/lpivx8z7sg4rbzqxlii08zm4qf23xfwd-crate-nix-0.24.1.drv": [
        "out"
      ],
      "/nix/store/pr348g0br42cp8rc2q21yxiymcrhhvrl-crate-syslog-6.0.1.drv": [
        "out"
      ],
      "/nix/store/q17wwicqhwv1mwz3agjp0ikj5731x0wn-rustdoc.drv": [
        "out"
      ],
      "/nix/store/q5vm18pd14i1bg4lkk8m14c3d8ib7lff-crate-xdg-2.4.1.drv": [
        "out"
      ],
      "/nix/store/qv0zbv3y8y0ivpar3jgp6i2qkdfmgflg-crate-chvt-0.2.0.drv": [
        "out"
      ],
      "/nix/store/qz9k298f7q72hn3i38zy18nnr1llp4ir-rust-minimal-1.61.0.drv": [
        "out"
      ],
      "/nix/store/wxy2mch28jh197gp672j6s909c97l9vf-crate-log-0.4.17.drv": [
        "out"
      ],
      "/nix/store/z352683d716ry8mhdsc491r0lswlwg7h-linux-pam-1.5.2.drv": [
        "out"
      ]
    },
    "inputSrcs": [
      "/nix/store/9krlzvny65gdc8s7kpb6lkx8cd02c25b-default-builder.sh",
      "/nix/store/d44qdkn0xbkli5q0y7lgldsqzs13myif-qyh2wv6cr06dazvffss5m1x7xr1x50z7-source",
      "/nix/store/vfkaxc70kdq6jiiyk4l1awb6gsjhcfwg-mkcrate-utils.sh"
    ],
    "name": "crate-radm-0.6.4",
    "outputs": {
      "bin": {
        "path": "/nix/store/05djdwln3sp3hji36zjicc4kq1h301dp-crate-radm-0.6.4-bin"
      },
      "out": {
        "path": "/nix/store/mbr2yj9wbqq5h3ijr2ripcznalfkf62d-crate-radm-0.6.4"
      }
    },
    "system": "x86_64-linux"
  }
}
env | sort

After repeating all runHooks in OP (again excluding runCargo):

builder=/nix/store/0d3wgx8x6dxdb2cpnq105z23hah07z7l-bash-5.1-p16/bin/bash
buildInputs=
CONFIG_SHELL=/nix/store/0d3wgx8x6dxdb2cpnq105z23hah07z7l-bash-5.1-p16/bin/bash
configureFlags=
curlOpts=
depsBuildBuild=
depsBuildBuildPropagated=
depsBuildTarget=
depsBuildTargetPropagated=
depsHostHost=
depsHostHostPropagated=
depsTargetTarget=
depsTargetTargetPropagated=
doCheck=
doInstallCheck=
dontAddDisableDepTrack=1
downloadToTemp=
EDITOR=nvim
__ETC_PROFILE_DONE=1
executable=
GPG_TTY=/dev/pts/5
GTK_A11Y=none
GTK_PATH=/.nix-profile/lib/gtk-2.0:/.nix-profile/lib/gtk-3.0:/.nix-profile/lib/gtk-4.0:/etc/profiles/per-user//lib/gtk-2.0:/etc/profiles/per-user//lib/gtk-3.0:/etc/profiles/per-user//lib/gtk-4.0:/nix/var/nix/profiles/default/lib/gtk-2.0:/nix/var/nix/profiles/default/lib/gtk-3.0:/nix/var/nix/profiles/default/lib/gtk-4.0:/run/current-system/sw/lib/gtk-2.0:/run/current-system/sw/lib/gtk-3.0:/run/current-system/sw/lib/gtk-4.0
HOST_PATH=/nix/store/47n5hzqpahs7yv84ia6cxp3jg9ca8r86-coreutils-9.0/bin:/nix/store/6ib6hn9fq8mgkdq2nq5f7kz050p49rp2-findutils-4.9.0/bin:/nix/store/685c5dr4agkf7vx8ya7f1r9rd9qwg2ri-diffutils-3.8/bin:/nix/store/sppjn85p06m1il70kd05drg1j26cjxd3-gnused-4.8/bin:/nix/store/49vp3yp54fqliy7k8gvxsybd50l9a82f-gnugrep-3.7/bin:/nix/store/fr7vrxblkj327ypn3vhjwfhf19lddqqd-gawk-5.1.1/bin:/nix/store/5p3qyadsv163m7zvqssiw80zh6xfv2jv-gnutar-1.34/bin:/nix/store/2bwqikh67y1231ccb71gjfrggwjw066q-gzip-1.12/bin:/nix/store/wjf2554ffvap47vanabh9lk0dmj1q295-bzip2-1.0.6.0.2-bin/bin:/nix/store/2hvj24gaq4y32cyf0jp9sj01y00k7czy-gnumake-4.3/bin:/nix/store/0d3wgx8x6dxdb2cpnq105z23hah07z7l-bash-5.1-p16/bin:/nix/store/wa31fy0bgmq7p2gcvh5xyrr7m2v8i3s2-patch-2.7.6/bin:/nix/store/dr5shmim604rh50mmihwfic80k0wa3k0-xz-5.2.5-bin/bin
impureEnvVars=http_proxy https_proxy ftp_proxy all_proxy no_proxy NIX_CURL_FLAGS NIX_HASHED_MIRRORS NIX_CONNECT_TIMEOUT NIX_MIRRORS_alsa NIX_MIRRORS_apache NIX_MIRRORS_bioc NIX_MIRRORS_bitlbee NIX_MIRRORS_centos NIX_MIRRORS_cpan NIX_MIRRORS_debian NIX_MIRRORS_fedora NIX_MIRRORS_gcc NIX_MIRRORS_gentoo NIX_MIRRORS_gnome NIX_MIRRORS_gnu NIX_MIRRORS_gnupg NIX_MIRRORS_hackage NIX_MIRRORS_hashedMirrors NIX_MIRRORS_ibiblioPubLinux NIX_MIRRORS_imagemagick NIX_MIRRORS_kde NIX_MIRRORS_kernel NIX_MIRRORS_luarocks NIX_MIRRORS_maven NIX_MIRRORS_mozilla NIX_MIRRORS_mysql NIX_MIRRORS_openbsd NIX_MIRRORS_opensuse NIX_MIRRORS_osdn NIX_MIRRORS_postgresql NIX_MIRRORS_pypi NIX_MIRRORS_roy NIX_MIRRORS_sageupstream NIX_MIRRORS_samba NIX_MIRRORS_savannah NIX_MIRRORS_sourceforge NIX_MIRRORS_steamrt NIX_MIRRORS_tcsh NIX_MIRRORS_testpypi NIX_MIRRORS_ubuntu NIX_MIRRORS_xfce NIX_MIRRORS_xorg
INFOPATH=/.nix-profile/info:/.nix-profile/share/info:/etc/profiles/per-user//info:/etc/profiles/per-user//share/info:/nix/var/nix/profiles/default/info:/nix/var/nix/profiles/default/share/info:/run/current-system/sw/info:/run/current-system/sw/share/info
IN_NIX_SHELL=impure
KDEDIRS=/.nix-profile:/etc/profiles/per-user/:/nix/var/nix/profiles/default:/run/current-system/sw
LANG=en_US.UTF-8
LESSKEYIN_SYSTEM=/nix/store/1pr5p9z8jplgr5wlf0ihym13mw5vb231-lessconfig
LESSOPEN=|/nix/store/bxsd08ig9vblr7f6gfc5r826shg2bdqf-lesspipe-2.07/bin/lesspipe.sh %s
LIBEXEC_PATH=/.nix-profile/lib/libexec:/etc/profiles/per-user//lib/libexec:/nix/var/nix/profiles/default/lib/libexec:/run/current-system/sw/lib/libexec
LOCALE_ARCHIVE=/run/current-system/sw/lib/locale/locale-archive
LS_COLORS=
mirrorsFile=/nix/store/k0scnpkczxi580d4v33hyfbfpl7hyiq6-mirrors-list
MOZ_PLUGIN_PATH=/.nix-profile/lib/mozilla/plugins:/etc/profiles/per-user//lib/mozilla/plugins:/nix/var/nix/profiles/default/lib/mozilla/plugins:/run/current-system/sw/lib/mozilla/plugins
name=pam-sys-1.0.0-alpha4.tar.gz-env
nativeBuildInputs=/nix/store/1m77bcwy5vj0vvy816120cj84lxggz6z-curl-7.83.1-dev
NIX_BUILD_CORES=12
NIX_BUILD_TOP=/tmp/nix-shell.Rx5v1V
NIX_CFLAGS_COMPILE= -frandom-seed=57qlafhk31
NIX_ENFORCE_NO_NATIVE=1
NIX_GCROOT=/nix/store/57qlafhk31x2lzqyswjjrs57kwhn66jh-pam-sys-1.0.0-alpha4.tar.gz-env
NIX_INDENT_MAKE=1
NIX_LDFLAGS=-rpath /home/ag/src/OWN/radm/outputs/out/lib64 -rpath /home/ag/src/OWN/radm/outputs/out/lib 
__NIXOS_SET_ENVIRONMENT_DONE=1
NIX_PATH=nixpkgs=/nix/store/pqddk12i1q7jl2ldljm4lf2xfrpdr36z-source:nixos-config=/nix/store/rww0xv5f4x2pvlhdv2h4vmmlvr6gr7dh-nixos:home-manager=/nix/store/v861wki5p16lr246nyb6rmq2dj9aklhz-source
NIXPKGS_CONFIG=/etc/nix/nixpkgs-config.nix
nixpkgsVersion=22.05
NIX_PROFILES=/run/current-system/sw /nix/var/nix/profiles/default /etc/profiles/per-user/ /.nix-profile
_=/nix/store/47n5hzqpahs7yv84ia6cxp3jg9ca8r86-coreutils-9.0/bin/env
NIX_STORE=/nix/store
NIX_USER_PROFILE_DIR=/nix/var/nix/profiles/per-user/
NO_AT_BRIDGE=1
NODE_OPTIONS=--use-openssl-ca
OLDPWD=/home/ag/src/OWN/radm
out=/home/ag/src/OWN/radm/outputs/out
outputHash=5e9dfd42858f6a6bb1081079fd9dc259ca3e2aaece6cb689fd36b1058046c969
outputHashAlgo=sha256
outputHashMode=flat
outputs=out
PAGER=less
patches=
PATH=/nix/store/1m77bcwy5vj0vvy816120cj84lxggz6z-curl-7.83.1-dev/bin:/nix/store/aw8lvrb6vagzd5pp9mjsv5dh3r8h18hd-libkrb5-1.19.3-dev/bin:/nix/store/kz9zyv3z4z883vb6z0rw6588mvyrmczh-libkrb5-1.19.3/bin:/nix/store/jpzizwnh5lxyc02pivid8ni4isag3rs4-nghttp2-1.47.0-bin/bin:/nix/store/fvwn12wkpnc61cvd7i8q0a4xmsh37a3c-openssl-1.1.1o-bin/bin:/nix/store/shs5mmslksfjkds8qz5pk7942y2g5bk3-curl-7.83.1-bin/bin:/nix/store/n1jgqr8xzjz9shn3ads5x07p8lqn5rqk-patchelf-0.14.5/bin:/nix/store/47n5hzqpahs7yv84ia6cxp3jg9ca8r86-coreutils-9.0/bin:/nix/store/6ib6hn9fq8mgkdq2nq5f7kz050p49rp2-findutils-4.9.0/bin:/nix/store/685c5dr4agkf7vx8ya7f1r9rd9qwg2ri-diffutils-3.8/bin:/nix/store/sppjn85p06m1il70kd05drg1j26cjxd3-gnused-4.8/bin:/nix/store/49vp3yp54fqliy7k8gvxsybd50l9a82f-gnugrep-3.7/bin:/nix/store/fr7vrxblkj327ypn3vhjwfhf19lddqqd-gawk-5.1.1/bin:/nix/store/5p3qyadsv163m7zvqssiw80zh6xfv2jv-gnutar-1.34/bin:/nix/store/2bwqikh67y1231ccb71gjfrggwjw066q-gzip-1.12/bin:/nix/store/wjf2554ffvap47vanabh9lk0dmj1q295-bzip2-1.0.6.0.2-bin/bin:/nix/store/2hvj24gaq4y32cyf0jp9sj01y00k7czy-gnumake-4.3/bin:/nix/store/0d3wgx8x6dxdb2cpnq105z23hah07z7l-bash-5.1-p16/bin:/nix/store/wa31fy0bgmq7p2gcvh5xyrr7m2v8i3s2-patch-2.7.6/bin:/nix/store/dr5shmim604rh50mmihwfic80k0wa3k0-xz-5.2.5-bin/bin:/run/wrappers/bin:/.nix-profile/bin:/etc/profiles/per-user//bin:/nix/var/nix/profiles/default/bin:/run/current-system/sw/bin
postFetch=
preferHashedMirrors=1
preferLocalBuild=1
propagatedBuildInputs=
propagatedNativeBuildInputs=
PWD=/home/ag/src/OWN/radm/pam-sys-1.0.0-alpha4
QT_PLUGIN_PATH=/.nix-profile/lib/qt4/plugins:/.nix-profile/lib/kde4/plugins:/etc/profiles/per-user//lib/qt4/plugins:/etc/profiles/per-user//lib/kde4/plugins:/nix/var/nix/profiles/default/lib/qt4/plugins:/nix/var/nix/profiles/default/lib/kde4/plugins:/run/current-system/sw/lib/qt4/plugins:/run/current-system/sw/lib/kde4/plugins
QTWEBKIT_PLUGIN_PATH=/.nix-profile/lib/mozilla/plugins/:/etc/profiles/per-user//lib/mozilla/plugins/:/nix/var/nix/profiles/default/lib/mozilla/plugins/:/run/current-system/sw/lib/mozilla/plugins/
shell=/nix/store/0d3wgx8x6dxdb2cpnq105z23hah07z7l-bash-5.1-p16/bin/bash
SHLVL=1
showURLs=
SOURCE_DATE_EPOCH=315532800
SSH_ASKPASS=
stdenv=/nix/store/7cifvbmgjm5y9ds5a7c6c861g1xcm1qr-stdenv-linux
strictDeps=
system=x86_64-linux
TEMPDIR=/tmp/nix-shell.Rx5v1V
TEMP=/tmp/nix-shell.Rx5v1V
TERM=dumb
TERMINFO_DIRS=/.nix-profile/share/terminfo:/etc/profiles/per-user//share/terminfo:/nix/var/nix/profiles/default/share/terminfo:/run/current-system/sw/share/terminfo
TMPDIR=/tmp/nix-shell.Rx5v1V
TMP=/tmp/nix-shell.Rx5v1V
TMUX_TMPDIR=
TZDIR=/etc/zoneinfo
urls=https://crates.io/api/v1/crates/pam-sys/1.0.0-alpha4/download
XCURSOR_PATH=/.icons:/.local/share/icons:/.nix-profile/share/icons:/.nix-profile/share/pixmaps:/etc/profiles/per-user//share/icons:/etc/profiles/per-user//share/pixmaps:/nix/var/nix/profiles/default/share/icons:/nix/var/nix/profiles/default/share/pixmaps:/run/current-system/sw/share/icons:/run/current-system/sw/share/pixmaps
XDG_CONFIG_DIRS=/etc/xdg:/.nix-profile/etc/xdg:/etc/profiles/per-user//etc/xdg:/nix/var/nix/profiles/default/etc/xdg:/run/current-system/sw/etc/xdg
XDG_DATA_DIRS=/nix/store/1m77bcwy5vj0vvy816120cj84lxggz6z-curl-7.83.1-dev/share:/nix/store/kz9zyv3z4z883vb6z0rw6588mvyrmczh-libkrb5-1.19.3/share:/nix/store/jpzizwnh5lxyc02pivid8ni4isag3rs4-nghttp2-1.47.0-bin/share:/nix/store/9ih68mrvdv8fhw77v14yka0x37ny34gn-zlib-1.2.12/share:/nix/store/dq74hwfjr8rnyka9yj3hxv05rg4x8jbj-curl-7.83.1/share:/nix/store/n1jgqr8xzjz9shn3ads5x07p8lqn5rqk-patchelf-0.14.5/share:/nix/store/r3ff0cflflysvm6dwdd8v0c10ickl7zx-desktops/share:/.nix-profile/share:/etc/profiles/per-user//share:/nix/var/nix/profiles/default/share:/run/current-system/sw/share

@psionic-k
Copy link
Member

Oh, my bad. If you look through the existing overrides, most of the sys packages use buildInputs, and the consequence of using propagatedBuildInputs is that this derivation isn't also having libpam available in it's buildInputs, but any crate that depends on it would have it transitively.

propagatedBuildInputs is what you imagine, causing buildInputs to be added to dependents. Should fix right up. Please close if it works.

@Goorzhel
Copy link
Author

Alas, I'm still doing something wrong
❯ git diff
diff --git a/flake.nix b/flake.nix
index f416333..bb7e469 100644
--- a/flake.nix
+++ b/flake.nix
@@ -20,7 +20,7 @@
                 (pkgs.rustBuilder.rustLib.makeOverride {
                   name = "pam-sys";
                   overrideAttrs = old: {
-                    propagatedBuildInputs = old.propagatedBuildInputs ++ [
+                    buildInputs = old.buildInputs ++ [
                       pkgs.linux-pam
                     ];

❯ nix build
warning: Git tree '/home/ag/src/OWN/radm' is dirty
error: builder for '/nix/store/289d45nn8f6asryzn7zd321r2wck0qka-crate-pam-sys-1.0.0-alpha4.drv' failed with exit code 101;
       last 10 log lines:
       >   --- stdout
       >   cargo:rustc-link-lib=pam
       >   cargo:rustc-link-lib=pam_misc
       >   cargo:rerun-if-changed=wrapper.h
       >
       >   --- stderr
       >   wrapper.h:1:10: fatal error: 'security/pam_appl.h' file not found
       >   wrapper.h:1:10: fatal error: 'security/pam_appl.h' file not found, err: true
       >   thread 'main' panicked at 'Unable to generate bindings: ()', build.rs:69:10
       >   note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
       For full logs, run 'nix log /nix/store/289d45nn8f6asryzn7zd321r2wck0qka-crate-pam-sys-1.0.0-alpha4.drv'.
error: 1 dependencies of derivation '/nix/store/kcby4nzvnf6rsz3wx1f0a6j270fhsn99-crate-pam-0.7.0.drv' failed to build
error: 1 dependencies of derivation '/nix/store/92g3n67ln017z3kq9aqmgc4iphq2l7dg-crate-radm-0.6.4.drv' failed to build
I checked `linux-pam` too, no dev output:
❯ nix repl
Welcome to Nix 2.15.1. Type :? for help.

nix-repl> (import <nixpkgs> {}).pkgs.linux-pam.outputs
[ "out" "doc" "man" ]

@psionic-k
Copy link
Member

When sys crates fail, often we can look at the build.rs script trying to do something that assumes it has access to everything. Build.rs scripts don't always interpret the provided environment correctly.

https://github.com/1wilkens/pam-sys/blob/master/build.rs

It's using bindgen.

Can you print your environment again now that libpam is included in buildInputs?

There should be a way to pass an option for the location directly to the build script and enable it to find your libraries.

@Goorzhel
Copy link
Author

❯ nix develop -i /nix/store/289d45nn8f6asryzn7zd321r2wck0qka-crate-pam-sys-1.0.0-alpha4.drv
bash-5.1$ for i in preConfigure findCrate configureCargo postConfigure overrideCargoManifest setBuildEnv; do runHook $i; done
bash-5.1$ runHook runCargo
<...>
  wrapper.h:1:10: fatal error: 'security/pam_appl.h' file not found
<...>
bash-5.1$ env | grep -i linux-pam | cut -d = -f1
NIX_CFLAGS_COMPILE_FOR_BUILD
HOST_PATH
NIX_LDFLAGS_FOR_BUILD
NIX_CFLAGS_COMPILE
buildInputs
PATH
NIX_LDFLAGS
env | grep -i pam
bash-5.1$ env | grep -i pam
NIX_GCROOT=/nix/store/pbn7ksl963v33sxvnwwnpz4v0l7v7qkd-crate-pam-sys-1.0.0-alpha4-env
configureFlags=        --bindir=/home/ag/src/OWN/radm/outputs/bin/bin --sbindir=/home/ag/src/OWN/radm/outputs/bin/sbin         --includedir=/home/ag/src/OWN/radm/outputs/out/include --oldincludedir=/home/ag/src/OWN/radm/outputs/out/include         --mandir=/home/ag/src/OWN/radm/outputs/bin/share/man --infodir=/home/ag/src/OWN/radm/outputs/bin/share/info         --docdir=/home/ag/src/OWN/radm/outputs/out/share/doc/crate-pam-sys         --libdir=/home/ag/src/OWN/radm/outputs/out/lib --libexecdir=/home/ag/src/OWN/radm/outputs/out/libexec         --localedir=/home/ag/src/OWN/radm/outputs/out/share/locale                 --bindir=/home/ag/src/OWN/radm/outputs/bin/bin --sbindir=/home/ag/src/OWN/radm/outputs/bin/sbin         --includedir=/home/ag/src/OWN/radm/outputs/out/include --oldincludedir=/home/ag/src/OWN/radm/outputs/out/include         --mandir=/home/ag/src/OWN/radm/outputs/bin/share/man --infodir=/home/ag/src/OWN/radm/outputs/bin/share/info         --docdir=/home/ag/src/OWN/radm/outputs/out/share/doc/crate-pam-sys         --libdir=/home/ag/src/OWN/radm/outputs/out/lib --libexecdir=/home/ag/src/OWN/radm/outputs/out/libexec         --localedir=/home/ag/src/OWN/radm/outputs/out/share/locale
src=/nix/store/cqjv2093az8izx225ldh3i0z5jfsy46n-pam-sys-1.0.0-alpha4.tar.gz
NIX_CFLAGS_COMPILE_FOR_BUILD= -isystem /nix/store/0zl79km49n4s0037ks1v6qyvq3d7k5my-jq-1.6-dev/include -isystem /nix/store/0zl79km49n4s0037ks1v6qyvq3d7k5my-jq-1.6-dev/include -isystem /nix/store/vzqny68wq33dcg4hkdala51n5vqhpnwc-python3-3.9.12/include -isystem /nix/store/vzqny68wq33dcg4hkdala51n5vqhpnwc-python3-3.9.12/include -isystem /nix/store/491im6imqwa9ssfixsy9wvrvi17bqmdr-linux-pam-1.5.2/include -isystem /nix/store/491im6imqwa9ssfixsy9wvrvi17bqmdr-linux-pam-1.5.2/include -isystem /nix/store/0zl79km49n4s0037ks1v6qyvq3d7k5my-jq-1.6-dev/include -isystem /nix/store/0zl79km49n4s0037ks1v6qyvq3d7k5my-jq-1.6-dev/include -isystem /nix/store/vzqny68wq33dcg4hkdala51n5vqhpnwc-python3-3.9.12/include -isystem /nix/store/vzqny68wq33dcg4hkdala51n5vqhpnwc-python3-3.9.12/include -isystem /nix/store/491im6imqwa9ssfixsy9wvrvi17bqmdr-linux-pam-1.5.2/include -isystem /nix/store/491im6imqwa9ssfixsy9wvrvi17bqmdr-linux-pam-1.5.2/include -isystem /nix/store/0zl79km49n4s0037ks1v6qyvq3d7k5my-jq-1.6-dev/include -isystem /nix/store/0zl79km49n4s0037ks1v6qyvq3d7k5my-jq-1.6-dev/include -isystem /nix/store/vzqny68wq33dcg4hkdala51n5vqhpnwc-python3-3.9.12/include -isystem /nix/store/vzqny68wq33dcg4hkdala51n5vqhpnwc-python3-3.9.12/include -isystem /nix/store/491im6imqwa9ssfixsy9wvrvi17bqmdr-linux-pam-1.5.2/include -isystem /nix/store/491im6imqwa9ssfixsy9wvrvi17bqmdr-linux-pam-1.5.2/include
PWD=/home/ag/src/OWN/radm/pam-sys-1.0.0-alpha4
HOST_PATH=/nix/store/jji13abyzk0hm0f4prf2fjh0qmcm2mn8-crate-bindgen-0.59.2/bin:/nix/store/9xg2ar3l9h8bmcch3qiikj9nssjcjpfc-crate-bindgen-0.59.2-bin/bin:/nix/store/491im6imqwa9ssfixsy9wvrvi17bqmdr-linux-pam-1.5.2/bin:/nix/store/47n5hzqpahs7yv84ia6cxp3jg9ca8r86-coreutils-9.0/bin:/nix/store/6ib6hn9fq8mgkdq2nq5f7kz050p49rp2-findutils-4.9.0/bin:/nix/store/685c5dr4agkf7vx8ya7f1r9rd9qwg2ri-diffutils-3.8/bin:/nix/store/sppjn85p06m1il70kd05drg1j26cjxd3-gnused-4.8/bin:/nix/store/49vp3yp54fqliy7k8gvxsybd50l9a82f-gnugrep-3.7/bin:/nix/store/fr7vrxblkj327ypn3vhjwfhf19lddqqd-gawk-5.1.1/bin:/nix/store/5p3qyadsv163m7zvqssiw80zh6xfv2jv-gnutar-1.34/bin:/nix/store/2bwqikh67y1231ccb71gjfrggwjw066q-gzip-1.12/bin:/nix/store/wjf2554ffvap47vanabh9lk0dmj1q295-bzip2-1.0.6.0.2-bin/bin:/nix/store/2hvj24gaq4y32cyf0jp9sj01y00k7czy-gnumake-4.3/bin:/nix/store/0d3wgx8x6dxdb2cpnq105z23hah07z7l-bash-5.1-p16/bin:/nix/store/wa31fy0bgmq7p2gcvh5xyrr7m2v8i3s2-patch-2.7.6/bin:/nix/store/dr5shmim604rh50mmihwfic80k0wa3k0-xz-5.2.5-bin/bin
CARGO_HOME=/home/ag/src/OWN/radm/pam-sys-1.0.0-alpha4/.cargo
  | jq -r 'if .lib."name" then .lib."name" else "pam_sys" end' \
NIX_RUST_LINK_FLAGS=--extern libc=/nix/store/sidmvih33f9mfr4i9yxfm76zjkxvq5vq-crate-libc-0.2.126/lib/liblibc.rlib -L dependency=/nix/store/sidmvih33f9mfr4i9yxfm76zjkxvq5vq-crate-libc-0.2.126/lib/deps -L dependency=/home/ag/src/OWN/radm/pam-sys-1.0.0-alpha4/deps --cap-lints warn
NIX_RUST_BUILD_FLAGS=--extern bindgen=/nix/store/jji13abyzk0hm0f4prf2fjh0qmcm2mn8-crate-bindgen-0.59.2/lib/libbindgen.rlib -L dependency=/nix/store/jji13abyzk0hm0f4prf2fjh0qmcm2mn8-crate-bindgen-0.59.2/lib/deps -L dependency=/home/ag/src/OWN/radm/pam-sys-1.0.0-alpha4/build_deps
NIX_LDFLAGS_FOR_BUILD= -L/nix/store/hl6bfz95l6cnww1zi8dl9w3nyygcir0c-jq-1.6-lib/lib -L/nix/store/vzqny68wq33dcg4hkdala51n5vqhpnwc-python3-3.9.12/lib -L/nix/store/7il125cr19fza1h0fxzszmsyc8dss248-rust-minimal-1.61.0/lib -L/nix/store/sidmvih33f9mfr4i9yxfm76zjkxvq5vq-crate-libc-0.2.126/lib -L/nix/store/jji13abyzk0hm0f4prf2fjh0qmcm2mn8-crate-bindgen-0.59.2/lib -L/nix/store/491im6imqwa9ssfixsy9wvrvi17bqmdr-linux-pam-1.5.2/lib -L/nix/store/hl6bfz95l6cnww1zi8dl9w3nyygcir0c-jq-1.6-lib/lib -L/nix/store/vzqny68wq33dcg4hkdala51n5vqhpnwc-python3-3.9.12/lib -L/nix/store/7il125cr19fza1h0fxzszmsyc8dss248-rust-minimal-1.61.0/lib -L/nix/store/sidmvih33f9mfr4i9yxfm76zjkxvq5vq-crate-libc-0.2.126/lib -L/nix/store/jji13abyzk0hm0f4prf2fjh0qmcm2mn8-crate-bindgen-0.59.2/lib -L/nix/store/491im6imqwa9ssfixsy9wvrvi17bqmdr-linux-pam-1.5.2/lib -L/nix/store/hl6bfz95l6cnww1zi8dl9w3nyygcir0c-jq-1.6-lib/lib -L/nix/store/vzqny68wq33dcg4hkdala51n5vqhpnwc-python3-3.9.12/lib -L/nix/store/7il125cr19fza1h0fxzszmsyc8dss248-rust-minimal-1.61.0/lib -L/nix/store/sidmvih33f9mfr4i9yxfm76zjkxvq5vq-crate-libc-0.2.126/lib -L/nix/store/jji13abyzk0hm0f4prf2fjh0qmcm2mn8-crate-bindgen-0.59.2/lib -L/nix/store/491im6imqwa9ssfixsy9wvrvi17bqmdr-linux-pam-1.5.2/lib
NIX_CFLAGS_COMPILE= -frandom-seed=pbn7ksl963 -isystem /nix/store/0zl79km49n4s0037ks1v6qyvq3d7k5my-jq-1.6-dev/include -isystem /nix/store/vzqny68wq33dcg4hkdala51n5vqhpnwc-python3-3.9.12/include -isystem /nix/store/491im6imqwa9ssfixsy9wvrvi17bqmdr-linux-pam-1.5.2/include -isystem /nix/store/0zl79km49n4s0037ks1v6qyvq3d7k5my-jq-1.6-dev/include -isystem /nix/store/vzqny68wq33dcg4hkdala51n5vqhpnwc-python3-3.9.12/include -isystem /nix/store/491im6imqwa9ssfixsy9wvrvi17bqmdr-linux-pam-1.5.2/include
buildInputs=/nix/store/sidmvih33f9mfr4i9yxfm76zjkxvq5vq-crate-libc-0.2.126 /nix/store/jji13abyzk0hm0f4prf2fjh0qmcm2mn8-crate-bindgen-0.59.2 /nix/store/491im6imqwa9ssfixsy9wvrvi17bqmdr-linux-pam-1.5.2
manifest_path=$(cargoRelativeManifest pam-sys)
echo name = \"pam-sys\" >> Cargo.lock
PATH=/nix/store/r7r10qvsqlnvbzjkjinvscjlahqbxifl-gcc-wrapper-11.3.0/bin:/nix/store/d7q0qfm12hb59wj63wyjs0hrdhmmapfz-gcc-11.3.0/bin:/nix/store/vkwlwmagq5i0if2f60ywrg2gxjf5xr9i-glibc-2.34-210-bin/bin:/nix/store/47n5hzqpahs7yv84ia6cxp3jg9ca8r86-coreutils-9.0/bin:/nix/store/10h6ymfb28wx6x8amj82h2sgw3ixrsb2-binutils-wrapper-2.38/bin:/nix/store/2b99rpx8zwdjjqkrvk7kqgn9mxhiidjy-binutils-2.38/bin:/nix/store/vr8pw7pfrvxx7nvh0abh2bhn66n9v707-jq-1.6-bin/bin:/nix/store/zgmikgwi2h57ynmzbihrhkfa6p59wxhs-remarshal-0.14.0/bin:/nix/store/vzqny68wq33dcg4hkdala51n5vqhpnwc-python3-3.9.12/bin:/nix/store/7il125cr19fza1h0fxzszmsyc8dss248-rust-minimal-1.61.0/bin:/nix/store/n1jgqr8xzjz9shn3ads5x07p8lqn5rqk-patchelf-0.14.5/bin:/nix/store/jji13abyzk0hm0f4prf2fjh0qmcm2mn8-crate-bindgen-0.59.2/bin:/nix/store/9xg2ar3l9h8bmcch3qiikj9nssjcjpfc-crate-bindgen-0.59.2-bin/bin:/nix/store/491im6imqwa9ssfixsy9wvrvi17bqmdr-linux-pam-1.5.2/bin:/nix/store/47n5hzqpahs7yv84ia6cxp3jg9ca8r86-coreutils-9.0/bin:/nix/store/6ib6hn9fq8mgkdq2nq5f7kz050p49rp2-findutils-4.9.0/bin:/nix/store/685c5dr4agkf7vx8ya7f1r9rd9qwg2ri-diffutils-3.8/bin:/nix/store/sppjn85p06m1il70kd05drg1j26cjxd3-gnused-4.8/bin:/nix/store/49vp3yp54fqliy7k8gvxsybd50l9a82f-gnugrep-3.7/bin:/nix/store/fr7vrxblkj327ypn3vhjwfhf19lddqqd-gawk-5.1.1/bin:/nix/store/5p3qyadsv163m7zvqssiw80zh6xfv2jv-gnutar-1.34/bin:/nix/store/2bwqikh67y1231ccb71gjfrggwjw066q-gzip-1.12/bin:/nix/store/wjf2554ffvap47vanabh9lk0dmj1q295-bzip2-1.0.6.0.2-bin/bin:/nix/store/2hvj24gaq4y32cyf0jp9sj01y00k7czy-gnumake-4.3/bin:/nix/store/0d3wgx8x6dxdb2cpnq105z23hah07z7l-bash-5.1-p16/bin:/nix/store/wa31fy0bgmq7p2gcvh5xyrr7m2v8i3s2-patch-2.7.6/bin:/nix/store/dr5shmim604rh50mmihwfic80k0wa3k0-xz-5.2.5-bin/bin:/run/wrappers/bin:/.nix-profile/bin:/etc/profiles/per-user//bin:/nix/var/nix/profiles/default/bin:/run/current-system/sw/bin
NIX_LDFLAGS=-rpath /home/ag/src/OWN/radm/outputs/out/lib64 -rpath /home/ag/src/OWN/radm/outputs/out/lib  -L/nix/store/hl6bfz95l6cnww1zi8dl9w3nyygcir0c-jq-1.6-lib/lib -L/nix/store/vzqny68wq33dcg4hkdala51n5vqhpnwc-python3-3.9.12/lib -L/nix/store/7il125cr19fza1h0fxzszmsyc8dss248-rust-minimal-1.61.0/lib -L/nix/store/sidmvih33f9mfr4i9yxfm76zjkxvq5vq-crate-libc-0.2.126/lib -L/nix/store/jji13abyzk0hm0f4prf2fjh0qmcm2mn8-crate-bindgen-0.59.2/lib -L/nix/store/491im6imqwa9ssfixsy9wvrvi17bqmdr-linux-pam-1.5.2/lib -L/nix/store/hl6bfz95l6cnww1zi8dl9w3nyygcir0c-jq-1.6-lib/lib -L/nix/store/vzqny68wq33dcg4hkdala51n5vqhpnwc-python3-3.9.12/lib -L/nix/store/7il125cr19fza1h0fxzszmsyc8dss248-rust-minimal-1.61.0/lib -L/nix/store/sidmvih33f9mfr4i9yxfm76zjkxvq5vq-crate-libc-0.2.126/lib -L/nix/store/jji13abyzk0hm0f4prf2fjh0qmcm2mn8-crate-bindgen-0.59.2/lib -L/nix/store/491im6imqwa9ssfixsy9wvrvi17bqmdr-linux-pam-1.5.2/lib
name=crate-pam-sys-1.0.0-alpha4-env
</details>

@psionic-k
Copy link
Member

I'd like to try and build this later and see what's not grepped. If you can strip down the example, that would help. I am suspicious of why clang is involved at all. Pam has been around since a long time before clang.

@Goorzhel
Copy link
Author

strip down the example

I can try:

  1. Add to any project's Cargo.toml
[dependencies.pam]
git = "https://github.com/1wilkens/pam"
rev = "44ef38dbd1b2fae407cb1baa926cfebcabd18474"
# crates.io has a very outdated version
  1. Your Cargo.nix will inherit this crate
pam-sys 1.0.0-alpha4
  "registry+https://github.com/rust-lang/crates.io-index".pam-sys."1.0.0-alpha4" = overridableMkRustCrate (profileName: rec {
    name = "pam-sys";
    version = "1.0.0-alpha4";
    registry = "registry+https://github.com/rust-lang/crates.io-index";
    src = fetchCratesIo { inherit name version; sha256 = "5e9dfd42858f6a6bb1081079fd9dc259ca3e2aaece6cb689fd36b1058046c969"; };
    dependencies = {
      libc = rustPackages."registry+https://github.com/rust-lang/crates.io-index".libc."0.2.126" { inherit profileName; };
    };
    buildDependencies = {
      bindgen = buildRustPackages."registry+https://github.com/rust-lang/crates.io-index".bindgen."0.59.2" { profileName = "__noProfile"; };
    };
  });
  1. nix build expecting it to fail trying to open ./security (rather than /nix/store/491im6imqwa9ssfixsy9wvrvi17bqmdr-linux-pam-1.5.2/include/security/).

Another possibility: git clone https://git.sr.ht/~goorzhel/radm --branch=nix.

@Goorzhel
Copy link
Author

Goorzhel commented Dec 8, 2023

I found out why Clang is involved:

bindgen uses libclang to parse C and C++ header files.

The link further in that paragraph about clang-sys explains why I need LIBCLANG_PATH in the flake.

I recently updated my flake and caused myself a cascade of more headaches: now crate-clang-sys-1.6.1.drv is failing with

thread 'main' panicked at 'called Result::unwrap() on an Err value: "couldn't find any valid shared libraries matching: ['libclang.so', 'libclang-*.so'], set the LIBCLANG_PATH environment variable to a path where one of these files can be found (invalid: [])"', build/dynamic.rs:206:45

But I'm guessing that's fixable with an override. I'll write back when I have more information.

@Goorzhel
Copy link
Author

Goorzhel commented Dec 9, 2023

I just shotgunned includes (turns out their order matters too) until `pam-sys` started building
diff --git a/flake.nix b/flake.nix
index b2a4784..1406d81 100644
--- a/flake.nix
+++ b/flake.nix
@@ -5,7 +5,8 @@
     nixpkgs.follows = "cargo2nix/nixpkgs";
   };
   outputs = inputs:
     with inputs;
+    mkInclude = pkg: dir: "-I${pkg}/${dir}"; in
       flake-utils.lib.eachDefaultSystem (
         system: let
           pkgs = import nixpkgs {
@@ -26,7 +27,13 @@
                 (pkgs.rustBuilder.rustLib.makeOverride {
                   name = "pam-sys";
                   overrideAttrs = old: {
-                    BINDGEN_EXTRA_CLANG_ARGS = "-I${pkgs.linux-pam}/include -I${pkgs.linuxHeaders}/include -I${pkgs.linuxHeaders}/include/linux -I${pkgs.glibc.dev}/include -I${pkgs.clang}/resource-root/include";
+                    BINDGEN_EXTRA_CLANG_ARGS = pkgs.lib.strings.concatStringsSep " "
+                    [
+                      (mkInclude pkgs.clang "resource-root/include")
+                      (mkInclude pkgs.linuxHeaders "include")
+                      (mkInclude pkgs.glibc.dev "include")
+                      (mkInclude pkgs.linux-pam "include")
+                    ];
                     LIBCLANG_PATH = pkgs.lib.makeLibraryPath [pkgs.llvmPackages.libclang.lib];
                   };
                 })

pam won't, because

the Nix builder can't find proc-macro2
❯ nix log /nix/store/r1z5zjz1m0mxz1i7b78klqm6d8f8ay3p-crate-pam-0.7.0.drv^out
@nix { "action": "setPhase", "phase": "unpackPhase" }
unpacking sources
unpacking source archive /nix/store/ifyyn67fcaalfj9f7n7dfif80xglmkv2-source
source root is source
@nix { "action": "setPhase", "phase": "patchPhase" }
patching sources
@nix { "action": "setPhase", "phase": "configurePhase" }
configuring
@nix { "action": "setPhase", "phase": "buildPhase" }
building
    Updating crates.io index
warning: spurious network error (3 tries remaining): [6] Couldn't resolve host name (Could not resolve host: index.crates.io)
warning: spurious network error (2 tries remaining): [6] Couldn't resolve host name (Could not resolve host: index.crates.io)
warning: spurious network error (1 tries remaining): [6] Couldn't resolve host name (Could not resolve host: index.crates.io)
error: failed to get `proc-macro2` as a dependency of package `pam-macros v0.0.3 (/build/source/macros)`

Caused by:
  failed to query replaced source registry `crates-io`

Caused by:
  download of config.json failed

Caused by:
  failed to download from `https://index.crates.io/config.json`

Caused by:
  [6] Couldn't resolve host name (Could not resolve host: index.crates.io)
/nix/store/gv2cl6qvvslz5h15vqd89f1rpvrdg5yc-stdenv-linux/setup: line 146: pop_var_context: head of shell_variables not a function context

but that's a story for another issue, if I get too stuck to figure it out myself again.

@Goorzhel Goorzhel closed this as completed Dec 9, 2023
@psionic-k psionic-k reopened this Dec 9, 2023
@psionic-k
Copy link
Member

I reopened because I didn't have time to check why this closed. TLDR lol

@Goorzhel
Copy link
Author

Goorzhel commented Dec 9, 2023

My bad. TL;DR version: I needed to supply -I/path/to/headers in BINDGEN_EXTRA_CLANG_ARGS for each of (in order) clang, linux, libc, and PAM so bindgen would find the necessary headers.

@Goorzhel
Copy link
Author

As for the proc-macro2 problem, the only guess I have is that the pam crate has

[workspace]
members = [
    ".",
    "macros"
]

and Nix is trying to build the ./macros workspace using only pam's dependencies.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants