cachix / devenv

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

Wrapping `devenv shell` in a FHS environment? #1398

Open shymega opened 3 weeks ago

shymega commented 3 weeks ago

Hi!

I'm working on a Rust Steam Play tool, and I'm trying to wrap devenv shell in an FHS environment, for Proton. It doesn't run otherwise.

I've tried using pkgs and inputsFrom to get this working, to no avail.

Is it possible to wrap devenv into a FHS environment?

Thanks.

shymega commented 3 weeks ago

Actually, I think I've found the issue. It was my Nix derivation.

Regardless, using devenv as a shell wrapped in FHS might be useful. Is it worth opening a feature request for?

EDIT: I've fixed the Nix derivation, but running cargo build inside devenv, then running the executable fails. No idea if this is normal behaviour.

sandydoo commented 3 weeks ago

I don't think anyone has really tried this.

You can override shell and replace the default mkShell implementation with buildFHSEnv.

{ pkgs, lib, config, inputs, ... }:

{
  env.HELLO = "WORLD";

  packages = [
    pkgs.hello
  ];

  shell = lib.mkForce (pkgs.buildFHSEnv {
    name = "devenv-shell";
    targetPkgs = _: config.packages;
    runScript = "bash";
    profile = ''
      ${lib.optionalString config.devenv.debug "set -x"}
      ${config.enterShell}
    '' + lib.concatStringsSep "\n" (lib.mapAttrsToList (name: value: ''
      export ${name}=${value}
    '') config.env);
  }).env;
}

This seems to work as expected:

which hello
/usr/bin/hello

But direnv fails to launch this shell, so the question is what else does this break.

Another approach would be to wrap just the binary in a buildFHSEnv. Maybe there's a way to leverage scripts for this?

shymega commented 3 weeks ago

Yeah, I get the following error from direnv - do you as well?

Would it be a good idea to open a feature request?

direnv: loading ~/projects/git.shymega.org.uk/DeckCheatz/DeckCheatz/.envrc
direnv: loading https://raw.githubusercontent.com/cachix/devenv/95f329d49a8a5289d31e0982652f7058a189bfca/direnvrc (sha256-d+8cBpDfDBj41inrADaJt+bDWhOktwslgoP5YiGJ1v0=)
direnv: using devenv
direnv: .envrc changed, reloading
• Using Cachix: devenv
[1/0/7 built] building python3.11-aiohttp-3.9.3 (buildPhase): cython -3 -o aiohttp/_websocket.c aiohttp/_websocket.pyx -I aiohttp -Werrodirenv: ([/nix/store/ic11r65mm23k23jf6k1bcnvxwssl4sk7-direnv-2.34.0/bin/direnv export zsh]) is taking a while to execute. Use CTRL-C to give up.
direnv: updated devenv shell cache
pre-commit-hooks.nix: updating /home/dzrodriguez/projects/git.shymega.org.uk/DeckCheatz/DeckCheatz repo
pre-commit installed at .git/hooks/pre-commit
✨ devenv 1.0.8 is newer than devenv input in devenv.lock. Run `devenv update` to sync.
mkdir: cannot create directory ‘’: No such file or directory
/etc/profile: line 154: export: `-C': not a valid identifier
/etc/profile: line 154: export: `link-arg=-fuse-ld=mold': not a valid identifier
/etc/profile: line 156: export: `-C': not a valid identifier
/etc/profile: line 156: export: `link-arg=-fuse-ld=mold': not a valid identifier
✨ devenv 1.0.8 is newer than devenv input in devenv.lock. Run `devenv update` to sync.
bash: export: `-C': not a valid identifier
bash: export: `link-arg=-fuse-ld=mold': not a valid identifier
bash: export: `-C': not a valid identifier
bash: export: `link-arg=-fuse-ld=mold': not a valid identifier
sandydoo commented 3 weeks ago

I got:

/home/sandydoo/.cache/direnv/cas/77ef1c0690df0c18f8d629eb003689b7e6c35a13a4b70b258283f9622189d6fd:1997: DISPLAY: unbound variable
direnv: error exit status 1

Would it be a good idea to open a feature request?

You can keep this issue open as well.

@domenkozar and I briefly discussed this and we're unlikely to want to implement and maintain this because of the lack of support on macOS. Maybe we can come up with docs on how to work around this, either using the above shell override or by providing instructions on how to wrap specific binaries.