1 { pkgs, config, lib, ... }:
4 cfg = config.services.envfs;
11 "fallback-path=${pkgs.runCommand "fallback-path" {} (''
13 ln -s ${config.environment.usrbinenv} $out/env
14 ln -s ${config.environment.binsh} $out/sh
15 '' + cfg.extraFallbackPathCommands)}"
19 # We need to bind-mount /bin to /usr/bin, because otherwise upgrading
20 # from envfs < 1.0.5 will cause having the old envs with no /bin bind mount.
21 # Systemd is smart enough to not mount /bin if it's already mounted.
25 options = [ "bind" "nofail" ];
31 enable = lib.mkEnableOption "Envfs filesystem" // {
33 Fuse filesystem that returns symlinks to executables based on the PATH
34 of the requesting process. This is useful to execute shebangs on NixOS
35 that assume hard coded locations in locations like /bin or /usr/bin
40 package = lib.mkOption {
41 type = lib.types.package;
43 defaultText = lib.literalExpression "pkgs.envfs";
44 description = "Which package to use for the envfs.";
47 extraFallbackPathCommands = lib.mkOption {
48 type = lib.types.lines;
50 example = "ln -s $''{pkgs.bash}/bin/bash $out/bash";
51 description = "Extra commands to run in the package that contains fallback executables in case not other executable is found";
55 config = lib.mkIf (cfg.enable) {
56 environment.systemPackages = [ cfg.package ];
57 # we also want these mounts in virtual machines.
58 fileSystems = if config.virtualisation ? qemu then lib.mkVMOverride mounts else mounts;
60 # We no longer need those when using envfs
61 system.activationScripts.usrbinenv = lib.mkForce "";
62 system.activationScripts.binsh = lib.mkForce "";