Skip to content

Conversation

@llakala
Copy link
Contributor

@llakala llakala commented Jan 9, 2026

I've been working on a collection of wrappers, and want each wrapper to support both:

  1. directly passing in a config value, with some pkgs.formats transformation (think home-manager .settings options
  2. an impure solution, where you pass the program a homedir path, and have it read from the state of that file at runtime

Most programs support taking a config path, but some can only read from the state of an env var, or the flags they've been passed directly. To allow these programs to be handled impurely, the wrapper itself needs to read from the file and pass the contents to the program.

This PR adds the ability to do the first part of that. Calling wrapProgram $out/bin/foo --set-from-file FOO_ENV_VAR /home/user/example/file creates the relevant C code to read from /home/user/example/file at runtime, and set FOO_ENV_VAR to the contents of this file. I'm using this locally with one of my wrappers, and can confirm it functions.

Feel free to critique my C code. In a future PR, I'd like to add the equivalent feature for --add-flags, and see if I can bring this API to the normal makeWrapper as well.

Things done

  • Built on platform:
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • Tested, as applicable:
  • Ran nixpkgs-review on this PR. See nixpkgs-review usage.
  • Tested basic functionality of all binary files, usually in ./result/bin/.
  • Nixpkgs Release Notes
    • Package update: when the change is major or breaking.
  • NixOS Release Notes
    • Module addition: when adding a new NixOS module.
    • Module update: when the change is significant.
  • Fits CONTRIBUTING.md, pkgs/README.md, maintainers/README.md and other READMEs.

Add a 👍 reaction to pull requests you find important.

@llakala llakala force-pushed the read-from-file-at-runtime branch from 6918457 to 9d0eca4 Compare January 9, 2026 02:08
@llakala llakala changed the base branch from master to staging January 9, 2026 02:11
@nixpkgs-ci nixpkgs-ci bot closed this Jan 9, 2026
@nixpkgs-ci nixpkgs-ci bot reopened this Jan 9, 2026
@nixpkgs-ci nixpkgs-ci bot added 10.rebuild-linux: 501+ This PR causes many rebuilds on Linux and should normally target the staging branches. 10.rebuild-darwin: 501+ This PR causes many rebuilds on Darwin and should normally target the staging branches. 10.rebuild-darwin-stdenv This PR causes stdenv to rebuild on Darwin and must target a staging branch. 10.rebuild-darwin: 5001+ This PR causes many rebuilds on Darwin and must target the staging branches. 10.rebuild-linux: 5001+ This PR causes many rebuilds on Linux and must target the staging branches. 9.needs: reviewer This PR currently has no reviewers requested and needs attention. labels Jan 9, 2026
@adisbladis
Copy link
Member

adisbladis commented Jan 9, 2026

Something adjacent I'd find useful is to be able to source the equivalent of systemd's EnvironmentFile directive: https://www.freedesktop.org/software/systemd/man/latest/systemd.exec.html#EnvironmentFile=.
Not a blocker for this feature addition though.

@nixpkgs-ci nixpkgs-ci bot added 12.approvals: 1 This PR was reviewed and approved by one person. and removed 9.needs: reviewer This PR currently has no reviewers requested and needs attention. labels Jan 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

10.rebuild-darwin: 501+ This PR causes many rebuilds on Darwin and should normally target the staging branches. 10.rebuild-darwin: 5001+ This PR causes many rebuilds on Darwin and must target the staging branches. 10.rebuild-darwin-stdenv This PR causes stdenv to rebuild on Darwin and must target a staging branch. 10.rebuild-linux: 501+ This PR causes many rebuilds on Linux and should normally target the staging branches. 10.rebuild-linux: 5001+ This PR causes many rebuilds on Linux and must target the staging branches. 12.approvals: 1 This PR was reviewed and approved by one person.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants