1. 22
  1. 5

    Author here. Feel free to ask any questions.

    carnix did not work for my personal projects and after failing to fix it, I created crate2nix.

    For me, it is also a personal goal for this year to publish software and/or blog articles. Despite of or because of being an experienced professional software developer, this has been difficult for me: I always think that I should be able to do better. So, publishing this in an early but useful state is already a medium-sized triumph for me :)

    1. 1

      Nice work!

      • The README states that crate2nix only works on Linux. But after replacing nixos-unstable in the shell.nix of crate2nix and replacing nixos in the generated default.nix file, it seems to work fine in macOS.

      • It doesn’t seem to work correctly in a directory that is a Cargo workspace.

      Keep up the good work!

      1. 2

        Thanks a lot!

        1. platform support: nice to know! for the generated files, it still filters all dependencies restricted to a target config to Linux. if you don’t have Linux specific targets, that’s fine, of course. I did this because some obscure fuchsia, windows libs broke my build.

        2. true: I should mention it in the restrictions. it should also be easy to do better.

        feel very free to file bugs for dependencies that break the tool.

      2. 1

        Any thoughts on using https://github.com/google/cargo-raze and Bazel inside Nix?

        1. 1

          I haven’t tried cargo-raze but I looked at the code for inspiration. I decided to use tera because of that.

          I use sandboxed builds. If bazel uses its own caches, I don’t know how that should work. Do you have an idea?

          For me, it is important and what I like about nix that I just run nix build or nixops deploy and I do not have to install any other dependencies.

          1. 1

            Oh, I forgot to mention that the other way around looks quite fancy:

            https://www.tweag.io/posts/2018-03-15-bazel-nix.html

            Using nix to install some binaries/dependencies from blaze.

            That said, I am not sure if there is a proper ecosystem around blaze? E.g. deployment tools integration or similar?

            1. 1

              I think it would be a sandbox in a sandbox, which should work fine. The Bazel build would benefit users on Windows (without MinGW)

              Bazel has a nixpkg IIRC, so it shouldn’t be too difficult to get started.

              Bazel sandbox would also give you a few additional features:

              1. Remote caching across a network
              2. Remote execution on a build cluster

              These can accelerate the build process.

              I haven’t tried Rust + Bazel + Nix, so was interested if you had!

              1. 1

                The sandboxing problem that I had in mind was no network connectivity (except in-built nix fetchers). That would block the features that you mentioned, correct? also how to access even a local cache and update it?

                I haven’t really set it up for myself but remote builders look easy to setup. Not sure how hard it is to generalize that to a bigger cluster.

                Remote caching should also be possible, e.g. with cachix.

                Maybe bazel does it better.

        2. 4

          Various problems with Nix builds were one reason I was recently arguing in another thread that one reason I wouldn’t promote Rust over C for system tools and things like Emacs, at this stage, is that C toolchains are basically guaranteed to be the first thing that works and that never breaks in all of the distributions and build systems. That might be mostly just a self-perpetuating situation, but there’s something to be said for being the decades-old established base system…

          1. 1

            A C compiler is everywhere. But the whole C toolchains? Many of them haven’t even been properly ported to Windows.

          2. 2

            Nice work! And kuddos for the very clean codebase.

            Out of curiosity, did you try reaching pmeunier to report your bug? I guess he would be happy to know which use cases of yours failed with his tool :).

            1. 2

              Thank you! Yes, I did report bugs and also tried to fix them. There are quite some open bugs: carnix. I don’t blame him, probably just not enough bandwidth.

              That said, I am very willing to work together with anyone on a cool/canonical solution for rust/nix that also works for me.