Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,5 +80,11 @@ a temporary environment. That is, it sets up your environment, gets you
logged in, then takes care of tearing it up and tidying up after you when
you log out.



####Why do I get "no such file or directory"?
You may need to change the confdir and statedir options, which are the paths
to nixos-container configurations and container states, respectively. These vary
between systems, due to
[this pull request](https://github.com/NixOS/nixpkgs/pull/87268). Our defaults
are `/etc/containers` and `/var/lib/containers` for backwards compatibility; but
newer systems may need to set these to `/etc/nixos-containers` and
`/var/lib/nixos-containers` instead.
26 changes: 14 additions & 12 deletions src/nixos-shell/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,17 @@ var cmd = &Cmd{}

// Cmd encapsulates the command and it's options.
type Cmd struct {
Config string `short:"C" long:"config" description:"path to configuration.nix" default:"./configuration.nix"`
Bind string `short:"b" long:"bind" description:"path on host to bind to /src in the container" default:"./"`
Command string `short:"c" long:"command" description:"shell commands to execute"`
Id string `long:"name" description:"name to use for the container" default:"random"`
Verbose bool `short:"v" description:"show verbose logging"`
Timeout int `short:"t" description:"timeout in seconds to wait for container boot" default:"90"`
Ports []string `short:"p" long:"port" description:"expose a container port to the host. example '8080:80' allows access to container port 80 via host port 8080"`
sigint chan bool
netenv map[string]string
Config string `short:"C" long:"config" description:"path to configuration.nix" default:"./configuration.nix"`
Bind string `short:"b" long:"bind" description:"path on host to bind to /src in the container" default:"./"`
Command string `short:"c" long:"command" description:"shell commands to execute"`
ConfDir string `long:"confdir" description:"path to container configurations" default:"/etc/containers"`
StateDir string `long:"statedir" description:"path to container states" default:"/var/lib/containers"`
Id string `long:"name" description:"name to use for the container" default:"random"`
Verbose bool `short:"v" description:"show verbose logging"`
Timeout int `short:"t" description:"timeout in seconds to wait for container boot" default:"90"`
Ports []string `short:"p" long:"port" description:"expose a container port to the host. example '8080:80' allows access to container port 80 via host port 8080"`
sigint chan bool
netenv map[string]string
}

// logging
Expand Down Expand Up @@ -186,7 +188,7 @@ func (cmd *Cmd) keygen() (private string, public string, err error) {
err = fmt.Errorf("could not find 'ssh-keygen' command.")
return
}
home := path.Join("/var/lib/containers", cmd.Id, "var")
home := path.Join(cmd.StateDir, cmd.Id, "var")
if err = os.MkdirAll(home, 0755); err != nil {
err = fmt.Errorf("failed to create home dir in container: %s", err)
return
Expand Down Expand Up @@ -223,7 +225,7 @@ func (cmd *Cmd) ssh(args ...string) error {
}

func (cmd *Cmd) getNetworkEnv() (env map[string]string, err error) {
b, err := ioutil.ReadFile(path.Join("/etc/containers", fmt.Sprintf("%s.conf", cmd.Id)))
b, err := ioutil.ReadFile(path.Join(cmd.ConfDir, fmt.Sprintf("%s.conf", cmd.Id)))
if err != nil {
return nil, fmt.Errorf("could not find generated network info: %s", err)
}
Expand Down Expand Up @@ -444,7 +446,7 @@ func (cmd *Cmd) Execute() error {
}
}
// Create the container root
root := path.Join("/var/lib/containers", cmd.Id)
root := path.Join(cmd.StateDir, cmd.Id)
cmd.debug("creating", root)
if err := os.MkdirAll(root, 0755); err != nil {
return err
Expand Down