1
0
Fork 0
mirror of https://github.com/LnL7/nix-darwin.git synced 2025-03-16 21:38:21 +00:00

add nix-tools and use <darwin-config> instead of config.nix

This commit is contained in:
Daiderd Jordan 2016-12-11 12:49:11 +01:00
parent dae0095a4e
commit 6ca27b9903
No known key found for this signature in database
GPG key ID: D02435D05B810C96
4 changed files with 217 additions and 225 deletions

View file

@ -12,14 +12,20 @@ let
./modules/system/defaults
./modules/system/etc.nix
./modules/system/launchd.nix
./modules/nix
./modules/environment
./modules/launchd
./modules/services/activate-system.nix
./modules/services/nix-daemon.nix
./modules/programs/tmux.nix
./modules/programs/nix-darwin.nix
];
};
system = eval.config.system.build.toplevel;
in
eval
{
inherit (eval) config;
inherit system;
}

View file

@ -1,12 +1,9 @@
{ pkgs ? import <nixpkgs> {} }:
let
config =
{ config, lib, pkgs, ... }:
{
{ config, lib, pkgs, ... }:
{
environment.systemPackages =
[ pkgs.lnl.zsh
[ config.system.build.nix
pkgs.lnl.zsh
pkgs.lnl.tmux
pkgs.lnl.vim
pkgs.curl
@ -82,21 +79,15 @@ let
'i'|'instantiate') nix-instantiate -E "with import <nixpkgs> {}; $@" ;;
'r'|'repl') nix-repl '<nixpkgs>' ;;
's'|'shell') nix-shell -E "with import <nixpkgs> {}; $@" ;;
'p'|'package') nix-shell '<nixpkgs>' -p "with import <nixpkgs> {}; $@" --run ${pkgs.lnl.zsh}/bin/zsh ;;
'z'|'zsh') nix-shell '<nixpkgs>' -E "with import <nixpkgs> {}; $@" --run ${pkgs.lnl.zsh}/bin/zsh ;;
esac
}
nixdarwin-rebuild () {
cmd=$1
shift
case $cmd in
'build') nix-build '<nixpkgs>' -A nixdarwin.toplevel "$@" ;;
'repl') nix-repl "$HOME/.nixpkgs/config.nix" "$@" ;;
'shell') nix-shell '<nixpkgs>' -p nixdarwin.toplevel --run ${pkgs.lnl.zsh}/bin/zsh "$@" ;;
'exec') __ETC_ZSHRC_SOURCED= __ETC_ZSHENV_SOURCED= __ETC_ZPROFILE_SOURCED= exec ${pkgs.lnl.zsh}/bin/zsh -l ;;
'switch') systemConfig=$(nix-build --no-out-link '<nixpkgs>' -A nixdarwin.toplevel) && nix-shell '<nixpkgs>' -A nixdarwin.toplevel --run 'sudo $out/activate' && sudo nix-env --profile ${config.system.profile} --set $systemConfig ;;
'p'|'package') nix-shell '<nixpkgs>' -p "with import <nixpkgs> {}; $@" --run $SHELL ;;
'z'|'zsh') nix-shell '<nixpkgs>' -E "with import <nixpkgs> {}; $@" --run $SHELL ;;
'exec')
echo "reexecuting shell: $SHELL" >&2
__ETC_ZSHRC_SOURCED= \
__ETC_ZSHENV_SOURCED= \
__ETC_ZPROFILE_SOURCED= \
exec $SHELL -l
;;
esac
}
@ -119,7 +110,7 @@ let
if [ -n "$__ETC_ZSHENV_SOURCED" ]; then return; fi
export __ETC_ZSHENV_SOURCED=1
export NIX_PATH=nixpkgs=$HOME/.nix-defexpr/nixpkgs:$HOME/.nix-defexpr/channels_root
export NIX_PATH=nixpkgs=$HOME/.nix-defexpr/nixpkgs:darwin=$HOME/.nix-defexpr/darwin:darwin-config=$HOME/.nixpkgs/darwin-config.nix:$HOME/.nix-defexpr/channels_root
# Set up secure multi-user builds: non-root users build through the
# Nix daemon.
@ -159,84 +150,4 @@ let
. /etc/zshrc.local
fi
'';
};
eval = import ../.. { inherit config; };
in
{
inherit (eval) config;
inherit (eval.config.system) build;
packageOverrides = self: {
nixdarwin = eval.config.system.build;
lnl.zsh = pkgs.runCommand pkgs.zsh.name
{ buildInputs = [ pkgs.makeWrapper ]; }
''
source $stdenv/setup
mkdir -p $out/bin
makeWrapper "${pkgs.zsh}/bin/zsh" "$out/bin/zsh"
'';
lnl.tmux = pkgs.runCommand pkgs.tmux.name
{ buildInputs = [ pkgs.makeWrapper ]; }
''
source $stdenv/setup
mkdir -p $out/bin
makeWrapper "${pkgs.tmux}/bin/tmux" "$out/bin/tmux" \
--add-flags -f --add-flags "/run/current-system/etc/tmux.conf" \
'';
lnl.vim = pkgs.vim_configurable.customize {
name = "vim";
vimrcConfig.customRC = ''
set nocompatible
filetype plugin indent on
syntax on
colorscheme solarized
set bg=dark
set et sw=2 ts=2
set bs=indent,start
set nowrap
set list
set listchars=tab:»·,trail:·,extends:,precedes:
set fillchars+=vert:\ ,stl:\ ,stlnc:\
set lazyredraw
set clipboard=unnamed
vmap s S
cnoremap %% <C-r>=expand('%:h') . '/'<CR>
set hlsearch
nnoremap // :nohlsearch<CR>
let mapleader = ' '
nnoremap <Leader>p :FZF<CR>
nnoremap <silent> <Leader>e :exe 'FZF ' . expand('%:h')<CR>
source $HOME/.vimrc.local
'';
# vimrcConfig.vam.knownPlugins = with pkgs.vimUtils; (pkgs.vimPlugins // {
# vim-nix = buildVimPluginFrom2Nix {
# name = "vim-nix-unstable";
# src = ../../../vim-nix;
# };
# });
vimrcConfig.vam.pluginDictionaries = [
{ names = [ "fzfWrapper" "youcompleteme" "fugitive" "surround" "vim-nix" "colors-solarized" ]; }
];
};
};
allowUnfree = true;
}

