Flakes way of creating a FHS environment

I’m currently using a shell.nix file to produce a FHS environment to run a closed source binary

{ pkgs ? import <nixpkgs> {} }:

(pkgs.buildFHSUserEnv {
  name = "etx-env";
  targetPkgs = pkgs: (with pkgs;
    [ gdk-pixbuf
      glib
      glibc
      gtk3-x11
      libkrb5
    ]) ++ (with pkgs.xorg;
    [ libX11
      libXcursor
      libXrandr
      libXext
    ]);
  runScript = "bash";
}).env

What’s the flakes way to achieve the same and what’s the command equivalent to “nix-shell” in this case?

1 Like

In the outputs section of your flake.nix. write something like fhs_env = pkgs.buildFHSUserEnv {...};. Then you can run it with nix run .#fhs_env. If your runScript is a shell, you’ll enter the shell where you can explore the environment to determine what to adjust. See the wiki page on Flakes for details on the structure of flake.nix. Remember that flake.nix and flake.lock must be part of a git repo to use the flake.

1 Like

Thanks, that works! The Wiki page only mentions “apps…” attributes in conjunction with nix run which expects a store path. I didn’t understand how to specify it for an environment. I missed that there is a link to the nix run reference page with an example that, together with your explanation, clarifies it.

Thanks again.

1 Like
Hosted by Flying Circus.