about summary refs log tree commit diff
path: root/nixos/modules/tasks/filesystems
diff options
context:
space:
mode:
authorJörg Thalheim <joerg@thalheim.io>2022-12-28 15:09:54 +0100
committerJörg Thalheim <joerg@thalheim.io>2022-12-28 16:03:49 +0100
commit741a0f5a7f0dc997b775cb3bc45b469ba23e4675 (patch)
treec1a89f9b79f6b0cf0be473ba5ef0131e4650ac78 /nixos/modules/tasks/filesystems
parent4d5535c90c817917015bf26794d29802e254cb32 (diff)
downloadnixlib-741a0f5a7f0dc997b775cb3bc45b469ba23e4675.tar
nixlib-741a0f5a7f0dc997b775cb3bc45b469ba23e4675.tar.gz
nixlib-741a0f5a7f0dc997b775cb3bc45b469ba23e4675.tar.bz2
nixlib-741a0f5a7f0dc997b775cb3bc45b469ba23e4675.tar.lz
nixlib-741a0f5a7f0dc997b775cb3bc45b469ba23e4675.tar.xz
nixlib-741a0f5a7f0dc997b775cb3bc45b469ba23e4675.tar.zst
nixlib-741a0f5a7f0dc997b775cb3bc45b469ba23e4675.zip
envfs: init at 1.0.0
Diffstat (limited to 'nixos/modules/tasks/filesystems')
-rw-r--r--nixos/modules/tasks/filesystems/envfs.nix51
1 files changed, 51 insertions, 0 deletions
diff --git a/nixos/modules/tasks/filesystems/envfs.nix b/nixos/modules/tasks/filesystems/envfs.nix
new file mode 100644
index 000000000000..ef8f655c532a
--- /dev/null
+++ b/nixos/modules/tasks/filesystems/envfs.nix
@@ -0,0 +1,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.mdDoc "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 "";
+  };
+}