summaryrefslogtreecommitdiff
path: root/modules/envfs.nix
diff options
context:
space:
mode:
authorGregor Kleen <gkleen@yggdrasil.li>2023-09-23 16:48:17 +0200
committerGregor Kleen <gkleen@yggdrasil.li>2023-09-23 16:48:17 +0200
commitff504f0d6c9f22430412bacc5ae82d5f27ce077f (patch)
tree43d34db26cc85a7e34ad6e2a6171f80cccc2a839 /modules/envfs.nix
parentcb118fd08ceac4607bd53298810c5685220f5faf (diff)
downloadnixos-ff504f0d6c9f22430412bacc5ae82d5f27ce077f.tar
nixos-ff504f0d6c9f22430412bacc5ae82d5f27ce077f.tar.gz
nixos-ff504f0d6c9f22430412bacc5ae82d5f27ce077f.tar.bz2
nixos-ff504f0d6c9f22430412bacc5ae82d5f27ce077f.tar.xz
nixos-ff504f0d6c9f22430412bacc5ae82d5f27ce077f.zip
...
Diffstat (limited to 'modules/envfs.nix')
-rw-r--r--modules/envfs.nix69
1 files changed, 66 insertions, 3 deletions
diff --git a/modules/envfs.nix b/modules/envfs.nix
index 6aa12c1c..1463dce8 100644
--- a/modules/envfs.nix
+++ b/modules/envfs.nix
@@ -1,4 +1,67 @@
1{ lib, ... }: 1{ pkgs, config, lib, ... }:
2{ 2
3 config.services.envfs.enable = lib.mkDefault true; 3let
4 cfg = config.services.envfs;
5 mounts = {
6 "/usr/bin" = {
7 device = "none";
8 fsType = "envfs";
9 options = [
10 "fallback-path=${pkgs.symlinkJoin {
11 name = "fallback-path";
12 inherit (cfg) paths;
13 }}"
14 ];
15 };
16 "/bin" = {
17 device = "/usr/bin";
18 fsType = "none";
19 options = [ "bind" "nofail" ];
20 };
21 };
22in {
23 disabledModules = [ "tasks/filesystems/envfs.nix" ];
24
25 options = {
26 services.envfs = {
27 enable = lib.mkEnableOption (lib.mdDoc "Envfs filesystem") // {
28 default = true;
29 description = lib.mdDoc ''
30 Fuse filesystem that returns symlinks to executables based on the PATH
31 of the requesting process. This is useful to execute shebangs on NixOS
32 that assume hard coded locations in locations like /bin or /usr/bin
33 etc.
34 '';
35 };
36
37 package = lib.mkOption {
38 type = lib.types.package;
39 default = pkgs.envfs;
40 defaultText = lib.literalExpression "pkgs.envfs";
41 description = lib.mdDoc "Which package to use for the envfs.";
42 };
43
44 paths = lib.mkOption {
45 type = lib.types.listOf lib.types.package;
46 default = [
47 (pkgs.runCommand "fallback-path-environment" {} ''
48 mkdir -p $out
49 ln -s ${config.environment.usrbinenv} $out/env
50 ln -s ${config.environment.binsh} $out/sh
51 '')
52 ];
53 description = lib.mdDoc "Extra packages to join into collection of fallback executables in case not other executable is found";
54 };
55 };
56 };
57
58 config = lib.mkIf (cfg.enable) {
59 environment.systemPackages = [ cfg.package ];
60 # we also want these mounts in virtual machines.
61 fileSystems = if config.virtualisation ? qemu then lib.mkVMOverride mounts else mounts;
62
63 # We no longer need those when using envfs
64 system.activationScripts.usrbinenv = lib.mkForce "";
65 system.activationScripts.binsh = lib.mkForce "";
66 };
4} 67}