`nix` usage is confusing/broken
Ordinarily, one would expect that, for a utility, nix run github:immunant/c2rust would build the utility, set meta.mainProgram to that utility, then nix run would know to automatically launch it after build. However, what actually happens as of #3e0183e4d56f9d4d003f1ea2e9a814648debf307 is:
nix run github:immunant/c2rust
error: unable to execute '/nix/store/m7ci1fxcxaq1f8nnjkl0shssix93srr1-nix-shell/bin/nix-shell': Not a directory
Huh. That's strange! I guess we should try building it:
🐟 ❯ nix build github:immunant/c2rust
🐟 ❯ ls -la result
lrwxrwxrwx 1 ada users 53 Apr 1 17:29 result -> /nix/store/m7ci1fxcxaq1f8nnjkl0shssix93srr1-nix-shell
cating this file gives us:
------------------------------------------------------------
WARNING: the existence of this path is not guaranteed.
It is an internal implementation detail for pkgs.mkShell.
------------------------------------------------------------
declare -x AR="ar"
declare -x AR_FOR_TARGET="ar"
declare -x AS="as"
declare -x AS_FOR_TARGET="as"
declare -x CC="gcc"
. . .
Sooo, that's pretty confusing. And similarly, nix develop github:immunant/c2rust builds & puts you in the environment, but the devShell does not give you access to the c2rust utility. I'm not quite sure how this is meant to be used, but setting defaultPackage = self.devShell.${system}; doesn't make a lot of sense?
So, I resort to cloning the repo manually, then doing nix-shell:
🐟 ❯ nix-shell 2025-04-01 (Apr, Tue) 17:36:52
error:
… while calling the 'derivationStrict' builtin
at <nix/derivation-internal.nix>:34:12:
33|
34| strict = derivationStrict drvAttrs;
| ^
35|
… while evaluating derivation 'c2rust'
whose name attribute is located at /nix/store/04g613f6bn6w95kwkivlk2752azsikc0-5k90vvmnhiyjfyz2fq2qcznb2l13c8x8-source/pkgs/stdenv/generic/make-derivation.nix:336:7
… while evaluating attribute 'buildInputs' of derivation 'c2rust'
at /nix/store/04g613f6bn6w95kwkivlk2752azsikc0-5k90vvmnhiyjfyz2fq2qcznb2l13c8x8-source/pkgs/stdenv/generic/make-derivation.nix:383:7:
382| depsHostHost = elemAt (elemAt dependencies 1) 0;
383| buildInputs = elemAt (elemAt dependencies 1) 1;
| ^
384| depsTargetTarget = elemAt (elemAt dependencies 2) 0;
(stack trace truncated; use '--show-trace' to show the full, detailed trace)
error: attribute 'pkgconfig' missing
at /home/ada/Projects/c2rust/default.nix:14:5:
13| pkgs.openssl
14| pkgs.pkgconfig
| ^
15| pkgs.python3
Did you mean one of pkg-config or pkgconf?
Yeah, sadly, it looks like nix support is mostly broken, in this repo. :P As it's set up, nix develop might be useful for manually pinning your deps, but everything else (sandboxed build, dev environments that use c2rust as nativeBuildInput alongside recommended utilities, etc) appears missing or broken. Also noteworthy that relying entirely on nix-shell is not recommended, unless you're using niv to pin your nixpkgs stuff. Otherwise it has to use the system channel -- which means that the toolchain versions end up set to whatever nixpkgs is on, rather than whatever your repo was at, at the time you built it.
Edit: so, I found that one of the maintainers said:
We're not in a position to review and maintain nix things for c2rust, but we may be able to merge this (like the other existing nix things) with no promises about maintainability.
Totally reasonable! If you want, I can make a PR to fix all these features, so that Nix users can get the full benefit. I've been using Nix for a long time, and package my own Rust programs with it. What you have here is a decent start, but with a few improvements it could be awesome. :)
Edit: so, I found that one of the maintainers said:
We're not in a position to review and maintain nix things for c2rust, but we may be able to merge this (like the other existing nix things) with no promises about maintainability.
Totally reasonable! If you want, I can make a PR to fix all these features, so that Nix users can get the full benefit. I've been using Nix for a long time, and package my own Rust programs with it. What you have here is a decent start, but with a few improvements it could be awesome. :)
Feel free to open a PR to fix these nix issues. We just won't be able to very meaningfully review or maintain it, unfortunately. Thanks for the help, though!