From ffc8ec5c9ae6cf7b3bb95866432e30e46e7cc731 Mon Sep 17 00:00:00 2001 From: Malo Bourgon Date: Sun, 14 Aug 2022 14:04:20 -0700 Subject: [PATCH] Add .nix-defexpr to NIX_PATH the way the NixOS module does --- modules/nix/default.nix | 24 ++++++++++++++---------- modules/system/checks.nix | 8 +++++--- pkgs/darwin-installer/default.nix | 4 ++-- 3 files changed, 21 insertions(+), 15 deletions(-) diff --git a/modules/nix/default.nix b/modules/nix/default.nix index c816648a..6b32caa7 100644 --- a/modules/nix/default.nix +++ b/modules/nix/default.nix @@ -378,7 +378,6 @@ in # Include default path . { darwin-config = "${config.environment.darwinConfig}"; } "/nix/var/nix/profiles/per-user/root/channels" - "$HOME/.nix-defexpr/channels" ]; description = '' The default Nix expression search path, used by the Nix @@ -734,21 +733,26 @@ in (mkIf (config.system.stateVersion > 3) (mkOrder 1200 [ { darwin-config = "${config.environment.darwinConfig}"; } "/nix/var/nix/profiles/per-user/root/channels" - "$HOME/.nix-defexpr/channels" ])) ]; # Set up the environment variables for running Nix. environment.variables = cfg.envVars // { NIX_PATH = cfg.nixPath; }; - # Unreladed to use in NixOS module - environment.extraInit = '' - # Set up secure multi-user builds: non-root users build through the - # Nix daemon. - if [ ! -w /nix/var/nix/db ]; then - export NIX_REMOTE=daemon - fi - ''; + environment.extraInit = + '' + if [ -e "$HOME/.nix-defexpr/channels" ]; then + export NIX_PATH="$HOME/.nix-defexpr/channels''${NIX_PATH:+:$NIX_PATH}" + fi + '' + + # Not in NixOS module + '' + # Set up secure multi-user builds: non-root users build through the + # Nix daemon. + if [ ! -w /nix/var/nix/db ]; then + export NIX_REMOTE=daemon + fi + ''; nix.nrBuildUsers = mkDefault (max 32 (if cfg.settings.max-jobs == "auto" then 0 else cfg.settings.max-jobs)); diff --git a/modules/system/checks.nix b/modules/system/checks.nix index 2af25c8f..4ce69912 100644 --- a/modules/system/checks.nix +++ b/modules/system/checks.nix @@ -125,7 +125,9 @@ let ''; nixPath = '' - darwinConfig=$(NIX_PATH=${concatStringsSep ":" config.nix.nixPath} nix-instantiate --find-file darwin-config) || true + nixPath=${concatStringsSep ":" config.nix.nixPath}:$HOME/.nix-defexpr/channels + + darwinConfig=$(NIX_PATH=$nixPath nix-instantiate --find-file darwin-config) || true if ! test -e "$darwinConfig"; then echo "error: Changed but target does not exist, aborting activation" >&2 echo "Create ''${darwinConfig:-~/.nixpkgs/darwin-configuration.nix} or set environment.darwinConfig:" >&2 @@ -139,7 +141,7 @@ let exit 2 fi - darwinPath=$(NIX_PATH=${concatStringsSep ":" config.nix.nixPath} nix-instantiate --find-file darwin) || true + darwinPath=$(NIX_PATH=$nixPath nix-instantiate --find-file darwin) || true if ! test -e "$darwinPath"; then echo "error: Changed but target does not exist, aborting activation" >&2 echo "Add the darwin repo as a channel or set nix.nixPath:" >&2 @@ -153,7 +155,7 @@ let exit 2 fi - nixpkgsPath=$(NIX_PATH=${concatStringsSep ":" config.nix.nixPath} nix-instantiate --find-file nixpkgs) || true + nixpkgsPath=$(NIX_PATH=$nixPath nix-instantiate --find-file nixpkgs) || true if ! test -e "$nixpkgsPath"; then echo "error: Changed but target does not exist, aborting activation" >&2 echo "Add a nixpkgs channel or set nix.nixPath:" >&2 diff --git a/pkgs/darwin-installer/default.nix b/pkgs/darwin-installer/default.nix index cf1c7058..496aa4f0 100644 --- a/pkgs/darwin-installer/default.nix +++ b/pkgs/darwin-installer/default.nix @@ -145,13 +145,13 @@ stdenv.mkDerivation { env -i USER=john HOME=/Users/john bash -li -c 'echo $PATH' env -i USER=john HOME=/Users/john bash -li -c 'echo $PATH' | grep /Users/john/.nix-profile/bin:/run/current-system/sw/bin:/nix/var/nix/profiles/default/bin:/usr/local/bin:/usr/bin:/usr/sbin:/bin:/sbin env -i USER=john HOME=/Users/john bash -li -c 'echo $NIX_PATH' - env -i USER=john HOME=/Users/john bash -li -c 'echo $NIX_PATH' | grep darwin-config=/Users/john/.nixpkgs/darwin-configuration.nix:/nix/var/nix/profiles/per-user/root/channels:/Users/john/.nix-defexpr/channels + env -i USER=john HOME=/Users/john bash -li -c 'echo $NIX_PATH' | grep darwin-config=/Users/john/.nixpkgs/darwin-configuration.nix:/nix/var/nix/profiles/per-user/root/channels echo >&2 "checking zsh environment" env -i USER=john HOME=/Users/john zsh -l -c 'echo $PATH' env -i USER=john HOME=/Users/john zsh -l -c 'echo $PATH' | grep /Users/john/.nix-profile/bin:/run/current-system/sw/bin:/nix/var/nix/profiles/default/bin:/usr/local/bin:/usr/bin:/usr/sbin:/bin:/sbin - env -i USER=john HOME=/Users/john zsh -l -c 'echo $NIX_PATH' | grep darwin-config=/Users/john/.nixpkgs/darwin-configuration.nix:/nix/var/nix/profiles/per-user/root/channels:/Users/john/.nix-defexpr/channels env -i USER=john HOME=/Users/john zsh -l -c 'echo $NIX_PATH' + env -i USER=john HOME=/Users/john zsh -l -c 'echo $NIX_PATH' | grep darwin-config=/Users/john/.nixpkgs/darwin-configuration.nix:/nix/var/nix/profiles/per-user/root/channels echo >&2 ok exit