Skip to content

A command to add a gc root #7138

Open
Open
@roberth

Description

Is your feature request related to a problem? Please describe.

I'm generating a script that needs create an indirect gc root to a store path that's in the script's closure. E.g.

writeScript "foo" ''
  # wrong (missing gc root)
  ln -s ${pkgs.hello} ./program
''

Describe the solution you'd like

A new command as follows. (I didn't find a suitable command in the unstable manual or the nix-store manpage)
Here's a fictional doc I hope we can turn into reality.


nix store add-root path storepath

Create an indirect garbage collection root at location path to refer to the storepath.
Note that most commands that produce store paths have an option to produce a garbage collection root, so that the store path can not be garbage collected before a root is created.
A valid use case for nix store add-root is in scripts built with Nix. In this case the store path is already referenced by the script's store path, and nix store add-root is used to prevent collection of the store path after the script exits.

writeScript "foo" ''
  nix store add-root ./program ${pkgs.hello}
''

Describe alternatives you've considered

Abusing some other command to create the root and then replace the symlink. This is bad because it's complicated and may leave the symlink in a bad state.

Additional context

Metadata

Assignees

No one assigned

    Labels

    cliThe old and/or new command line interfacefeatureFeature request or proposalnew-cliRelating to the "nix" command

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions