Repository navigation
lib/shell: add idempotent search-variable merge primitives - #9859
Open
khaneliman wants to merge 1 commit into
Open
khaneliman wants to merge 1 commit into
khaneliman wants to merge 1 commit into
Conversation
khaneliman
force-pushed
the
session-vars-2-merge-primitives
branch
from
August 28, 2026 06:17
954e843 to
38c71ac
Compare
khaneliman
force-pushed
the
session-vars-2-merge-primitives
branch
from
August 28, 2026 19:53
38c71ac to
5772763
Compare
khaneliman
force-pushed
the
session-vars-2-merge-primitives
branch
from
August 28, 2026 20:48
5772763 to
d5eea22
Compare
khaneliman
force-pushed
the
session-vars-2-merge-primitives
branch
2 times, most recently
from
August 28, 2026 21:04
6807577 to
618888c
Compare
khaneliman
force-pushed
the
session-vars-2-merge-primitives
branch
3 times, most recently
from
August 29, 2026 04:47
fe8ec2c to
21d95a0
Compare
khaneliman
marked this pull request as ready for review
August 29, 2026 04:49
khaneliman
force-pushed
the
session-vars-2-merge-primitives
branch
from
September 9, 2026 22:13
21d95a0 to
9a3c024
Compare
khaneliman
force-pushed
the
session-vars-2-merge-primitives
branch
from
September 11, 2026 03:12
9a3c024 to
6b88e44
Compare
khaneliman
force-pushed
the
session-vars-2-merge-primitives
branch
from
September 30, 2026 18:58
6b88e44 to
b373a11
Compare
khaneliman
force-pushed
the
session-vars-2-merge-primitives
branch
from
October 1, 2026 02:11
b373a11 to
70f3963
Compare
Adds a POSIX `__hm_merge` helper and one `mergeSearchVariables` generator. The generator owns helper setup, prepend and append calls, marker export, and cleanup so callers cannot misorder those stages. Nothing consumes it yet; `prependToVar` is untouched. Adding an entry that is already present never duplicates it. Whether an already-present entry may be moved depends on where the merge runs: - First merge in a process tree, detected by `__HM_SESS_VARS_MERGED` being unset: configured entries take their configured precedence and existing occurrences are repositioned. - Any later merge: existing entries keep their position, so re-sourcing cannot reorder a path a development shell, direnv, or a wrapper put in front. The complete generator exports the marker after the last merge, then removes its helper and scratch variables. The marker is deliberately separate from `__HM_SESS_VARS_SOURCED`, whose position relative to the merges is not fixed. Entries expand in a double-quoted shell context. Raw double quotes remain shell syntax so quoted command substitutions keep working; `\"` produces a literal quote. The helper lives in `session-search-merge.sh` rather than a Nix string. It contains no interpolation, so keeping it as shell source avoids three layers of escaping and lets shellcheck read it. Removal is join-based rather than token-splitting. Splitting on the separator is not idempotent for entries that contain the separator: merging `a:b` into `x:a:b:y` would grow on every source. Verified in bash, dash, and zsh across substring entries and globs. Coverage also includes separator-bearing values, marker transitions, prepend and append ordering, cleanup, and repeated sourcing.
khaneliman
force-pushed
the
session-vars-2-merge-primitives
branch
from
November 18, 2026 01:13
70f3963 to
4a200a2
Compare
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Adds the POSIX
__hm_mergehelper and one publicmergeSearchVariables { prepend, append }generator. The generator emits thecomplete sourceable block: helper definition, merge calls, process marker, and
cleanup. Keeping those stages private prevents callers from omitting or
misordering them. Nothing consumes the generator yet;
prependToVarisuntouched, so this PR changes no generated output.
Adding an already-present entry never duplicates it. On the first merge in a
process tree, detected through
__HM_SESS_VARS_MERGED, configured entries takeconfigured precedence and may be repositioned. On later merges, existing
entries keep their position, so re-sourcing cannot reorder a path that
nix develop, direnv, or a wrapper put in front. Removal is join-based ratherthan token-splitting so entries containing the separator stay idempotent.
The in-tree test suite (
tests/lib/shell/search-variable-merge.nix) exercisesthe complete generator across Bash, dash, and Zsh. It covers expansion,
prepend and append ordering, marker export, cleanup, and repeated sourcing.
Part of splitting #9735 into independently reviewable changes; the stack as a
whole supersedes that PR.
Checklist
nix fmt.nix build .#test-all.{component}: {description}format.