cachix / devenv

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

devenv up broken with flakes #756

Closed vesdev closed 1 month ago

vesdev commented 9 months ago

Describe the bug devenv up not working with flakes

To reproduce use example flake in the guides and run devenv up https://devenv.sh/guides/using-with-flakes/#modifying-your-flakenix-file

gives the error

error: flake does not provide attribute 'packages.x86_64-linux.devenv-up', 'legacyPackages.x86_64-linux.devenv-up' or 'devenv-up'

Version devenv: 0.6.3

aumetra commented 9 months ago

Did some analysis based on the Git history of src/devenv-devShell.nix

The last commit in the history of that file that worked was d12fb308ef41e693dd3142c7d16af21809bbc948. Everything after that broke.

So we can conclude that commit ddba5b442488a0036bba88097b9048d83dd0e709 broke the devenv up with flakes.
And indeed, if I use the commit just before the commit in question, 1e4701fb1f51f8e6fe3b0318fc2b80aed0761914, the example starts working again.

domenkozar commented 9 months ago

I'll look into this tomorrow.

domenkozar commented 9 months ago

You can workaround it for now by using revision github:cachix/devenv/9ba9e3b908a12ddc6c43f88c52f2bf3c1d1e82c1 as an input.

amiuhle commented 8 months ago

github:cachix/devenv/6a30b674fb5a54eff8c422cc7840257227e0ead2 is also working for me, with dotenv integration

fourseven commented 8 months ago

Thanks for that suggestion @amiuhle, I was using the v0.6.3 branch through finding this issue about 2 weeks ago, but of course that was failing with dotenv and so your comment was a very helpful work-around

alejandro-angulo commented 8 months ago

The suggested commits didn't work for me since I was using some newer options. I ended up adding the following to my flake as a workaround: packages.devenv-up = self.devShell.${system}.config.procfileScript;

basically I'm manually doing this https://github.com/cachix/devenv/blob/63d20fe09aa09060ea9ec9bb6d582c025402ba15/flake-module.nix#L51

alejandro-angulo commented 8 months ago

Looks like there's some issue evaluating the devenv config. I see the following error in a nix repl (hope this is helpful)

