Getting into rust and gtk programming

Hello everyone!

I recently installed NixOS and I’m quite happy using it to manage my settings and programs. I am not a programmer by any standard, I only have a little experience writing Python scripts for work and for private use.

On the Linux distro I’ve used before I played a little bit with rust, mostly by reading through the rust book and writing some little toy programs. I would like to continue with this endeavor and in the future I would also like to get a bit into graphical applications using gtk and, who knows, maybe even publish a usable program some day.

Now that I’m on NixOS I’m not really sure how to setup rust. The rust book recommends to install rustup through some shell script and then install dependencies through cargo if needed. This is what I did on fedora, but it doesn’t feel very nix-y. The NixOS wiki mentions about a gazillion other ways to install rust, many of which seem to target experienced programmers writing big projects. Should I already look into one of these methods or don’t they have a benefit in my current situation?

Say I want to get into gtk in the mid-future. The gtk-rs book tells me I will need some other dependencies. I’m also interested what would be the recommended way to get into gtk programming with rust on NixOS.

Thank you very much for your help!

The default rustup install script from https://rustup.rs/ will not work on NixOS due it being a dynamically linked executable (not compatible with how NixOS does things)

Instead, you can install the rustup package into your environment and use rustup default stable to get a working rust toolchain without any fuss.

If you want to include external libraries into your rust projects you’re going to have to look into setting up development environments in Nix. I recommend going through the tutorials in https://nix.dev/ to get yourself oriented with using Nix.

Otherwise, there’s no shame in not using NixOS if you’re just starting out with programming/Nix. Nix can be installed and used on most Linux distributions (like Fedora).

Also the NixOS wiki is located here NixOS Wiki - NixOS Wiki not (nixos dot wiki)

Also, if you want to use NixOS for system-management, but still want to use imperative stuff at the same time, you could try Distrobox. (docs here)

Often you’ll find things that are hard to get set up in NixOS, and something like that can be a really good backup option. Especially when starting out.

(Do note that you won’t get Nix’s benefits in the container!)

Thanks to both of you! I think for now I will stay with a distrobox, but I’ll make sure to read through the nix.dev page and try to figure out dev shells :slight_smile: