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
docs/go: Document respected attributes better #97856
Conversation
Having two ways of setting these is confusing. I don't see that this is needed. Also this would mean |
Perhaps we should remove |
I think that having both
I couldn't find any reference of
The reality shows that sometimes it's super hard to get @zowoq let's put this to the test: Let's take
Tell me if there's something wrong with this patch: diff --git i/pkgs/tools/misc/gotify-cli/default.nix w/pkgs/tools/misc/gotify-cli/default.nix
index 9e9f3c84782..1b7f0fc9d57 100644
--- i/pkgs/tools/misc/gotify-cli/default.nix
+++ w/pkgs/tools/misc/gotify-cli/default.nix
@@ -19,6 +19,10 @@ buildGoModule rec {
mv $out/bin/cli $out/bin/gotify
'';
+ buildFlagsArray = [
+ "-ldflags='-X main.Version=${version} -X main.Commit=${version}'"
+ ];
+
meta = with lib; {
license = licenses.mit;
homepage = "https://github.com/gotify/cli"; Why does applying this patch doesn't make |
BTW that inline patch for nixpkgs/pkgs/servers/gotify/default.nix Lines 51 to 53 in 1435f5b
And there it does work. |
|
Doesn't need the single quotes. diff --git a/pkgs/tools/misc/gotify-cli/default.nix b/pkgs/tools/misc/gotify-cli/default.nix
index 9e9f3c84782..355bc34262f 100644
--- a/pkgs/tools/misc/gotify-cli/default.nix
+++ b/pkgs/tools/misc/gotify-cli/default.nix
@@ -19,6 +19,10 @@ buildGoModule rec {
mv $out/bin/cli $out/bin/gotify
'';
+ buildFlagsArray = [
+ "-ldflags=-X main.Version=${version} -X main.Commit=${version}"
+ ];
+
meta = with lib; {
license = licenses.mit;
homepage = "https://github.com/gotify/cli"; |
I'm not sure I understand the concern / issue, but |
This style works as well: diff --git a/pkgs/tools/misc/gotify-cli/default.nix b/pkgs/tools/misc/gotify-cli/default.nix
index 9e9f3c84782..fde9dfb9f14 100644
--- a/pkgs/tools/misc/gotify-cli/default.nix
+++ b/pkgs/tools/misc/gotify-cli/default.nix
@@ -19,6 +19,12 @@ buildGoModule rec {
mv $out/bin/cli $out/bin/gotify
'';
+ buildFlagsArray = ''
+ -ldflags=
+ -X main.Version=${version}
+ -X main.Commit=${version}
+ '';
+
meta = with lib; {
license = licenses.mit;
homepage = "https://github.com/gotify/cli"; |
DAMN. I would have never guessed it by myself, that quotes for spaces are not needed. This should be documented. I'm turning over the PR to a docs PR. |
846854c
to
51dd205
Compare
doc/languages-frameworks/go.xml
Outdated
@@ -152,7 +152,7 @@ deis = buildGoPackage rec { | |||
</callout> | |||
<callout arearefs='ex-buildGoPackage-5'> | |||
<para> | |||
<varname>buildFlags</varname> is a list of flags passed to the go build command. | |||
<varname>buildFlags</varname> is a list of flags passed to the go build command, explained with more examples <link xlink:href="#ssec-go-common-attributes">here</link>. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd remove this line and line 122 entirely and just have "Attributes used by the builders" section otherwise it still looks to be specific to buildGoPackage
.
Later we could de-dupe subPackages
, deleteVendor
and add other common attrs (e.g. excludedPackages
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed the commonly respected attributes from the examples to a common section where all of them are explained.
doc/languages-frameworks/go.xml
Outdated
@@ -221,4 +221,34 @@ done | |||
</screen> | |||
</para> | |||
</section> | |||
<section xml:id="ssec-go-common-attributes"> | |||
<title>Attributes used by the builders</title> | |||
<para>Both <link xlink:href="#ssec-go-modules"><varname>buildGoModule</varname></link> and <link xlink:href="#ssec-go-modules"><varname>buildGoPackage</varname></link> Read the attributes <varname>buildFlagsArray</varname> and <varname>buildFlags</varname> to set build flags supported by <varname>go</varname>'s commands such as <varname>go install</varname> and <varname>go build</varname>. Usually, you'd want to use one of the attributes to make the resulting executable aware of it's own version, or alike. For example:</para> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe remove buildFlags
and just have buildFlagsArray
listed here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it'd be a lie to not mention buildFlags
at all, unless we also remove it from the builder. However, we can recommend in the docs to use the array.
7043781
to
c1afcce
Compare
doc/languages-frameworks/go.xml
Outdated
-X main.Version=${version} | ||
-X main.Commit=${version} | ||
''; | ||
</programlisting> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indentation is off.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
doc/languages-frameworks/go.xml
Outdated
<para> | ||
This form should also work: | ||
</para> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<para> | |
This form should also work: | |
</para> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍.
0d73fce
to
6c00853
Compare
Squashed all changes. |
Move common attributes treated by both buildGoModule and buildGoPackage to a separate section, out of the examples' "callouts". Co-authored-by: zowoq <59103226+zowoq@users.noreply.github.com>
6c00853
to
2b35327
Compare
Thanks @doronbehar! |
Motivation for this change
Often, both forshadowfox
and forpistol
as well (see this), I experience issues setting-ldflags
for go builds. I debugged this a bit, and for shadowfox, the package in test,go install
was called with my-ldflags
(set frombuildFlagsArray
), but something unclear was wrong with the quoting, and eithergo install
failed orlink
(Go's internal linker seen called if you useNIX_DEBUG = 3
) didn't use it from some reason.I had easy success with this new option forgotify-cli
andshadowfox-updater
- no double or mixed quotes usage.It's hard to get
ldflags
/buildFlagsArray
right, this PR improves the docs on the matter.Things done
sandbox
innix.conf
on non-NixOS linux)nix-shell -p nixpkgs-review --run "nixpkgs-review wip"
./result/bin/
)nix path-info -S
before and after)