mirror of
https://github.com/LnL7/nix-darwin.git
synced 2025-03-16 05:18:17 +00:00
installer: init
This commit is contained in:
parent
335baf7936
commit
32481b542b
4 changed files with 110 additions and 0 deletions
|
@ -73,4 +73,6 @@ in
|
||||||
inherit (eval) options config;
|
inherit (eval) options config;
|
||||||
|
|
||||||
system = eval.config.system.build.toplevel;
|
system = eval.config.system.build.toplevel;
|
||||||
|
|
||||||
|
installer = pkgs.callPackage ./pkgs/darwin-installer {};
|
||||||
}
|
}
|
||||||
|
|
44
pkgs/darwin-installer/configuration.nix
Normal file
44
pkgs/darwin-installer/configuration.nix
Normal file
|
@ -0,0 +1,44 @@
|
||||||
|
{ config, lib, pkgs, ... }:
|
||||||
|
|
||||||
|
with lib;
|
||||||
|
|
||||||
|
{
|
||||||
|
imports = [ <user-darwin-config> ];
|
||||||
|
|
||||||
|
system.activationScripts.preUserActivation.text = mkBefore ''
|
||||||
|
darwinPath=$(NIX_PATH=${concatStringsSep ":" config.nix.nixPath} nix-instantiate --eval -E '<darwin>' 2> /dev/null) || true
|
||||||
|
if ! test -e "$darwinPath"; then
|
||||||
|
if test -t 1; then
|
||||||
|
read -p "Would you like to manage <darwin> with nix-channel? [y/n] " i
|
||||||
|
fi
|
||||||
|
case "$i" in
|
||||||
|
y|Y)
|
||||||
|
nix-channel --add https://github.com/LnL7/nix-darwin/archive/master.tar.gz darwin
|
||||||
|
nix-channel --update
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
fi
|
||||||
|
|
||||||
|
if ! test -L /etc/bashrc && ! grep -q /etc/static/bashrc /etc/bashrc; then
|
||||||
|
if test -t 1; then
|
||||||
|
read -p "Would you like to load darwin configuration in /etc/bashrc? [y/n] " i
|
||||||
|
fi
|
||||||
|
case "$i" in
|
||||||
|
y|Y)
|
||||||
|
echo 'if test -e /etc/static/bashrc; then . /etc/static/bashrc; fi' | sudo tee -a /etc/bashrc
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
fi
|
||||||
|
|
||||||
|
if ! test -L /etc/profile && grep -q 'etc/profile.d/nix-daemon.sh' /etc/profile; then
|
||||||
|
if test -t 1; then
|
||||||
|
read -p "Would you like to remove nix-daemon.sh configuration in /etc/profile? [y/n] " i
|
||||||
|
fi
|
||||||
|
case "$i" in
|
||||||
|
y|Y)
|
||||||
|
sudo patch -d /etc -p1 < '${./profile.patch}'
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
fi
|
||||||
|
'';
|
||||||
|
}
|
50
pkgs/darwin-installer/default.nix
Normal file
50
pkgs/darwin-installer/default.nix
Normal file
|
@ -0,0 +1,50 @@
|
||||||
|
{ 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
|
||||||
|
|
||||||
|
export nix=${nix}
|
||||||
|
|
||||||
|
config=$(nix-instantiate --eval -E '<darwin-config>' 2> /dev/null || echo "$HOME/.nixpkgs/darwin-configuration.nix")
|
||||||
|
if ! test -f "$config"; then
|
||||||
|
echo "copying example configuration.nix" >&2
|
||||||
|
mkdir -p "$HOME/.nixpkgs"
|
||||||
|
cp "${toString ../../modules/examples/simple.nix}" "$config"
|
||||||
|
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
|
||||||
|
|
||||||
|
darwin-rebuild switch -I "user-darwin-config=$config"
|
||||||
|
|
||||||
|
echo >&2
|
||||||
|
echo " Open '$config' to get started." >&2
|
||||||
|
echo " See the README for more information: [0;34mhttps://github.com/LnL7/nix-darwin/blob/master/README.md[0m" >&2
|
||||||
|
echo >&2
|
||||||
|
echo " Don't forget to start a new shell or source /etc/static/bashrc." >&2
|
||||||
|
echo >&2
|
||||||
|
exit
|
||||||
|
'';
|
||||||
|
}
|
14
pkgs/darwin-installer/profile.patch
Normal file
14
pkgs/darwin-installer/profile.patch
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
diff --git a/profile b/profile
|
||||||
|
index 3748e3b..36ad2cd 100644
|
||||||
|
--- a/profile
|
||||||
|
+++ b/profile
|
||||||
|
@@ -7,9 +7,3 @@ fi
|
||||||
|
if [ "${BASH-no}" != "no" ]; then
|
||||||
|
[ -r /etc/bashrc ] && . /etc/bashrc
|
||||||
|
fi
|
||||||
|
-
|
||||||
|
-# Nix
|
||||||
|
-if [ -e '/nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh' ]; then
|
||||||
|
- . '/nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh'
|
||||||
|
-fi
|
||||||
|
-# End Nix
|
Loading…
Add table
Reference in a new issue