Skip to content

cli: support source base directories in standalone - #194

Draft
ZetabS wants to merge 4 commits into
feel-co:mainfrom
ZetabS:feature/source-base-dir
Draft

ZetabS wants to merge 4 commits into
feel-co:mainfrom
ZetabS:feature/source-base-dir

Conversation

@ZetabS

@ZetabS ZetabS commented Sep 27, 2026 •

Copy link
Copy Markdown

Summary

Allow Hjem standalone switch and build commands to resolve relative source
paths against an explicitly supplied source base directory.

hjem standalone switch \
  --flake . \
  --source-base-dir /Users/me/nix-config

The CLI adds source_base_dir to the manifest produced from --config or
--flake, then passes the resulting manifest through the existing Hjem and
smfh activation flow.

Motivation

Nix evaluation can describe a repository-relative source path, but it cannot
reliably discover the user's checkout location during pure evaluation. The
checkout path is therefore supplied at runtime by the standalone CLI.

This supports live files outside the Nix store:

application → Hjem symlink → repository working tree

Applications can modify the repository file directly, and the change remains
visible to version control without a separate capture step.

Scope

  • Add --source-base-dir to standalone switch and build.
  • Require the supplied path to be absolute.
  • Inject it only for manifests obtained from --config or --flake.
  • Reject combining --source-base-dir with --manifest; a pre-generated
    manifest must contain its own source_base_dir.
  • Preserve existing manifest, generation, rollback, linker, and activation
    behavior.
  • Add NixOS standalone integration coverage for source resolution and
    rollback.

Dependency

This change depends on the corresponding smfh change being merged first:

feat: support manifest base directories #66

The Hjem CLI writes source_base_dir into the evaluated manifest, so this
feature is not functional with an smfh version that does not understand that
manifest field. The Hjem PR can be merged after the Smfh PR is merged and
released.

TODO: after the Smfh release, update smfh-core and cli/Cargo.lock to the
released version and remove the local Cargo patch used for development.

Compatibility

Existing invocations without --source-base-dir retain their current
behavior. Existing absolute sources and targets are unchanged.

Validation

  • Rust unit tests pass with the local smfh checkout via a Cargo patch.
  • Rust formatting and git diff --check pass.
  • Nix evaluates the standalone NixOS VM test derivation.
    • The VM test cannot be executed on the current macOS host because the target
      NixOS derivation requires Linux.

TODO: rerun after the published smfh dependency is available: Rust unit tests
pass without the local Cargo patch.

Sanity Checking

  • My changes fit the guidelines found in CONTRIBUTING guide
  • I have tested, and self-reviewed my code
  • The unit tests for Hjem pass (nix flake check/nix-build -A checks)
  • Style and consistency
    • I formatted all relevant code (nix fmt/nix run -f . formatter)
    • My changes are consistent with the rest of the codebase
    • My commit messages fit the guidelines found in CONTRIBUTING
  • If new changes are particularly complex:
    • My code includes comments in particularly complex areas
    • I have included a section in the documentation
  • Tested on platform(s)
    • x86_64-linux
    • aarch64-linux
    • aarch64-darwin

Add a 👍 reaction to pull requests you find important.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant