2022-12-28 21:21:41 +00:00
|
|
|
{ pkgs, config, lib, ... }:
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.services.envfs;
|
|
|
|
mounts = {
|
|
|
|
"/usr/bin" = {
|
|
|
|
device = "none";
|
|
|
|
fsType = "envfs";
|
|
|
|
options = [
|
2024-04-21 15:54:59 +00:00
|
|
|
"bind-mount=/bin"
|
2023-02-09 11:40:11 +00:00
|
|
|
"fallback-path=${pkgs.runCommand "fallback-path" {} (''
|
2022-12-28 21:21:41 +00:00
|
|
|
mkdir -p $out
|
2023-02-09 11:40:11 +00:00
|
|
|
ln -s ${config.environment.usrbinenv} $out/env
|
|
|
|
ln -s ${config.environment.binsh} $out/sh
|
|
|
|
'' + cfg.extraFallbackPathCommands)}"
|
2023-05-24 13:37:59 +00:00
|
|
|
"nofail"
|
2022-12-28 21:21:41 +00:00
|
|
|
];
|
|
|
|
};
|
2024-04-21 15:54:59 +00:00
|
|
|
# We need to bind-mount /bin to /usr/bin, because otherwise upgrading
|
|
|
|
# from envfs < 1.0.5 will cause having the old envs with no /bin bind mount.
|
|
|
|
# Systemd is smart enough to not mount /bin if it's already mounted.
|
2022-12-28 21:21:41 +00:00
|
|
|
"/bin" = {
|
|
|
|
device = "/usr/bin";
|
|
|
|
fsType = "none";
|
2023-05-24 13:37:59 +00:00
|
|
|
options = [ "bind" "nofail" ];
|
2022-12-28 21:21:41 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
in {
|
|
|
|
options = {
|
|
|
|
services.envfs = {
|
2024-04-21 15:54:59 +00:00
|
|
|
enable = lib.mkEnableOption "Envfs filesystem" // {
|
|
|
|
description = ''
|
2022-12-28 21:21:41 +00:00
|
|
|
Fuse filesystem that returns symlinks to executables based on the PATH
|
|
|
|
of the requesting process. This is useful to execute shebangs on NixOS
|
|
|
|
that assume hard coded locations in locations like /bin or /usr/bin
|
|
|
|
etc.
|
|
|
|
'';
|
|
|
|
};
|
2023-02-09 11:40:11 +00:00
|
|
|
|
2022-12-28 21:21:41 +00:00
|
|
|
package = lib.mkOption {
|
|
|
|
type = lib.types.package;
|
|
|
|
default = pkgs.envfs;
|
2023-02-02 18:25:31 +00:00
|
|
|
defaultText = lib.literalExpression "pkgs.envfs";
|
2024-04-21 15:54:59 +00:00
|
|
|
description = "Which package to use for the envfs.";
|
2023-02-09 11:40:11 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
extraFallbackPathCommands = lib.mkOption {
|
|
|
|
type = lib.types.lines;
|
|
|
|
default = "";
|
|
|
|
example = "ln -s $''{pkgs.bash}/bin/bash $out/bash";
|
2024-04-21 15:54:59 +00:00
|
|
|
description = "Extra commands to run in the package that contains fallback executables in case not other executable is found";
|
2022-12-28 21:21:41 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
config = lib.mkIf (cfg.enable) {
|
|
|
|
environment.systemPackages = [ cfg.package ];
|
|
|
|
# we also want these mounts in virtual machines.
|
|
|
|
fileSystems = if config.virtualisation ? qemu then lib.mkVMOverride mounts else mounts;
|
|
|
|
|
|
|
|
# We no longer need those when using envfs
|
|
|
|
system.activationScripts.usrbinenv = lib.mkForce "";
|
|
|
|
system.activationScripts.binsh = lib.mkForce "";
|
|
|
|
};
|
|
|
|
}
|