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

payme: fix version number string #297480

Merged
merged 3 commits into from
Mar 22, 2024
Merged

Conversation

cimm
Copy link
Contributor

@cimm cimm commented Mar 20, 2024

Description of changes

The current payme version in nixpkgs unstable does not show the correct version string for the application, notice the "local" in the version number:

$ payme --version
payme version local (local), built at 2024-03-14T11:42:21+01:00

This pull request corrects to version string as requested by the application developer:

$ payme --version
payme version v1.2.0 (416d53e3f518898a0411889a5af08e8d9858e70e), built at 2024-03-20T15:29:31+01:00

Background discussion can be found in the payme repo issue.

Things done

  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandboxing enabled in nix.conf? (See Nix manual)
    • sandbox = relaxed
    • sandbox = true
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • 24.05 Release Notes (or backporting 23.05 and 23.11 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
  • Fits CONTRIBUTING.md.

Add a 👍 reaction to pull requests you find important.

@cimm cimm changed the title payme: fix version numer string payme: fix version number string Mar 20, 2024
"-s"
"-w"
"-X main.gitRefName=v${version}"
"-X main.gitCommit=416d53e3f518898a0411889a5af08e8d9858e70e"
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure if hard coding the commit here is a great idea.
This is probably pretty easy to overlook and probably (i'm not sure on that?) can't get updated by r-ryantm

Copy link
Member

Choose a reason for hiding this comment

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

Good catch, this won't be updated. We should just hardcode this to a dummy value

Copy link
Member

Choose a reason for hiding this comment

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

IIRC r-ryantm runs the updateScript. Then we (?) can write a script that updates these values.

Copy link
Contributor Author

@cimm cimm Mar 20, 2024

Choose a reason for hiding this comment

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

Thanks for the feedback, I moved the commit to a variable in f4f5a30, is there a better option?

Copy link
Member

Choose a reason for hiding this comment

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

Is this value useful somehow?

If it isn't, then we can do as @SuperSandro2000 suggested and fill it with zeros or with deadfish five times - deadfishdeadfishdeadfishdeadfishdeadfish.
Else, I need to re-read the manuals on how to write updater scripts...

Copy link
Contributor Author

@cimm cimm Mar 21, 2024

Choose a reason for hiding this comment

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

I searched the nixpkgs repository for possible solutions. There seem to be two solutions to this. The first is to hard code the commit like I did in commit f4f5a30 (see 1, 2 or 3 for previous work). Then there is the second option, which stores the commit in a temporary file to use later (see 1, 2 or 3 for previous work).

The second option seems the most automated one. I tried using this second option, with a temporary COMMIT file, but could not get it to work. Even though it works if I try to build one of the other packages linked above.

  src = fetchFromGitHub {
    owner = "jovandeginste";
    repo = "payme";
    rev = "v${version}";
    hash = "sha256-WE/sAs0VSeb5UKkUy1iyjyXtgDmlQhdZkw8HMMSbQiE=";
    leaveDotGit = true;
    postFetch = ''
      git -C $out rev-parse HEAD > $out/COMMIT
      find "$out" -name .git -print0 | xargs -0 rm -rf
    '';
  };

  [...]
  
  preBuild = ''
    ldflags+=" -X main.gitCommit=$(cat COMMIT)"
  '';

The build fails as it can't find the COMMIT file. I don't know if it's never created (as in the postFetch is not executed) or if I am pointing to the wrong location in the preBuild step?

cat: COMMIT: No such file or directory

Any idea what I am missing here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@AndersonTorres As for your question, whether this is useful? It depends on your point of view, I suppose. The only thing I am trying to achieve here is adding the commit to the version string; it doesn't "change" the application, but adding the commit to the application's version output would make the nix version consistent with the binary compiled by the application developer.

Copy link
Member

Choose a reason for hiding this comment

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

Any idea what I am missing here?

$out from $src is not the same as from outer derivation.


About the value of commit hash, this is precisely the work for an updater script.
I suggest looking at how unstableGitUpdater grabs Git hashes and steal copy their ideas.

Copy link
Contributor Author

@cimm cimm Mar 21, 2024

Choose a reason for hiding this comment

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

I got it; the changes in 39b733e find the commit dynamically; it's no longer hard-coded in the file. I learned something new, thanks for the help!

@@ -8,11 +8,27 @@ buildGoModule rec {
owner = "jovandeginste";
repo = "payme";
rev = "v${version}";
hash = "sha256-WE/sAs0VSeb5UKkUy1iyjyXtgDmlQhdZkw8HMMSbQiE=";
hash = "sha256-2gZgmYgLaJQRQ+3VOUDnMm5QBjfKyxyutVf9NrbGO3g=";
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 somewhat dangerous, since it modified the hash.

However, given that I can't provide a better solution right now, I will not pursue this.

Copy link
Member

Choose a reason for hiding this comment

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

The easiest solution would be to just fill that has with zeros and don't worry about it but if you want to go the complicated route, sure.

@SuperSandro2000 SuperSandro2000 merged commit 506939e into NixOS:master Mar 22, 2024
22 of 23 checks passed
@cimm cimm deleted the payme-fix-version branch March 22, 2024 12:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants