panic on nixos
ever since updating on nixos I get this panic message
thread 'main' panicked at src/main.rs:87:61:
called `Option::unwrap()` on a `None` value
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Yup, can confirm. I don't know much rust but I'm not sure if the stack trace is any help at all. The only mint related lines seem to be around 13 and 14.
thread 'main' panicked at src/main.rs:87:61:
called `Option::unwrap()` on a `None` value
stack backtrace:
0: 0x55ce46401c32 - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::hd067277452905fe3
1: 0x55ce46425b83 - core::fmt::write::he8c54b1b75450954
2: 0x55ce463fe763 - std::io::Write::write_fmt::h24912c1e401ba6d1
3: 0x55ce46401a82 - std::sys::backtrace::BacktraceLock::print::hdf23e03df5369928
4: 0x55ce46403072 - std::panicking::default_hook::{{closure}}::h410657f83c887868
5: 0x55ce46402e75 - std::panicking::default_hook::h89d852edc127c4b8
6: 0x55ce46403a92 - std::panicking::rust_panic_with_hook::hd12d0c7813293dad
7: 0x55ce464037e6 - std::panicking::begin_panic_handler::{{closure}}::h0b9dd56a7f229e1a
8: 0x55ce46402139 - std::sys::backtrace::__rust_end_short_backtrace::hfc673033d2b0cd00
9: 0x55ce464034ad - __rustc[8c94f3b18780567b]::rust_begin_unwind
10: 0x55ce46423600 - core::panicking::panic_fmt::h3e85405dee1a1369
11: 0x55ce4642368c - core::panicking::panic::h865418c562774721
12: 0x55ce46423579 - core::option::unwrap_failed::he503da1c147f7412
13: 0x55ce45fdbcaa - <mint::Args as clap_builder::derive::Args>::augment_args::hc28a4b51847ac5ad
14: 0x55ce45fd8d49 - mint::main::hb71a1ea25e39b453
15: 0x55ce45fdcd63 - std::sys::backtrace::__rust_begin_short_backtrace::heb83d7f7ba2723a4
16: 0x55ce45fd732d - std::rt::lang_start::{{closure}}::h1f89053be7f9c1f8
17: 0x55ce463fa3a4 - std::rt::lang_start_internal::h71611c6ff65e6c36
18: 0x55ce45fdc195 - main
19: 0x7fd7da02a47e - __libc_start_call_main
20: 0x7fd7da02a539 - __libc_start_main_impl
21: 0x55ce45fd6425 - _start
22: 0x0 - <unknown>
I also checked src/main.rs and the offending line seems to be the following:
87:#[command(author, version=mint_lib::built_info::GIT_VERSION.unwrap())]
It seems that mint_lib::built_info is importing the file built.rs which is supposed to write something somewhere. Maybe that is failing? I don't really know though. That's as far as I could get.
Edit 2: Okay, so I did a bit more digging and found out that the stuff I mentioned previously is not relevant at all. The problem seems to be in the built.rs file generated during build. Below are the relevant lines:
#[doc=r#"If the crate was compiled from within a git-repository, `GIT_VERSION` contains HEAD's tag. The short commit id is used if HEAD is not tagged."#]
#[allow(dead_code)]
pub static GIT_VERSION: Option<&str> = None;
The GIT_VERSION variable is being set to None here. This is what's causing the .unwrap() to fail.
I see what's happening here though. While nix copies .cargo and .github dirs as well as .gitignore to the build sandbox, it does not copy the .git dir, which is what identifies a dir as a git repo and is also what built seems to use for getting the build metadata (If the crate was compiled from within a git-repository).
I think a fallback version number in such cases where GIT_VERSION is None may help solve this issue.
Alright, I seem to have figured it out. All I did was simply replace the GIT_VERSION.unwrap() calls with GIT_VERSION.unwrap_or("git master") and voila, the program seems to launch successfully. Here's the patch in case anyone wants to use this as an ad-hoc solution.
diff --git a/mint_lib/src/lib.rs b/mint_lib/src/lib.rs
index 1e30b97..9e4daa1 100644
--- a/mint_lib/src/lib.rs
+++ b/mint_lib/src/lib.rs
@@ -16,7 +16,7 @@ pub mod built_info {
include!(concat!(env!("OUT_DIR"), "/built.rs"));
pub fn version() -> &'static str {
- GIT_VERSION.unwrap()
+ GIT_VERSION.unwrap_or("git master")
}
}
diff --git a/src/gui/mod.rs b/src/gui/mod.rs
index 22b4859..f88758d 100644
--- a/src/gui/mod.rs
+++ b/src/gui/mod.rs
@@ -62,7 +62,7 @@ pub fn gui(dirs: Dirs, args: Option<Vec<String>>) -> Result<(), MintError> {
..Default::default()
};
eframe::run_native(
- &format!("mint {}", mint_lib::built_info::GIT_VERSION.unwrap()),
+ &format!("mint {}", mint_lib::built_info::GIT_VERSION.unwrap_or("git master")),
options,
Box::new(|cc| Ok(Box::new(App::new(cc, dirs, args)?))),
)
diff --git a/src/main.rs b/src/main.rs
index f87990e..71d0b0f 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -84,7 +84,7 @@ enum Action {
}
#[derive(Parser, Debug)]
-#[command(author, version=mint_lib::built_info::GIT_VERSION.unwrap())]
+#[command(author, version=mint_lib::built_info::GIT_VERSION.unwrap_or("git master"))]
struct Args {
#[command(subcommand)]
action: Option<Action>,
I packaged this in my NUR (also solving the GIT_VERSION problem), here's the source: https://github.com/gepbird/nur-packages/blob/main/pkgs/mint-mod-manager/default.nix
To try it out: nix run github:gepbird/nur-packages#mint-mod-manager
If you don't want to compile it yourself, you can add my cache first: nix run github:NixOS/nixpkgs#cachix -- use gepbird-nur-packages