at 23.11-pre 1.9 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 "fallback-path=${pkgs.runCommand "fallback-path" {} ('' 11 mkdir -p $out 12 ln -s ${config.environment.usrbinenv} $out/env 13 ln -s ${config.environment.binsh} $out/sh 14 '' + cfg.extraFallbackPathCommands)}" 15 "nofail" 16 ]; 17 }; 18 "/bin" = { 19 device = "/usr/bin"; 20 fsType = "none"; 21 options = [ "bind" "nofail" ]; 22 }; 23 }; 24in { 25 options = { 26 services.envfs = { 27 enable = lib.mkEnableOption (lib.mdDoc "Envfs filesystem") // { 28 description = lib.mdDoc '' 29 Fuse filesystem that returns symlinks to executables based on the PATH 30 of the requesting process. This is useful to execute shebangs on NixOS 31 that assume hard coded locations in locations like /bin or /usr/bin 32 etc. 33 ''; 34 }; 35 36 package = lib.mkOption { 37 type = lib.types.package; 38 default = pkgs.envfs; 39 defaultText = lib.literalExpression "pkgs.envfs"; 40 description = lib.mdDoc "Which package to use for the envfs."; 41 }; 42 43 extraFallbackPathCommands = lib.mkOption { 44 type = lib.types.lines; 45 default = ""; 46 example = "ln -s $''{pkgs.bash}/bin/bash $out/bash"; 47 description = lib.mdDoc "Extra commands to run in the package that contains fallback executables in case not other executable is found"; 48 }; 49 }; 50 }; 51 config = lib.mkIf (cfg.enable) { 52 environment.systemPackages = [ cfg.package ]; 53 # we also want these mounts in virtual machines. 54 fileSystems = if config.virtualisation ? qemu then lib.mkVMOverride mounts else mounts; 55 56 # We no longer need those when using envfs 57 system.activationScripts.usrbinenv = lib.mkForce ""; 58 system.activationScripts.binsh = lib.mkForce ""; 59 }; 60}