Add an explicit dependency on netbase for /etc/protocols Certain functions in glibc look for files present in /etc such as getprotobyname which reads /etc/protocols. If you are using Nix over a Linux installation, this file may not be present, and therefore it will cause errors. - add netbase as a new package in nixpks - add a dependency in glibc on it using postPatchPhase and substitute the path Fixes #124401main
parent
86b4033b23
commit
4687d7523b
@ -0,0 +1,17 @@ |
||||
# /etc files {#etc} |
||||
|
||||
Certain calls in glibc require access to runtime files found in /etc such as `/etc/protocols` or `/etc/services` -- [getprotobyname](https://linux.die.net/man/3/getprotobyname) is one such function. |
||||
|
||||
On non-NixOS distributions these files are typically provided by packages (i.e. [netbase](https://packages.debian.org/sid/netbase)) if not already pre-installed in your distribution. This can cause non-reproducibility for code if they rely on these files being present. |
||||
|
||||
If [iana-etc](https://hydra.nixos.org/job/nixos/trunk-combined/nixpkgs.iana-etc.x86_64-linux) is part of your _buildInputs_ then it will set the environment varaibles `NIX_ETC_PROTOCOLS` and `NIX_ETC_SERVICES` to the corresponding files in the package through a _setup-hook_. |
||||
|
||||
```bash |
||||
❯ nix-shell -p iana-etc |
||||
|
||||
[nix-shell:~]$ env | grep NIX_ETC |
||||
NIX_ETC_SERVICES=/nix/store/aj866hr8fad8flnggwdhrldm0g799ccz-iana-etc-20210225/etc/services |
||||
NIX_ETC_PROTOCOLS=/nix/store/aj866hr8fad8flnggwdhrldm0g799ccz-iana-etc-20210225/etc/protocols |
||||
``` |
||||
|
||||
Nixpkg's version of [glibc](https://hydra.nixos.org/job/nixos/trunk-combined/nixpkgs.glibc.x86_64-linux) has been patched to check for the existence of these environment variables. If the environment variable are *not set*, then it will attempt to find the files at the default location within _/etc_. |
@ -0,0 +1,51 @@ |
||||
diff --git a/nss/nss_files/files-XXX.c b/nss/nss_files/files-XXX.c
|
||||
index 1db9e46127..3a567e0224 100644
|
||||
--- a/nss/nss_files/files-XXX.c
|
||||
+++ b/nss/nss_files/files-XXX.c
|
||||
@@ -75,8 +75,20 @@ internal_setent (FILE **stream)
|
||||
|
||||
if (*stream == NULL)
|
||||
{
|
||||
- *stream = __nss_files_fopen (DATAFILE);
|
||||
-
|
||||
+ const char *file = DATAFILE;
|
||||
+
|
||||
+ #ifdef NIX_DATAFILE
|
||||
+ // use the Nix environment variable such as `NIX_ETC_PROTOCOLS`
|
||||
+ char *path = secure_getenv (NIX_DATAFILE);
|
||||
+
|
||||
+ // if the environment variable is set, then read from the /nix/store entry instead
|
||||
+ if (path && path[0]) {
|
||||
+ file = path;
|
||||
+ }
|
||||
+ #endif
|
||||
+
|
||||
+ *stream = __nss_files_fopen (file);
|
||||
+
|
||||
if (*stream == NULL)
|
||||
status = errno == EAGAIN ? NSS_STATUS_TRYAGAIN : NSS_STATUS_UNAVAIL;
|
||||
}
|
||||
diff --git a/nss/nss_files/files-proto.c b/nss/nss_files/files-proto.c
|
||||
index c30bedc0aa..b321e68d3c 100644
|
||||
--- a/nss/nss_files/files-proto.c
|
||||
+++ b/nss/nss_files/files-proto.c
|
||||
@@ -23,6 +23,7 @@ NSS_DECLARE_MODULE_FUNCTIONS (files)
|
||||
|
||||
#define ENTNAME protoent
|
||||
#define DATABASE "protocols"
|
||||
+#define NIX_DATAFILE "NIX_ETC_PROTOCOLS"
|
||||
|
||||
struct protoent_data {};
|
||||
|
||||
diff --git a/nss/nss_files/files-service.c b/nss/nss_files/files-service.c
|
||||
index bfc2590699..0bff36aee5 100644
|
||||
--- a/nss/nss_files/files-service.c
|
||||
+++ b/nss/nss_files/files-service.c
|
||||
@@ -24,6 +24,7 @@ NSS_DECLARE_MODULE_FUNCTIONS (files)
|
||||
|
||||
#define ENTNAME servent
|
||||
#define DATABASE "services"
|
||||
+#define NIX_DATAFILE "NIX_ETC_SERVICES"
|
||||
|
||||
struct servent_data {};
|
||||
|
Loading…
Reference in new issue