nix-repl> devShell.x86_64-linux.config.devenv
{ cliVersion = «error: error:
       … while evaluating the attribute 'value'

         at /nix/store/6s86padm2iikrwhlq8nwfv0lw9d1sbvq-source/lib/modules.nix:800:9:

          799|     in warnDeprecation opt //
          800|       { value = builtins.addErrorContext "while evaluating the option `${showOption loc}':" value;
             |         ^
          801|         inherit (res.defsFinal') highestPrio;

       … while calling the 'addErrorContext' builtin

         at /nix/store/6s86padm2iikrwhlq8nwfv0lw9d1sbvq-source/lib/modules.nix:800:17:

          799|     in warnDeprecation opt //
          800|       { value = builtins.addErrorContext "while evaluating the option `${showOption loc}':" value;
             |                 ^
          801|         inherit (res.defsFinal') highestPrio;

       (stack trace truncated; use '--show-trace' to show the full trace)

       error: The option `devenv.cliVersion' is used but not defined.»; debug = false; dotfile = "/home/alejandro/src/alejandro-angulo/alejandr0angul0.dev/.devenv"; flakesIntegration = true; latestVersion = "0.6.3"; profile = «derivation /nix/store/yfqphhzy7b0dhpgcrn1m7d9x8avifk53-devenv-profile.drv»; root = "/home/alejandro/src/alejandro-angulo/alejandr0angul0.dev"; state = "/home/alejandro/src/alejandro-angulo/alejandr0angul0.dev/.devenv/state"; warnOnNewVersion = false; }
jeffwkm commented 8 months ago

The suggested commits didn't work for me since I was using some newer options. I ended up adding the following to my flake as a workaround: packages.devenv-up = self.devShell.${system}.config.procfileScript;

Thanks, got this to fix my config too.

Added devenv-up as a flake output in context:

outputs = { self, nixpkgs, devenv, systems, ... }@inputs:
    let forEachSystem = nixpkgs.lib.genAttrs (import systems);
    in {
      devenv-up = self.devShells.x86_64-linux.default.config.procfileScript;

      devShells = forEachSystem (system: {
        default = devenv.lib.mkShell {
netbrain commented 7 months ago

Using the default flake template for devenv i had to add the following to my flake.nix

packages = forEachSystem (system: {
  devenv-up = self.devShells.${system}.default.config.procfileScript;
});

as a sibling of

devShells = ....

zarybnicky commented 7 months ago

When patching the flake, the second-order evaluation of procfileScript slows down devenv up by about a second on my machine, for each devenv up invocation - not a great DX improvement.

thenonameguy commented 6 months ago

@zarybnicky I circumvent this with process-compose via this enterShell snippet:

# symlinking latest templated process-compose yaml file from config.processes
ln -sf ${config.process-managers.process-compose.configFile} ${config.env.DEVENV_ROOT}/process-compose.yml

and gitignoring the symlinked file. This way I can just use the plain process-compose up with all the convenience of config.processes and direnv caching.

sebnow commented 3 months ago

The workarounds and implementation use the procfileScript from the default devShell. Are multiple devShells not supported, or am I incorrect in assuming that the procfileScript of the respective devShell would need to be used?

For instance I have a default shell with basic tooling, and another devShell which sets up processes. Having applied the workaround, when I nix develop .#second-shell --impure I get the message:

No 'processes' option defined: https://devenv.sh/processes/
Minimal reproducible example

## flake.nix ```nix { inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.05"; systems.url = "github:nix-systems/default"; devenv.url = "github:cachix/devenv"; }; nixConfig = { extra-trusted-public-keys = "devenv.cachix.org-1:w1cLUi8dv3hnoSPGAuibQv+f9TZLr6cv/Hm9XgU50cw="; extra-substituters = "https://devenv.cachix.org"; }; outputs = { self, nixpkgs, devenv, systems, ... } @ inputs: let forEachSystem = nixpkgs.lib.genAttrs (import systems); in { packages = forEachSystem (system: { devenv-up = self.devShells.${system}.default.config.procfileScript; }); devShells = forEachSystem (system: let pkgs = nixpkgs.legacyPackages.${system}; in { default = devenv.lib.mkShell { inherit inputs pkgs; modules = [ { packages = [ pkgs.cowsay ]; } ]; }; second-shell = devenv.lib.mkShell { inherit inputs pkgs; modules = [ { packages = [ pkgs.hello ]; enterShell = '' hello ''; processes.run.exec = "hello"; } ]; }; }); }; } ``` ## Actual Output ``` $ nix develop .#second-shell --impure Hello, world! $ devenv up No 'processes' option defined: https://devenv.sh/processes/ ``` ## Expected Output ``` $ devenv up 12:10:31 system | run.1 started (pid=281814) 12:10:31 run.1 | Hello, world! 12:10:31 system | run.1 stopped (rc=0) ```

arnm commented 1 month ago

The workarounds and implementation use the procfileScript from the default devShell. Are multiple devShells not supported, or am I incorrect in assuming that the procfileScript of the respective devShell would need to be used?

For instance I have a default shell with basic tooling, and another devShell which sets up processes. Having applied the workaround, when I nix develop .#second-shell --impure I get the message:

No 'processes' option defined: https://devenv.sh/processes/

Minimal reproducible example

Confirmed also works with latest v1.0 release

domenkozar commented 1 month ago

It's now possible to use devenv with flakes, but you need to insert that devenv-up shim. It's not yet possible to use more than one shell, shall we open a separate issue for that?

brianmay commented 1 month ago

A separate issue sounds like a good thing to me.