I have two questions about how to make a dev shell, that’s already working, a little bit better.
I setup a the-nix-way template flake with the mkShell
in order to setup a build environment for a non-nix project, that’s using yarn and emscripten. It’s quite simple:
{
description = "A Nix-flake-based Node.js development environment";
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
outputs = { self, nixpkgs }:
let
overlays = [
(final: prev: rec {
nodejs = prev.nodejs-18_x;
pnpm = prev.nodePackages.pnpm;
yarn = (prev.yarn.override { inherit nodejs; });
})
];
supportedSystems = [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin" ];
forEachSupportedSystem = f: nixpkgs.lib.genAttrs supportedSystems (system: f {
pkgs = import nixpkgs { inherit overlays system; config.allowUnfree = true; };
});
in
{
devShells = forEachSupportedSystem
({ pkgs }: {
default = pkgs.mkShell
{
packages = with pkgs; [ node2nix nodejs pnpm yarn emscripten python310 steam-run ];
shellHook = ''
if [ ! -d $(pwd)/.emscripten_cache ]; then
cp -R ${pkgs.emscripten}/share/emscripten/cache/ $(pwd)/.emscripten_cache
chmod u+rwX -R $(pwd)/.emscripten_cache
export EM_CACHE=$(pwd)/.emscripten_cache
fi
'';
};
});
};
}
The first question is related to the shellHook
. This seems to be related to a known “fixed” issue. A similar problem was originally described here, although wasn’t fixed for shell environments. The patch only seems to fix the cases when using specific emscripten packages.
Is this the type of thing I should send a PR against the emscripten package to define the shellHook
there? I’m guessing if it was that simple, it would’ve been done as part of the 172207 PR, but not really sure. Figured I’d ask here first.
My second question is around steam-run
usage. I end up having to run yarn compile
to build the project, which will fail because it eventually runs a locally built non-nixified-binary via npx
. I package steam-run
in the flake so that I can simply do steam-run yarn compile
to get around this, but I’m curious if there is some cleaner way so that one can just run the intended build commands without the steam-run
prefix?
Thanks.