This is an implementation detail leaking out into the bash environment
and it did manange to confuse me as potentially being a way to get the "default"
output name when structuredAttrs is enabled, because of the "outputName" derivation attribute.
This is very helpfull if you want to trigger partial builds in `nix
develop .#$some_package` and just need the to see all the phases, so you
can manually trigger them.
Without the change isMachO fails to work on UTF-8 locales as `read -u 4`
decoders 4 UTF-8 chars and not 4 bytes. `LANG=C` forces it to read bytes.
Closes: https://github.com/NixOS/nixpkgs/issues/431934
Presently, each patch in the for loop for patchPhase re-appends the
patchFlags. This can be harmless "patch -p1 -p1" is effectively the same
as "patch -p1". Other flags to patch, such as "-d" perform action each
time it is present in the argument list. The flagsArray doesn't contain
any patch-specific arguments and can be declared outside the loop.
This improves the implementation of `dumpVars` by removing a call to `install`.
This improves performance when sourcing setup.sh by more than 10%
It should also improve the performance when transitioning between build phases significantly as no process executions are issued anymore,
A test is added, which ensures that no extra execve calls are issued while sourcing setup.sh.
`mode` includes acls and xattrs. Those xattrs can include unsupported
attrs on the destination file system. I.E. If copying from nfs4 to ext
`fsetxattr` can be called with `system.nfs4_acl` which is an
unsupported operation on ext4. This will result in
`cp: preserving permissions for ...: Operation not supported`.
See, for instance:
https://lists.gnu.org/archive/html/coreutils/2024-09/msg00009.html
In our case we saw the following when adding a strace to the cp:
`lgetxattr("/nix/store/ihas6mzn9h54ldgp90pics0yrlmi6ln7-source", "system.nfs4_acl", NULL, 0) = -1 EOPNOTSUPP (Operation not supported)`
Removing this flag should not effect the resulting umask/permission
bits, which I think is all we care about. From the docs:
> In the absence of this option, the permissions of existing
> destination files are unchanged. Each new file is created with the
> mode of the corresponding source file minus the set-user-ID,
> set-group-ID, and sticky bits as the create mode; the operating system
> then applies either the umask or a default ACL, possibly resulting in
> a more restrictive file mode.
https://www.gnu.org/software/coreutils/manual/html_node/cp-invocation.html
So the only real problem I can foresee is if the setuid/setgid or
other sticky bits matter to a build. In which case I think an effected
build might have bigger issues.
This is a follow-up of #388908.
Previously, $out/nix-support/propagated-user-env-packages was not
created when __structuredAttrs is true, the first element of
propagatedUserEnvPkgs is null and the length of propagatedUserEnvPkgs
is at least 2.
Fixes#388829
Previously, when __structuredAttrs is true, only the first element of
propagatedUserEnvPkgs was written to
$out/nix-support/propagated-user-env-packages.
This also changes stdenv's substitute --replace-fail to error out when
the replacement is the same as the search pattern, but can't be found.
This should not cause any problems in existing code, from what I can
tell from grepping nixpkgs.
The exception for pattern==replacement was previously introduced all the
way back in 5ff872aa24, but this was
apparently only used to make the check for the warning "simpler".
Testing for the presence of an item in a space separated list with this
pattern needs to pad the list with spaces at the beginning and end.
Otherwise the first and last element will never be matched.
Resolves#354220
-p preserves permission,mode,timestamps.
When trying to copy with permission on NFS, it can fail;
The closest documentation I found on this was:
https://access.redhat.com/solutions/725513
One suggestion is to change the netapp configuration, but another that
should work for everyone is to use the cp command presented in this
patch.
With this, builds on nfs work for me. I however cannot say that I'm
certain that removing the permission preservation won't cause any other
troubles elsewhere, e.g. by perhaps introducing some sort of
non-determinism.
I've often run into substituteInPlace doing nothing when I invoked it
wrong, like:
substituteInPlace --replace-fail from to file.txt
The substitute function would pass file.txt on to substituteStream,
which complain about the extraneous argument. However, if no files are
passed, substitute is never called and substituteInPlace silently does
nothing.
It would be more annoying to make substituteInPlace accept file
arguments anywhere (since it would need to understand the arguments to
substituteStream), so let's error on this incorrect usage instead.
Change-Id: Ib2daad6f49bbe516a273a35d7f2a31fc42fd053c
Currently stdenv requires Bash 4.x that was released in 2009. This
change bumps the required version to Bash 5.x (2019, 5 years ago).
See https://mywiki.wooledge.org/BashFAQ/061 for more details.
Using a relatively modern Bash version allows us to rely on newer
features (e.g. ${var@a}) and remove workarounds for older quirks (e.g.
https://stackoverflow.com/a/7577209, “old bash empty array problem”).
Note that many setup hooks are using features added after 4.0 version,
e.g. makeWrapper uses ${var@Q} from 4.4, but some even require >5.0,
e.g. cargoBuildHook uses ${var@U} from 5.1.
The previously used pattern was introduced in #318614, but technically
leaked the default flags into the global scope. While this would
probably not make much of a practical difference, making concatTo
support default values is a much cleaner approach.
This fixes the regression introduced by c47a1e701d
on Darwin. The creation of the file using `install` and process
substitution does not work on Darwin, you get the following complain:
```
install: skipping file '/dev/fd/63', as it was replaced while being copied
```
Fixes#335016
Instead of checking for __structuredAttrs everywhere, it's easier to
just set the default value via parameter expansion and then hand the
array construction off to "concatTo".
Once more setup-hooks will be made structuredAttrs-aware, this pattern
will reduce the use of this implementation detail even more.
structuredAttrs was used here to make an assumption about the type of
the named variables passed as arguments. This can be done better by
looking at the actual types of those variables.
This gives a bit more backwards compatibility as well: Once you turn to
structuredAttrs, you should still be able to pass a bare string instead
of a list and have it behave as a whitespace-separated string like
before.
When running `nix develop` for a package, Nix records the stdenv
environment with NIX_LOG_FD set. That is, when the actual development
shell runs, it uses the functions that attempt to log to NIX_LOG_FD, but
this variable is not actually set.
As a workaround, check whether NIX_LOG_FD is set at runtime.
Example (before this change):
```console
$ nix develop --file . bash
$ echo "${NIX_LOG_FD-unset}"
unset
$ runPhase unpackPhase
bash: "$NIX_LOG_FD": Bad file descriptor
Running phase: unpackPhase
unpacking source archive /nix/store/v28dv6l0qk3j382kp40bksa1v6h7dx9p-bash-5.2.tar.gz
bash: "$NIX_LOG_FD": Bad file descriptor
source root is bash-5.2
bash: "$NIX_LOG_FD": Bad file descriptor
setting SOURCE_DATE_EPOCH to timestamp 1663942708 of file bash-5.2/y.tab.h
```
After this change:
```console
$ nix develop --file . bash
$ runPhase unpackPhase
Running phase: unpackPhase
unpacking source archive /nix/store/v28dv6l0qk3j382kp40bksa1v6h7dx9p-bash-5.2.tar.gz
source root is bash-5.2
setting SOURCE_DATE_EPOCH to timestamp 1663942708 of file bash-5.2/y.tab.h
```