about summary refs log tree commit diff
path: root/nixos/modules/tasks/filesystems/envfs.nix
blob: 450b805f0f580a6864baac1d31a9a8259ba7b3b6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
{ pkgs, config, lib, ... }:

let
  cfg = config.services.envfs;
  mounts = {
    "/usr/bin" = {
      device = "none";
      fsType = "envfs";
      options = [
        "fallback-path=${pkgs.runCommand "fallback-path" {} ''
          mkdir -p $out
          ln -s ${pkgs.coreutils}/bin/env $out/env
          ln -s ${config.system.build.binsh}/bin/sh $out/sh
        ''}"
      ];
    };
    "/bin" = {
      device = "/usr/bin";
      fsType = "none";
      options = [ "bind" ];
    };
  };
in {
  options = {
    services.envfs = {
      enable = lib.mkEnableOption (lib.mdDoc "Envfs filesystem") // {
        description = lib.mdDoc ''
          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.
        '';
      };
      package = lib.mkOption {
        type = lib.types.package;
        description = lib.mdDoc "Which package to use for the envfs.";
        default = pkgs.envfs;
        defaultText = lib.literalExpression "pkgs.envfs";
      };
    };
  };
  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 "";
  };
}