mirror of
https://github.com/LnL7/nix-darwin.git
synced 2024-12-14 11:57:34 +00:00
add nix-script
This commit is contained in:
parent
4978d9ee6f
commit
bc5fc1af32
2 changed files with 197 additions and 21 deletions
|
@ -27,6 +27,7 @@
|
|||
pkgs.gettext
|
||||
pkgs.git
|
||||
pkgs.jq
|
||||
pkgs.mosh
|
||||
pkgs.silver-searcher
|
||||
|
||||
pkgs.nix-repl
|
||||
|
@ -107,26 +108,12 @@
|
|||
'';
|
||||
|
||||
programs.zsh.loginShellInit = ''
|
||||
nix () {
|
||||
cmd=$1
|
||||
shift
|
||||
|
||||
case $cmd in
|
||||
'b'|'build') nix-build --no-out-link -E "with import <nixpkgs> {}; $@" ;;
|
||||
'e'|'eval') nix-instantiate --eval -E "with import <nixpkgs> {}; $@" ;;
|
||||
'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 $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
|
||||
reexec() {
|
||||
echo "reexecuting shell: $SHELL" >&2
|
||||
__ETC_ZSHRC_SOURCED= \
|
||||
__ETC_ZSHENV_SOURCED= \
|
||||
__ETC_ZPROFILE_SOURCED= \
|
||||
exec $SHELL -l
|
||||
}
|
||||
'';
|
||||
|
||||
|
@ -146,6 +133,8 @@
|
|||
environment.shellAliases.gl = "git log --graph --oneline";
|
||||
environment.shellAliases.gd = "git diff --minimal --patch";
|
||||
|
||||
environment.shellAliases.nix = "${pkgs.lnl.nix-script}/bin/nix";
|
||||
|
||||
nix.nixPath =
|
||||
[ # Use local nixpkgs checkout instead of channels.
|
||||
"darwin=$HOME/.nix-defexpr/darwin"
|
||||
|
@ -156,6 +145,12 @@
|
|||
|
||||
nixpkgs.config.allowUnfree = true;
|
||||
|
||||
nixpkgs.config.packageOverrides = self: {
|
||||
nixpkgs.config.packageOverrides = pkgs: {
|
||||
lnl.nix-script = pkgs.substituteAll {
|
||||
name = "nix";
|
||||
src = ../../pkgs/nix-tools/nix.sh;
|
||||
dir = "bin";
|
||||
isExecutable = true;
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
181
pkgs/nix-tools/nix.sh
Executable file
181
pkgs/nix-tools/nix.sh
Executable file
|
@ -0,0 +1,181 @@
|
|||
#! @shell@
|
||||
set -e
|
||||
set -o pipefail
|
||||
|
||||
|
||||
showUsage() {
|
||||
echo "usage: nix [--version] [--help]" >&2
|
||||
echo " <action> [<args>] [-- <expr>]" >&2
|
||||
echo "actions: {i | instantiate | e | eval | drv}" >&2
|
||||
echo " {b | build | out}" >&2
|
||||
echo " {s | shell | zsh}" >&2
|
||||
echo " {h | hash}" >&2
|
||||
echo " {store | gc}" >&2
|
||||
echo " {r | repl}" >&2
|
||||
exit ${@:-1}
|
||||
}
|
||||
|
||||
showVersion() {
|
||||
version=$(nix-env --version | awk '{print $3}')
|
||||
echo "$0 (Nix) $version"
|
||||
exit 0
|
||||
}
|
||||
|
||||
# Parse the command line.
|
||||
origArgs=("$@")
|
||||
extraNixFlags=()
|
||||
exprArg=
|
||||
action=
|
||||
src=
|
||||
|
||||
while [ "$#" -gt 0 ]; do
|
||||
i="$1"; shift 1
|
||||
case "$i" in
|
||||
--help)
|
||||
showUsage 0
|
||||
;;
|
||||
--version|v|version)
|
||||
showVersion
|
||||
;;
|
||||
i|instantiate)
|
||||
action='instantiate'
|
||||
;;
|
||||
e|eval)
|
||||
action='instantiate'
|
||||
extraNixFlags+=('--eval')
|
||||
;;
|
||||
drv)
|
||||
action='instantiate'
|
||||
extraNixFlags+=('-Q' '--indirect' '--add-root' "$PWD/result.drv")
|
||||
;;
|
||||
b|build)
|
||||
action='build'
|
||||
extraNixFlags+=('--no-out-link')
|
||||
;;
|
||||
out)
|
||||
action='build'
|
||||
extraNixFlags+=('-Q')
|
||||
;;
|
||||
s|shell)
|
||||
action='shell'
|
||||
;;
|
||||
zsh)
|
||||
action='shell'
|
||||
extraNixFlags+=('--run' 'zsh')
|
||||
;;
|
||||
h|hash)
|
||||
action='hash'
|
||||
extraNixFlags+=('--type' 'sha256')
|
||||
;;
|
||||
store)
|
||||
action='store'
|
||||
;;
|
||||
gc)
|
||||
action='store'
|
||||
extraNixFlags+=('--gc' '--max-freed' '32G')
|
||||
;;
|
||||
r|repl)
|
||||
action='repl'
|
||||
;;
|
||||
--strict|--xml|--json|--indirect)
|
||||
# nix-instantiate
|
||||
extraNixFlags+=("$i")
|
||||
;;
|
||||
--add-root)
|
||||
# nix-instantiate
|
||||
if [ -z "$1" ]; then
|
||||
echo "$0: \`$i' requires an argument"
|
||||
exit 1
|
||||
fi
|
||||
j="$1"; shift 1
|
||||
extraNixFlags+=("$i" "$j")
|
||||
;;
|
||||
--verbose|-v|--no-build-output|-Q|--keep-going|-k|--keep-failed|-K|--fallback|--readonly-mode|--show-trace)
|
||||
# nix-build
|
||||
extraNixFlags+=("$i")
|
||||
;;
|
||||
--max-jobs|-j|--cores|-A|-I|--drv-link|--out-link|-o)
|
||||
# nix-build
|
||||
if [ -z "$1" ]; then
|
||||
echo "$0: \`$i' requires an argument"
|
||||
exit 1
|
||||
fi
|
||||
j="$1"; shift 1
|
||||
extraNixFlags+=("$i" "$j")
|
||||
;;
|
||||
--option|--arg|--argstr)
|
||||
if [ -z "$1" -o -z "$2" ]; then
|
||||
echo "$0: \`$i' requires two arguments"
|
||||
exit 1
|
||||
fi
|
||||
j="$1"; shift 1
|
||||
k="$1"; shift 1
|
||||
extraNixFlags+=("$i" "$j" "$k")
|
||||
;;
|
||||
--)
|
||||
break
|
||||
;;
|
||||
'./'*|'<'*'>')
|
||||
src="$i"
|
||||
;;
|
||||
*)
|
||||
echo "Unknown option: $i" >&2
|
||||
showUsage 129
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [ -z "$action" ]; then showUsage; fi
|
||||
|
||||
if [ "$action" = version ]; then showVersion; fi
|
||||
|
||||
if [ -z "$src" -a -f ./default.nix ]; then
|
||||
src='./.'
|
||||
fi
|
||||
|
||||
if [ "$#" -gt 0 ]; then
|
||||
extraNixFlags+=('-E')
|
||||
exprArg="$@"
|
||||
fi
|
||||
|
||||
if [ -n "$src" -a -z "$exprArg" ]; then
|
||||
extraNixFlags+=("$src")
|
||||
fi
|
||||
|
||||
if [ -n "$exprArg" ]; then
|
||||
if [ -f "$src" -o -f "$src/default.nix" ]; then
|
||||
if [ "$src" = ./. ]; then
|
||||
exprArg="with import ./. {}; $exprArg"
|
||||
else
|
||||
exprArg="with callPackage $src {}; $exprArg"
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ "$src" != ./. ]; then
|
||||
exprArg="with import <nixpkgs> {}; $exprArg"
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ "$action" = instantiate ]; then
|
||||
exec nix-instantiate ${extraNixFlags[@]} "$exprArg"
|
||||
fi
|
||||
|
||||
if [ "$action" = build ]; then
|
||||
exec nix-build ${extraNixFlags[@]} "$exprArg"
|
||||
fi
|
||||
|
||||
if [ "$action" = shell ]; then
|
||||
exec nix-shell ${extraNixFlags[@]} "$exprArg"
|
||||
fi
|
||||
|
||||
if [ "$action" = hash ]; then
|
||||
exec nix-hash ${extraNixFlags[@]}
|
||||
fi
|
||||
|
||||
if [ "$action" = store ]; then
|
||||
exec nix-store ${extraNixFlags[@]} "$exprArg"
|
||||
fi
|
||||
|
||||
if [ "$action" = repl ]; then
|
||||
exec nix-repl '<nixpkgs/lib>' "${src:-<nixpkgs>}"
|
||||
fi
|
Loading…
Reference in a new issue