Nix Packages collection & NixOS
Go to file
Maximilian Bosch aaeeef5b6c
stdenv: fix custom hardening settings when using __structuredAttrs = true;
Replaces / Closes #353131

A while ago `postgresql` switched to using structured attrs[1]. In the
PR it was reported that this made postgresql notably slower when
importing SQL dumps[2].

After a bit of debugging it turned out that the hardening was entirely
missing and the following combination of settings was the culprit:

    hardeningEnable = [ "pie" ];
    __structuredAttrs = true;

I.e. the combination of custom hardening settings and structured attrs.

What happened here is that internally the default and enabled hardening
flags get written into `NIX_HARDENING_ENABLE`. However, the value is a list
and the setting is not in the `env` section. This means that in the
structured-attrs case we get something like

    declare -ax NIX_HARDENING_ENABLE=([0]="bindnow" [1]="format" [2]="fortify" [3]="fortify3" [4]="pic" [5]="relro" [6]="stackprotector" [7]="strictoverflow" [8]="zerocallusedregs" [9]="pie")

i.e. an actual array rather than a string with all hardening flags being
space-separated which is what the hardening code of the cc-wrapper
expects[3].

This only happens if `hardeningEnable` or `hardeningDisable` are
explicitly set by a derivation: if none of those are set,
`NIX_HARDENING_ENABLE` won't be set by `stdenv.mkDerivation` and the
default hardening flags are configured by the setup hook of the
cc-wrapper[4].

In other words, this _only_ applies to derivations that have both custom
hardening settings _and_ `__structuredAttrs = true;`.

All values of `NIX_HARDENING_ENABLE` are well-known, so we don't have to
worry about escaping issues. Just forcing it to a string by
concatenating the list everytime solves the issue without additional
issues like eval errors when inheriting `env` from a structuredAttrs
derivation[5]. The price we're paying is a full rebuild.

[1] https://github.com/NixOS/nixpkgs/pull/294504
[2] https://github.com/NixOS/nixpkgs/pull/294504#issuecomment-2451482522
[3] cf3e5d3744/pkgs/build-support/cc-wrapper/add-hardening.sh (L9)
[4] cf3e5d3744/pkgs/build-support/cc-wrapper/setup-hook.sh (L114)
[5] 1e84a7fb95
2024-11-02 22:30:01 +01:00
.github .github/labeler.yml: add nixos label to switch-to-configuration-ng pull requests 2024-11-01 11:50:13 +01:00
ci Merge staging-next into staging 2024-11-01 12:06:22 +00:00
doc Merge staging-next into staging 2024-11-02 00:14:22 +00:00
lib Merge staging-next into staging 2024-11-02 00:14:22 +00:00
maintainers xtrlock-pam: python2 -> python3 (#351629) 2024-11-01 22:41:01 +01:00
nixos Revert "NixOS apply script" 2024-11-01 20:18:09 -04:00
pkgs stdenv: fix custom hardening settings when using __structuredAttrs = true; 2024-11-02 22:30:01 +01:00
.editorconfig .editorconfig: accept package.json indent as is 2024-07-29 19:24:33 +02:00
.git-blame-ignore-revs .git-blame-ignore-revs: add 'sqlc: format with nixfmt' 2024-10-28 02:27:24 +00:00
.gitattributes .gitattributes: Mark ci/OWNERS as CODEOWNERS 2024-10-10 01:40:43 +02:00
.gitignore Ignore Direnv files 2024-07-23 17:06:34 +07:00
.mailmap mailmap: remap cafkafk 2024-09-23 04:07:26 +02:00
.version .version: Make lib/.version source of truth 2024-02-26 22:34:10 +01:00
CONTRIBUTING.md CONTRIBUTING.md: extend section on getting your PR merged (#350227) 2024-10-24 14:27:52 +02:00
COPYING COPYING: 2023 -> 2024 2024-01-30 16:49:51 +01:00
default.nix
flake.nix flake.nix: exclude armv6-linux, riscv64-linux, and FreeBSD from devShells 2024-10-16 08:46:44 -07:00
README.md Release NixOS 24.05 2024-05-31 20:17:44 +02:00
shell.nix ci: Add default.nix with exposed pkgs 2024-10-08 22:13:59 +02:00

NixOS logo

Contributors badge Open Collective supporters

Nixpkgs is a collection of over 100,000 software packages that can be installed with the Nix package manager. It also implements NixOS, a purely-functional Linux distribution.

Manuals

  • NixOS Manual - how to install, configure, and maintain a purely-functional Linux distribution
  • Nixpkgs Manual - contributing to Nixpkgs and using programming-language-specific Nix expressions
  • Nix Package Manager Manual - how to write Nix expressions (programs), and how to use Nix command line tools

Community

Other Project Repositories

The sources of all official Nix-related projects are in the NixOS organization on GitHub. Here are some of the main ones:

  • Nix - the purely functional package manager
  • NixOps - the tool to remotely deploy NixOS machines
  • nixos-hardware - NixOS profiles to optimize settings for different hardware
  • Nix RFCs - the formal process for making substantial changes to the community
  • NixOS homepage - the NixOS.org website
  • hydra - our continuous integration system
  • NixOS Artwork - NixOS artwork

Continuous Integration and Distribution

Nixpkgs and NixOS are built and tested by our continuous integration system, Hydra.

Artifacts successfully built with Hydra are published to cache at https://cache.nixos.org/. When successful build and test criteria are met, the Nixpkgs expressions are distributed via Nix channels.

Contributing

Nixpkgs is among the most active projects on GitHub. While thousands of open issues and pull requests might seem a lot at first, it helps consider it in the context of the scope of the project. Nixpkgs describes how to build tens of thousands of pieces of software and implements a Linux distribution. The GitHub Insights page gives a sense of the project activity.

Community contributions are always welcome through GitHub Issues and Pull Requests.

For more information about contributing to the project, please visit the contributing page.

Donations

The infrastructure for NixOS and related projects is maintained by a nonprofit organization, the NixOS Foundation. To ensure the continuity and expansion of the NixOS infrastructure, we are looking for donations to our organization.

You can donate to the NixOS foundation through SEPA bank transfers or by using Open Collective:

License

Nixpkgs is licensed under the MIT License.

Note: MIT license does not apply to the packages built by Nixpkgs, merely to the files in this repository (the Nix expressions, build scripts, NixOS modules, etc.). It also might not apply to patches included in Nixpkgs, which may be derivative works of the packages to which they apply. The aforementioned artifacts are all covered by the licenses of the respective packages.