Skip to content

Commit 4a03809

Browse files
committed
fix: load the devcontainer from the derivation
Forces direnv to load the shell using a call to `nix print-dev-env` directly on the derivation output, avoiding an extra evaluation and any possibility that the in-repo .envrc loads a difference shell.
1 parent f9129df commit 4a03809

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

cells/lib/ops/mkDevOCI.nix

+8-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
inputs,
33
cell,
44
}: let
5-
inherit (inputs) nixpkgs std;
5+
inherit (inputs) nixpkgs;
66
l = nixpkgs.lib // builtins;
77
n2c = inputs.n2c.packages.nix2container;
88

@@ -87,9 +87,10 @@ in
8787
mkdir -p $out/tmp
8888
8989
# Enable nix flakes
90-
mkdir -p $out/etc
90+
mkdir -p $out/etc/direnv
9191
echo "sandbox = false" > $out/etc/nix.conf
9292
echo "experimental-features = nix-command flakes" >> $out/etc/nix.conf
93+
echo "accept-flake-config = true" >> $out/etc/nix.conf
9394
9495
# Increase warn timeout and whitelist all paths
9596
cat >$out/etc/direnv.toml << EOF
@@ -99,11 +100,15 @@ in
99100
prefix = [ "/" ]
100101
EOF
101102
103+
# force override the project local .envrc to load the given shell
104+
echo 'eval "$(nix print-dev-env ${devshell})" ; exit' > /etc/direnvrc
105+
102106
# Add direnv shim
103107
cat >$out/etc/${shellConfigs.${shellName}} << EOF
104108
eval "\$(direnv hook ${shellName})"
105109
EOF
106110
111+
107112
# Put local profile in path
108113
echo 'export PATH="$HOME/.nix-profile/bin:/nix/var/nix/profiles/default/bin:$PATH"' >> $out/etc/${shellConfigs.${shellName}}
109114
@@ -260,8 +265,7 @@ in
260265
++ (l.optionals (! slim) [
261266
# Include <nixpkgs> to support installing additional packages
262267
"NIX_PATH=nixpkgs=${nixpkgs.path}"
263-
])
264-
++ (map envToList devshell.passthru.config.env);
268+
]);
265269
Volumes = l.optionalAttrs vscode {"/vscode" = {};};
266270
}
267271
// (l.optionalAttrs (! vscode) {WorkingDir = "/work";});

0 commit comments

Comments
 (0)