When I define RUSTFLAGS as a string, I get build failures with unrelated packages that define it as a list (e.g. asusctl). (error: cannot coerce a list to a string)
When I redefine it as a list, I get build failures for packages like caligula that define it as a string.
I thought that perhaps I was going about this all wrong and tried defining NIX_RUSTFLAGS instead, but then I get failures about sysroot being used multiple times (when building for a custom target).
Is there an example I could pull from regarding how to add some default RUSTFLAGS specifically when stdenv.isDarwin && buildType == "debug";?
Unfortunately that’s what I tried (and tried to describe above) – either way breaks existing packages (some having defined RUSTFLAGS as a string and others as a list of strings).
As I mentioned, asusctl uses RUSTFLAGS = [a_list]; and even with toString I get this build failure (note the toString rustflags).
… while calling the 'derivationStrict' builtin
at /builtin/derivation.nix:9:12: (source not available)
… while evaluating derivation 'asusctl-6.0.9'
whose name attribute is located at /nix/store/6zmjqqiawihw5wasbz0krvh5dvvrnsk3-source/pkgs/stdenv/generic/make-derivation.nix:334:7
… while evaluating attribute 'RUSTFLAGS' of derivation 'asusctl-6.0.9'
at /nix/store/6zmjqqiawihw5wasbz0krvh5dvvrnsk3-source/pkgs/build-support/rust/build-rust-package/default.nix:108:3:
107| # } // {
108| RUSTFLAGS = (toString rustflags) + lib.optionalString useSysroot "--sysroot ${sysroot} " + lib.optionalString isDarwinDebug "-C split-debuginfo=packed ";
| ^
109| # RUSTFLAGS = rustflags ++ lib.optionals useSysroot ["--sysroot ${sysroot}"];
error: cannot coerce a list to a string
EDIT: I also tried with lib.concatStringsSep " " rustflags
EDIT2: To clarify, I get error: value is a string while a list was expected in this case.
I’ll take a look at the PR later, but toString should normally just work
nix-repl> toString [ "a" "b" "c" ] + lib.optionalString true " test"
"a b c test"
nix-repl> toString "a b c" + lib.optionalString true " test"
"a b c test"
So something else is happening in the builder
@eljamm your code would only work for lists, not strings
It looks like this works – I think my problem was that I was trying to toString at the RUSTFLAGS = ... part lower down, which is where the error message indicated was the problem. However, having toString args.RUSTFLAGS higher up seems to work – the code for the debug symbols seems to build in my test case, and both asusctl and caligula now evaluate successfully.
Hmmm, well now I’m very confused. The above packages work, but I get it with both github:n8henrie/nix-rust-debug-info#sysroot-debug and github:n8henrie/nix-rust-debug-info#sysroot-release, which are outputs I made with a custom sysroot to make sure I didn’t break this functionality (it pulls in my nixpkgs branch with these changes). The resulting binary just exits with exit status 42.
Somehow I get infinite recursion locally, but not when I build from the repo. I’m sure I’m missing something obvious.
Locally fails to build with infinite recursion, no relevant local modifications that are unpushed:
$ git status
On branch master
Your branch is up to date with 'origin/master'.
Untracked files:
(use "git add <file>..." to include in what will be committed)
notes.md
nothing added to commit but untracked files present (use "git add" to track)
$ git remote -v
origin git@github.com:n8henrie/nix-rust-debug-info.git (fetch)
origin git@github.com:n8henrie/nix-rust-debug-info.git (push)
$
$
$ nix build --no-eval-cache .#sysroot-debug --out-link ./result-sysroot-debug --print-build-logs --show-trace
error:
… while calling the 'derivationStrict' builtin
at /builtin/derivation.nix:9:12: (source not available)
… while evaluating derivation 'nix-rust-debug-info-x86_64-unknown-linux-gnu'
whose name attribute is located at /nix/store/hrvag6fyx93x37pg1p2p8r1jkgcihblk-source/pkgs/stdenv/generic/make-
derivation.nix:334:7
… while evaluating attribute 'RUSTFLAGS' of derivation 'nix-rust-debug-info-x86_64-unknown-linux-gnu'
at /nix/store/hrvag6fyx93x37pg1p2p8r1jkgcihblk-source/pkgs/build-support/rust/build-rust-package/default.nix:10
6:49:
105| lib.optionalAttrs (args ? env.RUSTFLAGS) { env.RUSTFLAGS = RUSTFLAGS; } //
106| lib.optionalAttrs (args ? RUSTFLAGS) { inherit RUSTFLAGS; } // {
| ^
107|
… from call site
at /nix/store/hrvag6fyx93x37pg1p2p8r1jkgcihblk-source/pkgs/build-support/rust/build-rust-package/default.nix:90
:7:
89| + lib.optionalString isDarwinDebug "-C split-debuginfo=packed "
90| + lib.optionalString useSysroot "--sysroot ${sysroot} ";
| ^
91|
… while calling 'optionalString'
at /nix/store/hrvag6fyx93x37pg1p2p8r1jkgcihblk-source/lib/strings.nix:268:5:
267| # String to return if condition is true
268| string: if cond then string else "";
| ^
269|
… while evaluating derivation 'custom-sysroot-x86_64-unknown-linux-gnu'
whose name attribute is located at /nix/store/hrvag6fyx93x37pg1p2p8r1jkgcihblk-source/pkgs/stdenv/generic/make-derivation.nix:334:7
… while evaluating attribute 'RUSTFLAGS' of derivation 'custom-sysroot-x86_64-unknown-linux-gnu'
at /nix/store/hrvag6fyx93x37pg1p2p8r1jkgcihblk-source/pkgs/build-support/rust/build-rust-package/default.nix:106:49:
105| lib.optionalAttrs (args ? env.RUSTFLAGS) { env.RUSTFLAGS = RUSTFLAGS; } //
106| lib.optionalAttrs (args ? RUSTFLAGS) { inherit RUSTFLAGS; } // {
| ^
107|
error: infinite recursion encountered
at /nix/store/hrvag6fyx93x37pg1p2p8r1jkgcihblk-source/pkgs/build-support/rust/build-rust-package/sysroot/default.nix:10:10:
9| in rustPlatform.buildRustPackage {
10| inherit target RUSTFLAGS;
| ^
11|
On the same machine, with no changes, I am now getting infinite recursion from both local and github URLs. I assume some kind of cache messing with nix’s purity.
With that diff it should fail to evaluate (due to removal of the trailing {), right? Won’t adding it back in (adding the diff → removing those lines) fail to provide the debug symbols for darwin?
Yes, unfortunately with those lines commented out, it fails to fulfill the purpose of the PR; there are no .dSYM files in result/bin (EDIT: produced – I have a separate patch that puts them in $out/bin). Confirmed that it works again if I uncomment those lines (revert that diff):
Also, thank you for your time and help. I’ve tried so many permutations without any luck, it’s nice to have someone helping me brainstorm this!
EDIT2: Sorry, delta has removed the plus and minus markers in my git diff above, making it confusing. It is correct. Apparently I need to set keep-plus-minus-markers = true.