Current build helpers and setup hooks tend to override phases from the base workflow, making it difficult to coexist with the build process from different toolchains.
Alternative models of pkgs
and build helpers, such as module-configured pkgs
and package-level overlays , may solve this problem, but they still have a long way to go.
For the current model of stdenv/generic/setup.sh
, setup hooks, and build helper, we could significantly increase the interoperability from different workflows by extracting the build commands from each stage into a Bash function, such as cmakeConfigure
from cmakeConfigurePhase
or makeConfigure
from the stdenv
-configurePhase
. A developer could then invoke the specific Bash function to insert part of the build process from another workflow and enjoy the associated attributes.
For example, Apptainer is a Go application configured through a configuration script but still needs the Go modules fetched by buldGoModule
during its configure phase. Instead of invoking the configuration file manually inside postConfigure
, we could call scriptConfigure
inside the postConfigure
phase and specify the name of the configuration file and the configuration flags through the configureScript
and configureFlags
attributes.
buildGoModule {
configureScript = "mconfig";
configureFlags = [
"--localstatedir=${plaleholder "out"}/var/lib"
"--runstatedir=/var/run"
];
postConfigure = ''
scriptConfigure
'';
# ...
}
I created a PR that implements this idea into stdenv/generic/setup.sh
.
NixOS:staging
← ShamrockLee:stdenv-make-logic
opened 04:36AM - 25 Mar 24 UTC
## Description of changes
Extract `Make-based` build process into separated B… ash functions to make them reusable by packages, making them reusable by packages using a language- or framework-specific build helpers that rewrite the phases.
Proposed Bash functions containing the make-related logic:
- makeBuild
- makeCheck
- makeInstall
- makeInstallCheck
~Name each Make-based phases `make*Phase` and specify `*Phase=make*Phase` by default. This makes it align with build process based on other build tools such as CMake.~ Withhold due to the scale of fixes regarding the wide-spread "phases are Bash function" assumption. See #299045.
Use `apptainer` as an example how packages using `buildGoModule` could benefit from the Make-based build commands provided by `stdenv.mkDerivation`.
<!--
For package updates please link to a changelog or describe changes, this helps your fellow maintainers discover breaking updates.
For new packages please briefly describe the package or provide a link to its homepage.
-->
## Things done
- Built on platform(s)
- [X] x86_64-linux
- [ ] aarch64-linux
- [ ] x86_64-darwin
- [ ] aarch64-darwin
- For non-Linux: Is sandboxing enabled in `nix.conf`? (See [Nix manual](https://nixos.org/manual/nix/stable/command-ref/conf-file.html))
- [ ] `sandbox = relaxed`
- [ ] `sandbox = true`
- [ ] Tested, as applicable:
- [NixOS test(s)](https://nixos.org/manual/nixos/unstable/index.html#sec-nixos-tests) (look inside [nixos/tests](https://github.com/NixOS/nixpkgs/blob/master/nixos/tests))
- and/or [package tests](https://nixos.org/manual/nixpkgs/unstable/#sec-package-tests)
- or, for functions and "core" functionality, tests in [lib/tests](https://github.com/NixOS/nixpkgs/blob/master/lib/tests) or [pkgs/test](https://github.com/NixOS/nixpkgs/blob/master/pkgs/test)
- made sure NixOS tests are [linked](https://nixos.org/manual/nixpkgs/unstable/#ssec-nixos-tests-linking) to the relevant packages
- [ ] Tested compilation of all packages that depend on this change using `nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD"`. Note: all changes have to be committed, also see [nixpkgs-review usage](https://github.com/Mic92/nixpkgs-review#usage)
- [ ] Tested basic functionality of all binary files (usually in `./result/bin/`)
- [24.05 Release Notes](https://github.com/NixOS/nixpkgs/blob/master/nixos/doc/manual/release-notes/rl-2405.section.md) (or backporting [23.05](https://github.com/NixOS/nixpkgs/blob/master/nixos/doc/manual/release-notes/rl-2305.section.md) and [23.11](https://github.com/NixOS/nixpkgs/blob/master/nixos/doc/manual/release-notes/rl-2311.section.md) Release notes)
- [ ] (Package updates) Added a release notes entry if the change is major or breaking
- [ ] (Module updates) Added a release notes entry if the change is significant
- [ ] (Module addition) Added a release notes entry if adding a new NixOS module
- [X] Fits [CONTRIBUTING.md](https://github.com/NixOS/nixpkgs/blob/master/CONTRIBUTING.md).
<!--
To help with the large amounts of pull requests, we would appreciate your
reviews of other pull requests, especially simple package updates. Just leave a
comment describing what you have tested in the relevant package/service.
Reviewing helps to reduce the average time-to-merge for everyone.
Thanks a lot if you do!
List of open PRs: https://github.com/NixOS/nixpkgs/pulls
Reviewing guidelines: https://github.com/NixOS/nixpkgs/blob/master/pkgs/README.md#reviewing-contributions
-->
---
Add a :+1: [reaction] to [pull requests you find important].
[reaction]: https://github.blog/2016-03-10-add-reactions-to-pull-requests-issues-and-comments/
[pull requests you find important]: https://github.com/NixOS/nixpkgs/pulls?q=is%3Aopen+sort%3Areactions-%2B1-desc