Managed environments¶
All examples on this page will use my-env
as the name of the environment you're working on.
Install packages¶
Given that you want to install packages foo
, bar
, and baz
:
If a package comes from a catalog my-catalog
you must prefix the package name with my-catalog.
:
Remove packages¶
Given that you want to remove packages foo
and bar
:
If a package comes from a catalog my-catalog
you must prefix the package name with my-catalog.
:
List installed packages¶
Activate an environment¶
- Note that the shell prompt changes to show that you have entered the environment. It lists both
my-env
anddefault
. Thedefault
environment is always activated when you activate an environment.
Run a single command in an environment¶
Given that you want to run command foo
in the environment:
Manually edit the environment definition¶
Commands like flox install
modify a declarative configuration file defining the environment.
You can manually edit the environment definition with the flox edit
command.
See flox.nix
configuration for details on the file format.
The command should drop you into an editor with a file that has this format:
Set environment variables¶
Edit the environment definition with flox edit
and add an environmentVariables
section with key-value pairs in this format:
{
# other contents here
environmentVariables = {
MYVAR = "foo";
YOURVAR = "bar";
OURVAR = "baz";
};
}
This is a Nix attribute set.
See the Nix language guide for more details on the syntax, but key-value pairs are always of the form <name> = <value>;
.
This entire file is in fact a set of key-value pairs.
Add shell hooks¶
Shell hooks are shell commands that are run right before control is returned to the user when activating an environment. You can use shell hooks to run setup commands, start programs, etc.
Edit the environment definition with flox edit
and add a shell.hook
section with the shell commands you'd like to execute wrapped in pairs of single quotes:
The only exception to normal shell code is that the dollar sign $
needs to be escaped with another pair of single quotes like so:
Share an environment¶
Environments are stored as git repositories named floxmeta
.
First authenticate with GitHub if you haven't already done so:
This command will ask you questions about which GitHub account to use, which protocol to interact with (https or ssh), etc.
Now push the repository to a git host with flox push
:
This command will ask you questions about where to host the repository. This repository is set to private by default. If you'd like to share this environment with someone else you'll need to grant that person read access to the repository or make the repository public.
Use someone else's environment¶
Let's say you want to use an environment called their-env
from a GitHub user named someone-else
.
You pull someone else's environment with the flox pull
command:
You can now activate this environment like you would one of your own, simply prefix it with the other user's GitHub handle: