2017-07-23 16:05:46 +02:00
|
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
|
|
let
|
2017-07-23 18:56:37 +02:00
|
|
|
|
darwinChanges = ''
|
|
|
|
|
if test -e /run/current-system/darwin-changes; then
|
2017-07-23 19:22:40 +02:00
|
|
|
|
darwinChanges=$(diff --changed-group-format='%>' --unchanged-group-format= /run/current-system/darwin-changes $systemConfig/darwin-changes 2> /dev/null) || true
|
2017-07-23 18:56:37 +02:00
|
|
|
|
if test -n "$darwinChanges"; then
|
|
|
|
|
echo >&2
|
|
|
|
|
echo "[1;1mCHANGELOG[0m" >&2
|
|
|
|
|
echo >&2
|
|
|
|
|
echo "$darwinChanges" >&2
|
|
|
|
|
echo >&2
|
|
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
'';
|
|
|
|
|
|
2017-07-23 16:05:46 +02:00
|
|
|
|
buildUsers = optionalString config.services.nix-daemon.enable ''
|
2017-07-23 19:07:04 +02:00
|
|
|
|
buildUser=$(dscl . -read /Groups/nixbld GroupMembership 2>&1 | awk '/^GroupMembership: / {print $2}') || true
|
2017-07-23 16:05:46 +02:00
|
|
|
|
if [ -z $buildUser ]; then
|
2017-07-23 17:23:09 +02:00
|
|
|
|
echo "[1;31merror: Using the nix-daemon requires build users, aborting activation[0m" >&2
|
|
|
|
|
echo "Create the build users or disable the daemon:" >&2
|
|
|
|
|
echo "$ ./bootstrap -u" >&2
|
|
|
|
|
echo >&2
|
|
|
|
|
echo "or set" >&2
|
|
|
|
|
echo >&2
|
|
|
|
|
echo " services.nix-daemon.enable = false;" >&2
|
|
|
|
|
echo >&2
|
|
|
|
|
exit 2
|
|
|
|
|
fi
|
|
|
|
|
'';
|
|
|
|
|
|
2017-07-23 18:56:37 +02:00
|
|
|
|
nixPath = ''
|
2017-07-24 19:29:31 +02:00
|
|
|
|
darwinConfig=$(NIX_PATH=${concatStringsSep ":" config.nix.nixPath} nix-instantiate --eval -E '<darwin-config>') || true
|
2017-07-23 17:49:38 +02:00
|
|
|
|
if ! test -e "$darwinConfig"; then
|
2017-07-23 17:28:58 +02:00
|
|
|
|
echo "[1;31merror: Changed <darwin-config> but target does not exist, aborting activation[0m" >&2
|
|
|
|
|
echo "Move you configuration.nix or set NIX_PATH:" >&2
|
|
|
|
|
echo >&2
|
2017-07-23 18:27:01 +02:00
|
|
|
|
echo " nix.nixPath = [ \"darwin-config=$(nix-instantiate --eval -E '<darwin-config>')\" ];" >&2
|
2017-07-23 17:28:58 +02:00
|
|
|
|
echo >&2
|
|
|
|
|
exit 2
|
|
|
|
|
fi
|
|
|
|
|
|
2017-07-24 19:29:31 +02:00
|
|
|
|
darwinPath=$(NIX_PATH=${concatStringsSep ":" config.nix.nixPath} nix-instantiate --eval -E '<darwin>') || true
|
2017-07-23 17:49:38 +02:00
|
|
|
|
if ! test -e "$darwinPath"; then
|
2017-07-23 17:23:09 +02:00
|
|
|
|
echo "[1;31merror: Changed <darwin> but target does not exist, aborting activation[0m" >&2
|
|
|
|
|
echo "Add the darwin repo as a channel or set NIX_PATH:" >&2
|
|
|
|
|
echo "$ sudo nix-channel --add https://github.com/LnL7/nix-darwin/archive/master.tar.gz darwin" >&2
|
2017-07-23 17:49:38 +02:00
|
|
|
|
echo "$ sudo nix-channel --update" >&2
|
2017-07-23 17:23:09 +02:00
|
|
|
|
echo >&2
|
|
|
|
|
echo "or set" >&2
|
|
|
|
|
echo >&2
|
2017-07-23 18:27:01 +02:00
|
|
|
|
echo " nix.nixPath = [ \"darwin=$(nix-instantiate --eval -E '<darwin>')\" ];" >&2
|
2017-07-23 17:23:09 +02:00
|
|
|
|
echo >&2
|
2017-07-23 16:05:46 +02:00
|
|
|
|
exit 2
|
|
|
|
|
fi
|
2017-07-23 17:49:38 +02:00
|
|
|
|
|
2017-07-24 19:29:31 +02:00
|
|
|
|
nixpkgsPath=$(NIX_PATH=${concatStringsSep ":" config.nix.nixPath} nix-instantiate --eval -E '<nixpkgs>') || true
|
2017-07-23 17:49:38 +02:00
|
|
|
|
if ! test -e "$nixpkgsPath"; then
|
|
|
|
|
echo "[1;31merror: Changed <nixpkgs> but target does not exist, aborting activation[0m" >&2
|
|
|
|
|
echo "Add a nixpkgs channel or set NIX_PATH:" >&2
|
|
|
|
|
echo "$ sudo nix-channel --add http://nixos.org/channels/nixpkgs-unstable nixpkgs" >&2
|
|
|
|
|
echo "$ sudo nix-channel --update" >&2
|
|
|
|
|
echo >&2
|
|
|
|
|
echo "or set" >&2
|
|
|
|
|
echo >&2
|
2017-07-23 18:27:01 +02:00
|
|
|
|
echo " nix.nixPath = [ \"nixpkgs=$(nix-instantiate --eval -E '<darwin>')\" ];" >&2
|
2017-07-23 17:49:38 +02:00
|
|
|
|
echo >&2
|
|
|
|
|
exit 2
|
|
|
|
|
fi
|
2017-07-23 16:05:46 +02:00
|
|
|
|
'';
|
|
|
|
|
in
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
options = {
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
config = {
|
|
|
|
|
|
|
|
|
|
system.activationScripts.checks.text = ''
|
2017-07-23 18:56:37 +02:00
|
|
|
|
${darwinChanges}
|
2017-07-23 16:05:46 +02:00
|
|
|
|
${buildUsers}
|
2017-07-23 17:23:09 +02:00
|
|
|
|
${nixPath}
|
2017-07-23 18:02:08 +02:00
|
|
|
|
|
|
|
|
|
if test ''${checkActivation:-0} -eq 1; then
|
|
|
|
|
echo "ok" >&2
|
|
|
|
|
exit 0
|
|
|
|
|
fi
|
2017-07-23 16:05:46 +02:00
|
|
|
|
'';
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
}
|