Skip to content

Commit

Permalink
fix: load the devcontainer from the derivation
Browse files Browse the repository at this point in the history
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 different shell.
  • Loading branch information
nrdxp committed Jan 20, 2023
1 parent f9129df commit dab6d94
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions cells/lib/ops/mkDevOCI.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
inputs,
cell,
}: let
inherit (inputs) nixpkgs std;
inherit (inputs) nixpkgs;
l = nixpkgs.lib // builtins;
n2c = inputs.n2c.packages.nix2container;

Expand Down Expand Up @@ -87,9 +87,10 @@ in
mkdir -p $out/tmp
# Enable nix flakes
mkdir -p $out/etc
mkdir -p $out/etc/direnv
echo "sandbox = false" > $out/etc/nix.conf
echo "experimental-features = nix-command flakes" >> $out/etc/nix.conf
echo "accept-flake-config = true" >> $out/etc/nix.conf
# Increase warn timeout and whitelist all paths
cat >$out/etc/direnv.toml << EOF
Expand All @@ -99,11 +100,15 @@ in
prefix = [ "/" ]
EOF
# force override the project local .envrc to load the given shell
echo 'eval "$(nix print-dev-env ${devshell})" ; exit' > /etc/direnvrc
# Add direnv shim
cat >$out/etc/${shellConfigs.${shellName}} << EOF
eval "\$(direnv hook ${shellName})"
EOF
# Put local profile in path
echo 'export PATH="$HOME/.nix-profile/bin:/nix/var/nix/profiles/default/bin:$PATH"' >> $out/etc/${shellConfigs.${shellName}}
Expand Down Expand Up @@ -260,8 +265,7 @@ in
++ (l.optionals (! slim) [
# Include <nixpkgs> to support installing additional packages
"NIX_PATH=nixpkgs=${nixpkgs.path}"
])
++ (map envToList devshell.passthru.config.env);
]);
Volumes = l.optionalAttrs vscode {"/vscode" = {};};
}
// (l.optionalAttrs (! vscode) {WorkingDir = "/work";});
Expand Down

0 comments on commit dab6d94

Please sign in to comment.