at 24.11-pre 2.1 kB view raw
1{ pkgs, config, lib, ... }: 2 3let 4 cfg = config.services.envfs; 5 mounts = { 6 "/usr/bin" = { 7 device = "none"; 8 fsType = "envfs"; 9 options = [ 10 "bind-mount=/bin" 11 "fallback-path=${pkgs.runCommand "fallback-path" {} ('' 12 mkdir -p $out 13 ln -s ${config.environment.usrbinenv} $out/env 14 ln -s ${config.environment.binsh} $out/sh 15 '' + cfg.extraFallbackPathCommands)}" 16 "nofail" 17 ]; 18 }; 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. 22 "/bin" = { 23 device = "/usr/bin"; 24 fsType = "none"; 25 options = [ "bind" "nofail" ]; 26 }; 27 }; 28in { 29 options = { 30 services.envfs = { 31 enable = lib.mkEnableOption "Envfs filesystem" // { 32 description = '' 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 36 etc. 37 ''; 38 }; 39 40 package = lib.mkOption { 41 type = lib.types.package; 42 default = pkgs.envfs; 43 defaultText = lib.literalExpression "pkgs.envfs"; 44 description = "Which package to use for the envfs."; 45 }; 46 47 extraFallbackPathCommands = lib.mkOption { 48 type = lib.types.lines; 49 default = ""; 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"; 52 }; 53 }; 54 }; 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; 59 60 # We no longer need those when using envfs 61 system.activationScripts.usrbinenv = lib.mkForce ""; 62 system.activationScripts.binsh = lib.mkForce ""; 63 }; 64}