2018-01-17 01:51:39 +03:00
|
|
|
|
{ stdenv, writeScript, nix, pkgs }:
|
2018-01-13 17:57:10 +03:00
|
|
|
|
|
|
|
|
|
let
|
|
|
|
|
nixPath = stdenv.lib.concatStringsSep ":" [
|
|
|
|
|
"darwin-config=${toString ./configuration.nix}"
|
|
|
|
|
"darwin=${toString ../..}"
|
|
|
|
|
"nixpkgs=${toString pkgs.path}"
|
2018-10-26 19:47:45 +03:00
|
|
|
|
"$HOME/.nix-defexpr/channels"
|
|
|
|
|
"/nix/var/nix/profiles/per-user/root/channels"
|
2018-01-13 17:57:10 +03:00
|
|
|
|
"$NIX_PATH"
|
|
|
|
|
];
|
|
|
|
|
in
|
|
|
|
|
|
|
|
|
|
stdenv.mkDerivation {
|
|
|
|
|
name = "darwin-installer";
|
2018-01-25 00:37:40 +03:00
|
|
|
|
preferLocalBuild = true;
|
2018-01-13 17:57:10 +03:00
|
|
|
|
|
|
|
|
|
unpackPhase = ":";
|
|
|
|
|
|
|
|
|
|
installPhase = ''
|
|
|
|
|
mkdir -p $out/bin
|
|
|
|
|
echo "$shellHook" > $out/bin/darwin-installer
|
|
|
|
|
chmod +x $out/bin/darwin-installer
|
|
|
|
|
'';
|
|
|
|
|
|
|
|
|
|
shellHook = ''
|
|
|
|
|
set -e
|
|
|
|
|
|
2018-10-26 11:10:28 +03:00
|
|
|
|
_PATH=$PATH
|
2019-07-02 00:02:29 +03:00
|
|
|
|
export PATH=/nix/var/nix/profiles/default/bin:${nix}/bin:${pkgs.gnused}/bin:${pkgs.openssh}/bin:/usr/bin:/bin:/usr/sbin:/sbin
|
2018-06-29 18:32:09 +03:00
|
|
|
|
|
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-16 00:31:50 +03:00
|
|
|
|
echo >&2
|
|
|
|
|
echo >&2 "Installing nix-darwin..."
|
|
|
|
|
echo >&2
|
|
|
|
|
|
2018-09-14 22:52:12 +03:00
|
|
|
|
config=$(nix-instantiate --eval -E '<darwin-config>' 2> /dev/null || echo "$HOME/.nixpkgs/darwin-configuration.nix")
|
2018-01-13 17:57:10 +03:00
|
|
|
|
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"
|
2018-04-14 01:28:11 +03:00
|
|
|
|
chmod u+w "$config"
|
2018-01-15 22:44:00 +03:00
|
|
|
|
fi
|
2018-01-14 21:08:02 +03:00
|
|
|
|
|
2019-07-02 00:02:29 +03:00
|
|
|
|
# Enable nix-daemon service for multi-user installs.
|
|
|
|
|
if [ ! -w /nix/var/nix/db ]; then
|
|
|
|
|
sed -i 's/# services.nix-daemon.enable/services.nix-daemon.enable/' "$config"
|
|
|
|
|
fi
|
|
|
|
|
|
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)
|
2018-10-26 11:10:28 +03:00
|
|
|
|
PATH=$_PATH ''${EDITOR:-nano} "$config"
|
2018-01-15 22:44:00 +03:00
|
|
|
|
;;
|
|
|
|
|
esac
|
2018-01-13 17:57:10 +03:00
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
export NIX_PATH=${nixPath}
|
2019-06-25 20:50:37 +03:00
|
|
|
|
system=$(nix-build '<darwin>' -I "user-darwin-config=$config" -A system --no-out-link --show-trace)
|
2018-01-13 17:57:10 +03:00
|
|
|
|
|
2018-09-14 22:52:12 +03:00
|
|
|
|
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
|
|
|
|
|
'';
|
2018-01-17 01:51:39 +03:00
|
|
|
|
|
|
|
|
|
passthru.check = stdenv.mkDerivation {
|
|
|
|
|
name = "run-darwin-test";
|
|
|
|
|
shellHook = ''
|
|
|
|
|
set -e
|
|
|
|
|
echo >&2 "running installer tests..."
|
|
|
|
|
echo >&2
|
|
|
|
|
|
|
|
|
|
echo >&2 "checking configuration.nix"
|
|
|
|
|
test -f ~/.nixpkgs/darwin-configuration.nix
|
|
|
|
|
test -w ~/.nixpkgs/darwin-configuration.nix
|
|
|
|
|
echo >&2 "checking darwin channel"
|
|
|
|
|
readlink ~/.nix-defexpr/channels/darwin
|
|
|
|
|
test -e ~/.nix-defexpr/channels/darwin
|
|
|
|
|
echo >&2 "checking /etc"
|
|
|
|
|
readlink /etc/static
|
|
|
|
|
test -e /etc/static
|
|
|
|
|
grep /etc/static/bashrc /etc/bashrc
|
|
|
|
|
grep -v nix-daemon.sh /etc/profile
|
|
|
|
|
echo >&2 "checking /run/current-system"
|
|
|
|
|
readlink /run
|
|
|
|
|
test -e /run
|
|
|
|
|
readlink /run/current-system
|
|
|
|
|
test -e /run/current-system
|
|
|
|
|
echo >&2 "checking profile"
|
|
|
|
|
readlink /nix/var/nix/profiles/system
|
|
|
|
|
test -e /nix/var/nix/profiles/system
|
|
|
|
|
echo >&2 ok
|
|
|
|
|
exit
|
|
|
|
|
'';
|
|
|
|
|
};
|
2018-01-13 17:57:10 +03:00
|
|
|
|
}
|