|
2 | 2 |
|
3 | 3 | let |
4 | 4 | cfg = config.nixos-shell; |
5 | | - |
| 5 | + home = builtins.getEnv "HOME"; |
6 | 6 | mkVMDefault = lib.mkOverride 900; |
7 | 7 | in { |
8 | 8 | config = |
|
23 | 23 | }) |
24 | 24 |
|
25 | 25 | ( |
26 | | - let |
27 | | - home = builtins.getEnv "HOME"; |
28 | | - in |
29 | 26 | lib.mkIf (home != "" && cfg.mounts.mountHome) { |
30 | 27 | users.extraUsers.root.home = lib.mkVMOverride home; |
31 | 28 | } |
|
75 | 72 | "-mon chardev=char0,mode=readline" |
76 | 73 | "-device virtconsole,chardev=char0,nr=0" |
77 | 74 | ] ++ |
78 | | - lib.optional cfg.mounts.mountHome "-virtfs local,path=/home,security_model=none,mount_tag=home" ++ |
| 75 | + lib.optional cfg.mounts.mountHome "-virtfs local,path=${home},security_model=none,mount_tag=home" ++ |
79 | 76 | lib.optional (cfg.mounts.mountNixProfile && builtins.pathExists nixProfile) "-virtfs local,path=${nixProfile},security_model=none,mount_tag=nixprofile" ++ |
80 | 77 | lib.mapAttrsToList (target: mount: "-virtfs local,path=${builtins.toString mount.target},security_model=none,mount_tag=${mount.tag}") cfg.mounts.extraMounts; |
81 | 78 | }; |
82 | 79 |
|
83 | 80 | # build-vm overrides our filesystem settings in nixos-config |
84 | 81 | boot.initrd.postMountCommands = |
85 | 82 | (lib.optionalString cfg.mounts.mountHome '' |
86 | | - mkdir -p $targetRoot/home/ |
87 | | - mount -t 9p home $targetRoot/home/ -o trans=virtio,version=9p2000.L,cache=${cfg.mounts.cache},msize=${toString config.virtualisation.msize} |
| 83 | + mkdir -p $targetRoot/${lib.escapeShellArg home} |
| 84 | + mount -t 9p home $targetRoot/${lib.escapeShellArg home} -o trans=virtio,version=9p2000.L,cache=${cfg.mounts.cache},msize=${toString config.virtualisation.msize} |
88 | 85 | '') + |
89 | 86 | (lib.optionalString (user != "" && cfg.mounts.mountNixProfile) '' |
90 | 87 | mkdir -p $targetRoot/nix/var/nix/profiles/per-user/${user}/profile/ |
|
97 | 94 | '') |
98 | 95 | cfg.mounts.extraMounts); |
99 | 96 |
|
| 97 | + # avoid leaking incompatible host binaries into the VM |
| 98 | + system.activationScripts.shadow-nix-profile = lib.mkIf (options.virtualisation.host.pkgs.isDefined && config.virtualisation.host.pkgs.stdenv.hostPlatform != pkgs.stdenv.hostPlatform) (lib.stringAfter [ "specialfs" "users" "groups" ] '' |
| 99 | + mkdir -p ${lib.escapeShellArg home}/.nix-profile/ |
| 100 | + mount --bind ${config.system.path} ${lib.escapeShellArg home}/.nix-profile/ |
| 101 | + ''); |
| 102 | + |
100 | 103 | environment = { |
101 | 104 | systemPackages = with pkgs; [ |
102 | 105 | xterm # for resize command |
|
0 commit comments