Skip to content

Instantly share code, notes, and snippets.

@7c6f434c
Created December 7, 2018 19:08
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 7c6f434c/9dfe7478189344761818eacca0a453fd to your computer and use it in GitHub Desktop.
Save 7c6f434c/9dfe7478189344761818eacca0a453fd to your computer and use it in GitHub Desktop.
#! /bin/sh
nix-instantiate --find-file nixpkgs >/dev/null || {
echo "Could not find nixpkgs, please set up your NIX_PATH"
exit 1
}
NIX_DO_STASH="${NIX_DO_STASH:-$HOME/.local/share/nix-do}"
NIX_DO_PROFILE="${NIX_DO_PROFILE:-$(readlink $HOME/.nix-profile)}"
mkdir -p "$NIX_DO_STASH"
op="$1"; shift
case "$op" in
pull)
cd "$(nix-instantiate --find-file nixpkgs)";
git remote update
git pull -v
;;
expression)
echo "let
pkgs = import {};
fullEnv = packages:
pkgs.buildEnv {
name = ''$USER-profile-env'';
paths = packages;
ignoreCollisions = true;
pathsToLink = [''/''];
};
in
fullEnv [
$(for p in "$NIX_DO_STASH"/*/output*; do
test -e "$p" && readlink -f "$p"
done)
]
"
;;
rebuild)
nix-env --set -p "$NIX_DO_PROFILE" "$(nix-instantiate -E "$("$0" expression)")"
;;
install)
for p in "$@"; do
nix-build "" -A "$p.all" -o "$NIX_DO_STASH/$p/output"
done
"$0" rebuild
;;
upgrade)
"$0" install $("$0" list)
;;
remove)
( cd "$NIX_DO_STASH"; for p in "$@"; do rm -rf "$p"; done);
"$0" rebuild
;;
clean)
nix-collect-garbage -d
;;
list)
( cd "$NIX_DO_STASH"; ls )
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment