Repository: atuinsh/atuin (language: rust)

Issue:
Rust 1.78 in nix
As part of #2085, I've been trying to ensure that we properly stick to a MSRV, as stated in CONTRIBUTING.md

> We commit to supporting the latest stable version of Rust - nothing more, nothing less, no nightly.

Currently, this is 1.78. However updating the toolchain file leads to nix complaining that only 1.77 is available. 

I'm not familiar enough with nix to update this, and would love to have a way of updating MSRV to the latest stable that doesn't require some nix magic

1.79 is out in a few days, so this will need changing again


Discussion / hints:
Rust 1.79 will become stable tomorrow, and by the looks of things we still can't use 1.78 with Nix

I really really don't want to break our nix build, however I would like to ensure we properly stick to the latest stable version more.

Sorry for the ping @arcuru and @Sciencentistguy, but I'm hoping you might have a better idea of what to do 😊 

It appears there are (were?) some difficulties with rust 1.78 in nixpkgs - a quick read of https://github.com/NixOS/nixpkgs/pull/309580 it seems that changes to the way rustc uses llvm broke cross-compilation on darwin-aarch64.

I see you've got a nix flake update github action, there isn't really much you can do other than that if you want to keep using the rustc from nixpkgs.

It might be possible to use something like fenix to nixify rustc latest (or any specific version) independently of what nixpkgs is doing? I'll see if I can whip up a PR for that this evening.
That totally makes sense, thank you!

Fenix sounds cool, a PR would be amazing 🙏 
@Sciencentistguy If you want a reference, my recent projects all use a customization of [this flake](https://github.com/arcuru/pokem/blob/main/flake.nix)

It uses [crane](https://github.com/ipetkov/crane), [fenix](https://github.com/nix-community/fenix) and [pre-commit](https://github.com/cachix/git-hooks.nix), and includes checks for [tarpaulin](https://github.com/xd009642/tarpaulin) and [dependency auditing](https://github.com/rustsec/advisory-db) in addition to the usual clippy/formatting/doc stuff.
Or I'd be happy to make the changes myself. I'd just use that template I've been using and do a round of updates/customizations for atuin. I have the time this week.

Fix patch:
diff --git a/flake.lock b/flake.lock
index 4de942a1582..1b8ac53f317 100644
--- a/flake.lock
+++ b/flake.lock
@@ -1,5 +1,26 @@
 {
   "nodes": {
+    "fenix": {
+      "inputs": {
+        "nixpkgs": [
+          "nixpkgs"
+        ],
+        "rust-analyzer-src": "rust-analyzer-src"
+      },
+      "locked": {
+        "lastModified": 1717827974,
+        "narHash": "sha256-ixopuTeTouxqTxfMuzs6IaRttbT8JqRW5C9Q/57WxQw=",
+        "owner": "nix-community",
+        "repo": "fenix",
+        "rev": "ab655c627777ab5f9964652fe23bbb1dfbd687a8",
+        "type": "github"
+      },
+      "original": {
+        "owner": "nix-community",
+        "repo": "fenix",
+        "type": "github"
+      }
+    },
     "flake-compat": {
       "flake": false,
       "locked": {
@@ -52,11 +73,29 @@
     },
     "root": {
       "inputs": {
+        "fenix": "fenix",
         "flake-compat": "flake-compat",
         "flake-utils": "flake-utils",
         "nixpkgs": "nixpkgs"
       }
     },
+    "rust-analyzer-src": {
+      "flake": false,
+      "locked": {
+        "lastModified": 1717583671,
+        "narHash": "sha256-+lRAmz92CNUxorqWusgJbL9VE1eKCnQQojglRemzwkw=",
+        "owner": "rust-lang",
+        "repo": "rust-analyzer",
+        "rev": "48bbdd6a74f3176987d5c809894ac33957000d19",
+        "type": "github"
+      },
+      "original": {
+        "owner": "rust-lang",
+        "ref": "nightly",
+        "repo": "rust-analyzer",
+        "type": "github"
+      }
+    },
     "systems": {
       "locked": {
         "lastModified": 1681028828,
diff --git a/flake.nix b/flake.nix
index 678337540cc..8384a2c2625 100644
--- a/flake.nix
+++ b/flake.nix
@@ -6,11 +6,16 @@
       url = "github:edolstra/flake-compat";
       flake = false;
     };
+    fenix = {
+      url = "github:nix-community/fenix";
+      inputs.nixpkgs.follows = "nixpkgs";
+    };
   };
   outputs = {
     self,
     nixpkgs,
     flake-utils,
+    fenix,
     ...
   }:
     flake-utils.lib.eachDefaultSystem (system: let
@@ -18,6 +23,18 @@
     in {
       packages.atuin = pkgs.callPackage ./atuin.nix {
         inherit (pkgs.darwin.apple_sdk.frameworks) Security SystemConfiguration AppKit;
+        rustPlatform = let
+          toolchain =
+            fenix.packages.${system}.fromToolchainFile
+            {
+              file = ./rust-toolchain.toml;
+              sha256 = "sha256-7QfkHty6hSrgNM0fspycYkRcB82eEqYa4CoAJ9qA3tU=";
+            };
+        in
+          pkgs.makeRustPlatform {
+            cargo = toolchain;
+            rustc = toolchain;
+          };
       };
       packages.default = self.outputs.packages.${system}.atuin;
 


Test patch: