Last active
December 28, 2015 08:19
-
-
Save matejc/7471057 to your computer and use it in GitHub Desktop.
nixmy - my nixpkgs repo manage script inspired by nixdev but much much simpler
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# !!!MODIFY NEXT 3 LINES BEFORE RUNNING ANY COMMANDS!!! | |
export NIX_MY_PKGS='/home/matej/workarea/nixpkgs' # where the local repo is/will be after nixmy-init | |
export NIX_USER_PROFILE_DIR='/nix/var/nix/profiles/per-user/matej' # change your user name | |
export NIX_MY_GITHUB='git://github.com/matejc/nixpkgs.git' # your nixpkgs git repository | |
# after running nixmy-init you will have nixpkgs directory in current working directory | |
# | |
# BRANCHES: | |
# local - where you will do your work and modifications | |
# this is also where you want to be where nixmy-rebuild is called | |
# master - this is where master branch of git://github.com/NixOS/nixpkgs.git is | |
# | |
# REMOTES: | |
# origin - $NIX_MY_GITHUB | |
# upstream - official repository git://github.com/NixOS/nixpkgs.git | |
# before running nixmy-update make sure that you commit or stash changes | |
# running nixmy-update will rebase from NixOS/nixpkgs to master and then checkout local branch back | |
# every now and then you can update your $NIX_MY_GITHUB repository by pushing to it: | |
# ex: | |
# git checkout master | |
# git push origin master | |
# do not forget to checkout local branch after as this is your work branch | |
export NIX_PATH="nixpkgs=$NIX_MY_PKGS:nixos=$NIX_MY_PKGS/nixos:nixos-config=/etc/nixos/configuration.nix:services=/etc/nixos/services" | |
# alias nixmy-profile="nix-env -f '$NIX_MY_PKGS' -p $NIX_USER_PROFILE_DIR/" | |
alias nixmy-py27="nix-env -f '$NIX_MY_PKGS' -p $NIX_USER_PROFILE_DIR/py27 -i py27" | |
alias nixmy-robotenv="nix-env -f '$NIX_MY_PKGS' -p $NIX_USER_PROFILE_DIR/robotenv -i robotenv" | |
alias nixmy-makeenv="nix-env -f '$NIX_MY_PKGS' -p $NIX_USER_PROFILE_DIR/makeenv -i makeenv" | |
alias nixmy-cd="cd '$NIX_MY_PKGS'" | |
alias nix-env="nix-env -f '$NIX_MY_PKGS'" | |
# Sudo helper | |
_asroot() { | |
case `whoami` in | |
root) | |
echo "" ;; | |
*) | |
echo "sudo -H " ;; | |
esac | |
} | |
nixmy-profile() { | |
nix-env -f "$NIX_MY_PKGS" -p $NIX_USER_PROFILE_DIR/"$1" -i "$1" ; | |
} | |
nixmy-rebuild() { `_asroot` nixos-rebuild -I $NIX_MY_PKGS "$@" ; } | |
# Print latest Hydra's revision | |
nixmy-revision() { | |
local rev=`wget -q -S --output-document - http://nixos.org/channels/nixos-unstable/ 2>&1 | grep Location | awk -F '/' '{print $6}' | awk -F '.' '{print $3}'` | |
printf "%s" $rev | |
} | |
nixmy-update() { | |
cd $NIX_MY_PKGS | |
local diffoutput="`git --no-pager diff`" | |
if [ -z $diffoutput ]; then | |
{ | |
echo "git diff is empty, preceding ..." && | |
git checkout master && | |
git pull --rebase upstream master && | |
git checkout "local" && | |
local rev=`nixmy-revision` && | |
echo "rebasing 'local' to '$rev'" && | |
git rebase $rev && | |
echo "UPDATE done, enjoy!" | |
} || { | |
echo "ERROR with update!" | |
return 1 | |
} | |
else | |
git status | |
echo "STAGE IS NOT CLEAN! CLEAR IT BEFORE UPDATE!" | |
return 1 | |
fi | |
} | |
nixmy-init() { | |
{ | |
git clone $NIX_MY_GITHUB nixpkgs && | |
cd nixpkgs && | |
git remote add upstream git://github.com/NixOS/nixpkgs.git && | |
git pull --rebase upstream master && | |
git branch "local" && | |
git checkout "local" && | |
echo "INIT and UPDATE done, enjoy!" | |
} || { | |
echo "ERROR with init!" | |
return 1 | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment