Skip to content

Commit

Permalink
home: Add buildEnvWithNoChroot to help avoid darwin sandbox failures
Browse files Browse the repository at this point in the history
Sets `__noChroot = true` on select `buildEnv` derivations that assemble
large numbers of paths. This may be used to avoid sandbox failures on
darwin, see NixOS/nix#4119 and the `sandbox`
option in `man nix.conf`.
  • Loading branch information
amarshall committed Mar 2, 2023
1 parent a7d3f51 commit f09565f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 8 deletions.
20 changes: 16 additions & 4 deletions modules/home-environment.nix
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,14 @@ in
will be printed when the user configuration is being built.
'';
};

home.buildEnvWithNoChroot = mkEnableOption ''
Sets <code>__noChroot = true</code> on select <code>buildEnv</code>
derivations that assemble large numbers of paths. This may be used to
avoid sandbox failures on darwin, see
https://github.com/NixOS/nix/issues/4119 and the <code>sandbox</code>
option in <command>man nix.conf</command>.
'';
};

config = {
Expand Down Expand Up @@ -705,7 +713,7 @@ in
${activationCmds}
'';
in
pkgs.runCommand
(pkgs.runCommand
"home-manager-generation"
{
preferLocalBuild = true;
Expand All @@ -727,9 +735,11 @@ in
ln -s ${cfg.path} $out/home-path
${cfg.extraBuilderCommands}
'';
'').overrideAttrs (old: {
__noChroot = cfg.buildEnvWithNoChroot;
});

home.path = pkgs.buildEnv {
home.path = (pkgs.buildEnv {
name = "home-manager-path";

paths = cfg.packages;
Expand All @@ -740,6 +750,8 @@ in
meta = {
description = "Environment of packages installed through home-manager";
};
};
}).overrideAttrs (old: {
__noChroot = cfg.buildEnvWithNoChroot;
});
};
}
6 changes: 4 additions & 2 deletions modules/targets/darwin/fonts.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ with lib;

let
homeDir = config.home.homeDirectory;
fontsEnv = pkgs.buildEnv {
fontsEnv = (pkgs.buildEnv {
name = "home-manager-fonts";
paths = config.home.packages;
pathsToLink = "/share/fonts";
};
}).overrideAttrs (old: {
__noChroot = config.home.buildEnvWithNoChroot;
});
fonts = "${fontsEnv}/share/fonts";
in {
# macOS won't recognize symlinked fonts
Expand Down
6 changes: 4 additions & 2 deletions modules/targets/darwin/linkapps.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
config = lib.mkIf pkgs.stdenv.hostPlatform.isDarwin {
# Install MacOS applications to the user environment.
home.file."Applications/Home Manager Apps".source = let
apps = pkgs.buildEnv {
apps = (pkgs.buildEnv {
name = "home-manager-applications";
paths = config.home.packages;
pathsToLink = "/Applications";
};
}).overrideAttrs (old: {
__noChroot = config.home.buildEnvWithNoChroot;
});
in "${apps}/Applications";
};
}

0 comments on commit f09565f

Please sign in to comment.