cachix / devenv

Fast, Declarative, Reproducible, and Composable Developer Environments
https://devenv.sh
Apache License 2.0
4.44k stars 334 forks source link

cannot import nix file from parent directory? #1239

Open cyberjar09 opened 5 months ago

cyberjar09 commented 5 months ago

not sure if im doing something unintended here

example project:

├── nested
│   ├── devenv.nix
│   └── devenv.yaml
├── devenv.lock
├── devenv.nix
└── devenv.yaml

devenv.yaml

inputs:
  nixpkgs:
    url: github:cachix/devenv-nixpkgs/rolling

devenv.nix

{ pkgs, lib, config, inputs, ... }:
{
# https://devenv.sh/packages/
packages = [ ];

enterShell = ''
'';
}

nested/devenv.nix

{ pkgs, lib, config, inputs, ... }:
{
  packages = [ ];

  languages = {
    terraform = {
      enable = true;
      version = "1.5.6";
    };
  };
}

nexted/devenv.yaml

inputs:
  nixpkgs:
    url: github:cachix/devenv-nixpkgs/rolling
imports:
  - ../devenv.nix

when I go into the nested folder and devenv shell I get an error error: devenv: ../ is not supported for imports my use case is that different terraform folders contain their own version of terraform, but they can inherit from the parent folder devenv.nix

domenkozar commented 5 months ago

See nested in examples how that's currently done

cyberjar09 commented 5 months ago

I dont see anything named nested in the examples 🤔

domenkozar commented 5 months ago

https://github.com/cachix/devenv/tree/main/examples/compose

sandydoo commented 5 months ago

I think @cyberjar09 wants to run devenv shell in a nested folder and import a devenv.nix from the parent directory. We have checks in place to not allow imports starting with ../, which I assume is due to the restriction imposed by Nix flakes. Everything that's used to evaluate the shell must be tracked by git and in the current directory or lower.

SyedRoot commented 1 week ago

My use-case for this is to have a common postgres server running in the parent directory's devenv.nix and then in a sub-folder (micro-service) connect to it while having access to the psql cli.

What I'd do then is:

devenv up # starts server
cd subfolder
psql -d db -f file.sql

Would be cool if this could be supported.