Best way to define common FHS environment?

I have the following definition in my systemPackages, which gives me an fhs binary which drops me into a shell which looks like a normal Linux:

  environment.systemPackages = with pkgs; [
    (pkgs.buildFHSUserEnv {
      name = "fhs";
      targetPkgs = pkgs: with pkgs; [
        alsa-lib atk cairo cups curl dbus expat file fish fontconfig freetype
        fuse glib gtk3 libGL libnotify libxml2 libxslt netcat nspr nss openjdk8 pango pkg-config strace udev vulkan-loader watch wget which
        xorg.libX11 xorg.libxcb xorg.libXcomposite xorg.libXcursor
        xorg.libXdamage xorg.libXext xorg.libXfixes xorg.libXi xorg.libXrandr
        xorg.libXrender xorg.libXScrnSaver xorg.libxshmfence xorg.libXtst
        xorg.xcbutilkeysyms zlib fontconfig.lib
      profile = ''export FHS=1'';
      runScript = "fish";
    # all of my other packages
$ ls /usr/lib
"/usr/lib": No such file or directory (os error 2)

$ fhs

(fhs) $ ls /usr/lib | head -n 5
dr-xr-xr-x   - nobody  1 Jan  1970 32
dr-xr-xr-x   - nobody  1 Jan  1970 audit
dr-xr-xr-x   - nobody  1 Jan  1970 bash
dr-xr-xr-x   - nobody  1 Jan  1970 cairo
lrwxrwxrwx  69 nobody  1 Jan  1970 crt1.o -> /nix/store/aji28kaprqnrkapmfyjnnnv3ffvlaq0a-fhs-usr-target/lib/crt1.o
(fhs) $ # I can now run various unpatched vanilla binaries here

It works great, except that there’s this frightening block of standard packages which I partially copied from somewhere, and partially append a bunch of random stuff myself.

Is there some maintained-by-someone-else package I can re-use here? I am essentially looking for buildFHSUserEnv specialized to a set of “standard” packages (whatever that set is at the current moment in time).


I’m not aware of any standard set of packages, but something like this can include most of what you want

builtins.concatMap (p: p.buildInputs) config.environment.systemPackages
1 Like

I’m not super familiar with it, but I think there are various lists of packages for use with buildfhsuserenvs in nixpkgs.

For instance:

Used here for example (I think):


Thanks, this is exactly what I was looking for!

1 Like

I wanted to share this little script:

nix shell --impure --expr '(builtins.getFlake "nixpkgs-current").legacyPackages.${builtins.currentSystem}.buildFHSUserEnv { name = "fhs"; targetPkgs = p: with p; ['"$*"' ]; }' --command fhs

Arguments accepted are simply packages. This can also be improved to include support for additional arguments to the shell itself etc…

1 Like