19
modules/nix/default.nix Normal file
View file

@ -0,0 +1,19 @@
{ config, pkgs, ... }:
let
tools = pkgs.callPackage ../../pkgs/nix-tools {};
in
{
config = {
system.build.nix = pkgs.runCommand "nix-darwin" {} ''
mkdir -p $out/bin
ln -s ${tools.darwin-option} $out/bin/darwin-option
ln -s ${tools.darwin-rebuild} $out/bin/darwin-rebuild
'';
};
}

View file

@ -0,0 +1,56 @@
{ stdenv, writeScript, coreutils, nix }:
{
darwin-option = writeScript "darwin-option" ''
#! ${stdenv.shell}
set -e
echo "$0: not implemented" >&2
exit 1
'';
darwin-rebuild = writeScript "darwin-rebuild" ''
#! ${stdenv.shell}
set -e
showSyntax() {
exec man darwin-rebuild
exit 1
}
# Parse the command line.
origArgs=("$@")
action=
profile=/nix/var/nix/profiles/system
while [ "$#" -gt 0 ]; do
i="$1"; shift 1
case "$i" in
--help)
showSyntax
;;
switch|build)
action="$i"
;;
*)
echo "$0: unknown option \`$i'"
exit 1
;;
esac
done
if [ -z "$action" ]; then showSyntax; fi
export PATH=${coreutils}/bin:$PATH
echo "building the system configuration..." >&2
if [ "$action" = switch -o "$action" = build ]; then
systemConfig="$(nix-build '<darwin>' --no-out-link -A system)"
fi
if [ "$action" = switch ]; then
sudo nix-env -p "$profile" --set $systemConfig
sudo $systemConfig/activate
fi
'';
}