2018-01-13 17:57:10 +03:00
|
|
|
|
{ stdenv, nix, pkgs }:
|
|
|
|
|
|
|
|
|
|
let
|
|
|
|
|
nixPath = stdenv.lib.concatStringsSep ":" [
|
|
|
|
|
"darwin-config=${toString ./configuration.nix}"
|
|
|
|
|
"darwin=${toString ../..}"
|
|
|
|
|
"nixpkgs=${toString pkgs.path}"
|
|
|
|
|
"$NIX_PATH"
|
|
|
|
|
];
|
|
|
|
|
in
|
|
|
|
|
|
|
|
|
|
stdenv.mkDerivation {
|
|
|
|
|
name = "darwin-installer";
|
|
|
|
|
|
|
|
|
|
unpackPhase = ":";
|
|
|
|
|
|
|
|
|
|
installPhase = ''
|
|
|
|
|
mkdir -p $out/bin
|
|
|
|
|
echo "$shellHook" > $out/bin/darwin-installer
|
|
|
|
|
chmod +x $out/bin/darwin-installer
|
|
|
|
|
'';
|
|
|
|
|
|
|
|
|
|
shellHook = ''
|
|
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
set -e
|
|
|
|
|
|
2018-01-13 23:17:29 +03:00
|
|
|
|
action=switch
|
|
|
|
|
while [ "$#" -gt 0 ]; do
|
2018-01-15 22:44:00 +03:00
|
|
|
|
i="$1"; shift 1
|
|
|
|
|
case "$i" in
|
|
|
|
|
--help)
|
|
|
|
|
echo "darwin-installer: [--help] [--check]"
|
|
|
|
|
exit
|
|
|
|
|
;;
|
|
|
|
|
--check)
|
|
|
|
|
action=check
|
|
|
|
|
;;
|
|
|
|
|
esac
|
2018-01-13 23:17:29 +03:00
|
|
|
|
done
|
|
|
|
|
|
2018-01-13 17:57:10 +03:00
|
|
|
|
export nix=${nix}
|
|
|
|
|
|
|
|
|
|
config=$(nix-instantiate --eval -E '<darwin-config>' 2> /dev/null || echo "$HOME/.nixpkgs/darwin-configuration.nix")
|
|
|
|
|
if ! test -f "$config"; then
|
2018-01-15 22:44:00 +03:00
|
|
|
|
echo "copying example configuration.nix" >&2
|
|
|
|
|
mkdir -p "$HOME/.nixpkgs"
|
|
|
|
|
cp "${toString ../../modules/examples/simple.nix}" "$config"
|
|
|
|
|
fi
|
2018-01-14 21:08:02 +03:00
|
|
|
|
|
2018-01-15 22:44:00 +03:00
|
|
|
|
# Skip when stdin is not a tty, eg.
|
|
|
|
|
# $ yes | darwin-installer
|
|
|
|
|
if test -t 0; then
|
|
|
|
|
read -p "Would you like edit the default configuration.nix before starting? [y/n] " i
|
|
|
|
|
case "$i" in
|
|
|
|
|
y|Y)
|
|
|
|
|
$EDITOR "$config"
|
|
|
|
|
;;
|
|
|
|
|
esac
|
2018-01-13 17:57:10 +03:00
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
export NIX_PATH=${nixPath}
|
|
|
|
|
system=$($nix/bin/nix-build '<darwin>' -I "user-darwin-config=$config" -A system --no-out-link)
|
|
|
|
|
export PATH=$system/sw/bin:$PATH
|
|
|
|
|
|
2018-01-13 23:17:29 +03:00
|
|
|
|
darwin-rebuild "$action" -I "user-darwin-config=$config"
|
2018-01-13 17:57:10 +03:00
|
|
|
|
|
|
|
|
|
echo >&2
|
2018-01-15 22:44:00 +03:00
|
|
|
|
echo >&2 " Open '$config' to get started."
|
|
|
|
|
echo >&2 " See the README for more information: [0;34mhttps://github.com/LnL7/nix-darwin/blob/master/README.md[0m"
|
2018-01-13 17:57:10 +03:00
|
|
|
|
echo >&2
|
2018-01-15 22:44:00 +03:00
|
|
|
|
echo >&2 " Don't forget to start a new shell or source /etc/static/bashrc."
|
2018-01-13 17:57:10 +03:00
|
|
|
|
echo >&2
|
|
|
|
|
exit
|
|
|
|
|
'';
|
|
|
|
|
}
|