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

Adding flake.nix for nix users. #91

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

TornaxO7
Copy link
Contributor

A wild pikachu appeared.

Hi! This PR adds a flake.nix with a dev-shell and a package so that nix users are able to use a "nightly" version of crates-tui.

@TornaxO7 TornaxO7 mentioned this pull request Aug 13, 2024
@joshka
Copy link
Member

joshka commented Aug 13, 2024

For the non nix enlightened can you:

  • give a bit more detail about what this does
  • add some comments about the non-obvious choices of libs (e.g. the various github links)

@@ -2,3 +2,5 @@
export CRATES_TUI_CONFIG_HOME=$(pwd)/.config
export CRATES_TUI_DATA_HOME=$(pwd)/.data
export CRATES_TUI_LOG_LEVEL=DEBUG

use flake
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For direnv users who use nix + flakes: This will auto-load the dev-shell for you if you cd into the project.

Comment on lines +2 to +7
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
rust-overlay.url = "github:oxalica/rust-overlay";
flake-parts.url = "github:hercules-ci/flake-parts";
cargo-watchdoc.url = "github:ModProg/cargo-watchdoc";
};
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • nixpkgs well contains all available nix-packages which we need, especially the dependencies.
  • rust-overlay is basically a toolset for nix to, for example, fetch the latest stable toolchain of rust, while nixpkgs isn't that fast
  • flake-parts provides a better API to write a flake.nix
  • cargo-watchdoc: I personally think that this is kinda useful and nixpkgs hasn't packaged this one yet, so this github link is referring to the official repo to include it into a dev shell

Comment on lines +26 to +29
apps.default = {
type = "app";
program = self'.packages.default;
};
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This allows nix users to just run nix run and crates-tui will run without installing it.

program = self'.packages.default;
};

packages.default = pkgs.callPackage (import ./nix/package.nix) { };
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line declares a package, provided by this repository (here: crates-tui).

Comment on lines +33 to +46
devShells.default =
let
rust-toolchain = (pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml).override {
extensions = [ "rust-src" "rust-analyzer" ];
};
in
pkgs.mkShell {
packages = with pkgs; [
pkg-config
openssl
] ++ [ rust-toolchain inputs.cargo-watchdoc.packages.${system}.default ];
};
};
};
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one declares the dev shell with all required dependencies to just run cargo run or cargo build.

@TornaxO7
Copy link
Contributor Author

@joshka I hope my comments are clearing up some things, if not, feel free to ask :)

@kdheepak
Copy link
Contributor

Thanks for the PR! I like the idea of adding nix support in theory.

I personally cannot use nix on a work computer because it requires root access so I've avoided it for maintaining a setup for works across multiple machines.

  1. What are your thoughts on removing it from .envrc?
  2. How much maintenance work is this going to add if I don't use nix? Right now, if someone asks a question we'll have to point them to you :) If you'd be willing to answer questions regarding this in the future, I'd be more inclined to support a merge

@TornaxO7
Copy link
Contributor Author

What are your thoughts on removing it from .envrc?

Well, I don't mind if it gets removed (of course it would be nice if it stays there ;))

How much maintenance work is this going to add if I don't use nix?

Basically nothing I think. Because I've "included" the meta-data from the crate into the flake. So whenever you change anything to crates-tui it will also update flake.nix. The only thing which comes up in my mind is maybe updating the flake.lock from time after time. But this can be done, if it's required.

If you'd be willing to answer questions regarding this in the future, I'd be more inclined to support a merge

Aye! I wouldn't mind to get the questions

pikaThink

@joshka
Copy link
Member

joshka commented Sep 2, 2024

Revisiting this, my main question needs a bit more detail. I don't currently understand (as someone not well versed in nix) what value adding this has. Can you expand on that perhaps? What are you looking to achieve here?

@TornaxO7
Copy link
Contributor Author

TornaxO7 commented Sep 3, 2024

Revisiting this, my main question needs a bit more detail. I don't currently understand (as someone not well versed in nix) what value adding this has. Can you expand on that perhaps? What are you looking to achieve here?

Sure thing! So the main achievements which I'm looking for are:

  1. Being able to run the crates-tui from the latest commit without hassle. For example, I'll just need to execute nix run github:ratatui/crates-tui and it will do everything for me to run crates-tui in my terminal without explicitly cloning the repository, using the correct toolchain, compile it and run it then.
  2. Have a "crates-tui-nightly" package since this nix-flakes automatically provides a nix-package
  3. Being able to immediately start contributing to crates-tui or in other words: I just need to clone this repo and execute nix develop and nix will install all required dependencies and sets up the work environment so that I can immediately start to contribute to crates-tui.

I hope this clears up some questions.

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

Successfully merging this pull request may close these issues.

3 participants