@@ -439,6 +439,23 @@ try_cross_linking:;
439
439
#if !defined(GB_SYSTEM_WINDOWS)
440
440
lib_str = gb_string_appendc (lib_str, " -L/ " );
441
441
#endif
442
+
443
+ // Check if Odin is called inside Nix build environment.
444
+ bool nix_build = false ;
445
+ #if defined(GB_SYSTEM_LINUX)
446
+ __uid_t uid = getuid ();
447
+ passwd *passw = getpwuid (uid);
448
+ if (passw != NULL ) {
449
+ int groups_len = 0 ;
450
+ getgrouplist (passw->pw_name , passw->pw_gid , NULL , &groups_len);
451
+ if (groups_len == 1 ) {
452
+ __gid_t groups[2 ];
453
+ getgrouplist (passw->pw_name , passw->pw_gid , groups, &groups_len);
454
+ const char *gr_name = getgrgid (groups[0 ])->gr_name ;
455
+ nix_build = gb_strcmp (gr_name, " nixbld" ) == 0 ;
456
+ }
457
+ }
458
+ #endif
442
459
443
460
StringSet asm_files = {};
444
461
string_set_init (&asm_files, 64 );
@@ -615,7 +632,12 @@ try_cross_linking:;
615
632
// local to the executable (unless the system collection is used, in which case we search
616
633
// the system library paths for the library file).
617
634
if (string_ends_with (lib, str_lit (" .a" )) || string_ends_with (lib, str_lit (" .o" )) || string_ends_with (lib, str_lit (" .so" )) || string_contains_string (lib, str_lit (" .so." ))) {
618
- lib_str = gb_string_append_fmt (lib_str, " \" %.*s\" " , LIT (lib));
635
+ // Inside Nix build environment, the linker will not be able to find the libraries if `-l:` is specified.
636
+ if (nix_build) {
637
+ lib_str = gb_string_append_fmt (lib_str, " \" %.*s\" " , LIT (lib));
638
+ } else {
639
+ lib_str = gb_string_append_fmt (lib_str, " -l:\" %.*s\" " , LIT (lib));
640
+ }
619
641
} else {
620
642
// dynamic or static system lib, just link regularly searching system library paths
621
643
lib_str = gb_string_append_fmt (lib_str, " -l%.*s " , LIT (lib));
0 commit comments