Skip to content

Set version from LEMMY_VERSION env var#6254

Closed
Nutomic wants to merge 2 commits intomainfrom
version-env-var
Closed

Set version from LEMMY_VERSION env var#6254
Nutomic wants to merge 2 commits intomainfrom
version-env-var

Conversation

@Nutomic
Copy link
Member

@Nutomic Nutomic commented Dec 16, 2025

The change in #6246 is overly complicated, it requires extra bash logic to write the version name to a specific file path, and must be formatted to include Rust logic. In comparison this approach is much simpler:

  • In debug builds use version from Cargo.toml
  • In release builds use LEMMY_VERSION env var which can easily be set via Docker build-arg. If the value is nightly add current date, and if it is missing use the current version from git. This avoids cases where instances add their own patches to their forked code, but still show up as running an official release which can make debugging difficult.

Copy link
Member

@dessalines dessalines left a comment

Choose a reason for hiding this comment

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

This PR doesn't solve the git recompilation issue(the main problem), and still keeps all the version building logic inside lemmy, when it should be moved outside of lemmy as a pre-release step.

I already tried this in another branch, and ran into some docker limitations commented on in the other issue.

If you'd like to do an env var, I'm not opposed, but please keep all the version name logic outside lemmy and only have lemmy read those env vars.

Comment on lines 58 to 59
None => git_version::git_version!(
args = ["--tags", "--dirty=-modified"],
Copy link
Member

Choose a reason for hiding this comment

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

This is the main issue. Remove this and move it to the docker build (and you'll run into the docker bug I commented on in the other issue). Its causing re-compiles on every git dirty modification.

Copy link
Member Author

@Nutomic Nutomic Dec 17, 2025

Choose a reason for hiding this comment

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

Thats not a problem because its only checking the version from git in release builds. Debug builds use the version from Cargo.toml instead. Moving to Dockerfile is not ideal because it should also work for native builds.

}
match option_env!("LEMMY_VERSION") {
// For nightly add current date
Some("nightly") => format!("nightly-{}", chrono::Utc::now().date_naive()),
Copy link
Member

Choose a reason for hiding this comment

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

Just fill this from docker, its weird to have a special case adding the date when it can just be added in the docker build.

Copy link
Member Author

Choose a reason for hiding this comment

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

Did that in the last commit, although I dont like it much because it makes the dockerfile more complex, and needs to be written twice (once for x86 and once for ARM). Doing this in Rust is much easier, I dont understand why you have a problem with that.

)
.to_string()
}
match option_env!("LEMMY_VERSION") {
Copy link
Member

Choose a reason for hiding this comment

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

Just make this option_env!("LEMMY_VERSION").unwrap_or(env!("CARGO_PKG_VERSION"))

There's no reason to have special debug cases.

Copy link
Member Author

Choose a reason for hiding this comment

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

This is not for debug but for production. Many instances like lemmy.world run their own patches on top of our own releases, and by using the git version like this it is immediately clear. Otherwise they would appear to be running an official release which would be very misleading.

Comment on lines +55 to +60
// Use version from git if none was passed via env
git_version::git_version!(
args = ["--tags", "--dirty=-modified"],
fallback = env!("CARGO_PKG_VERSION")
)
.to_string()
Copy link
Member

@dessalines dessalines Jan 12, 2026

Choose a reason for hiding this comment

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

I still feel pretty strongly that we should move all this git out of lemmy. Even if it should be run only in release builds, I still think it could affect compiles in weird ways. And something that should be done as a pre-release step anyway. If people want custom versions numbers its on them to set, not us, and it should use the env var (or a version file like lemmy-ui)

I won't block this tho, so merge as you see fit.

@Nutomic
Copy link
Member Author

Nutomic commented Jan 13, 2026

This is probably unnecessary, and I dont want to make more changes to versioning now that its finally working.

@Nutomic Nutomic closed this Jan 13, 2026
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.

2 participants

Comments