Skip to content

Polyrepos

When working with multiple projects across separate repositories, you may want to compose environments or reference options --- such as outputs, packages, or other configuration --- defined in one devenv project from another.

There are two approaches:

Warning

The remote repository must use devenv.nix only --- devenv.yaml from imported projects is not evaluated. See #2205 for details.

Both examples below reference the same remote repository (myorg/my-service) with the following configuration:

my-service/devenv.nix
{ config, ... }: {
  languages.python.enable = true;

  outputs.my-service = config.languages.python.import ./. {};

  processes.my-service.exec = "${config.outputs.my-service}/bin/my-service";
}

Composing with imports

devenv projects compose naturally through imports. When you import another project via an input, all of its configuration --- packages, services, outputs, env, and more --- merges into your environment.

Add the remote repository as an input, then import from it:

devenv.yaml
inputs:
  my-service:
    url: github:myorg/my-service
imports:
  - my-service

Any configuration defined in the imported project's devenv.nix merges into your environment. For example, my-service's output and process are now available via config:

devenv.nix
{ config, ... }: {
  # my-service's output is merged into config.outputs
  packages = [ config.outputs.my-service ];

  # my-service's process is also merged, so `devenv up` will start it
}

For local cross-project imports (monorepos), see the monorepo guide.

Referencing config across inputs

New in version 2.0

When you don't want to merge an entire environment but need access to specific options from another project, you can reference them through inputs.<name>.devenv.config. This is particularly useful for consuming outputs defined in other projects.

devenv.yaml
inputs:
  my-service:
    url: github:myorg/my-service
    flake: false
devenv.nix
{ inputs, ... }: {
  packages = [
    inputs.my-service.devenv.config.outputs.my-service
  ];

  processes.my-service.exec = "${inputs.my-service.devenv.config.outputs.my-service}/bin/my-service";
}

Warning

Profiles don't work with cross-project references. See #2521 for details.