Skip to content

Instantly share code, notes, and snippets.

Created October 30, 2014 12:50
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
function nixos-cleanup-safe () {
df -h /
df -h /
sudo nix-store --optimise
df -h /
function nixos-garbage-add-root () {
sudo ln -s $1 /nix/var/nix/gcroots/
# Update ~/nixpkgs git repository based on what is the latest nixos unstable:
# - the git 'basesystem' branch is the branch always pointing to nixos unstable
# - the git 'system' branch is based on 'basesystem' and adds my own stuff on top
function nixos-update () {
sudo nix-channel --update 1>/dev/null 2>&1
newref=$(cut -d'.' -f2 /nix/var/nix/profiles/per-user/root/channels/nixos/nixpkgs/svn-revision)
cd ~/nixpkgs
oldref=$(git rev-parse --verify refs/heads/basesystem)
[[ "$oldref" = "$newref"* ]]
currentbranch=$(git symbolic-ref --short HEAD 2>/dev/null)
echo Current unstable branch is at: $newref
echo Old stable branch was at: $oldref
if [[ $samep != 0 ]]; then
# there is an update
echo There is a difference
echo updating ~/nixpkgs basesystem revision
git fetch --all --quiet
git update-ref refs/heads/basesystem $newref
echo updating ~/nixpkgs system revision
git-dirty-p && echo "Dirty current working directory, quitting" && return 0
currentbranch=$(git symbolic-ref --short HEAD 2>/dev/null)
[[ $currentbranch != "system" ]] && echo "Not in 'system' branch, quitting" && return 0
git rebase basesystem
echo There are no difference
function nixos-build () {
sudo nixos-rebuild build -I nixpkgs=/home/cassou/nixpkgs -I nixos=/home/cassou/nixpkgs/nixos
function nixos-switch () {
sudo nixos-rebuild switch -I nixpkgs=/home/cassou/nixpkgs -I nixos=/home/cassou/nixpkgs/nixos
function git-dirty-p {
[[ $(git diff --shortstat 2> /dev/null | tail -n1) != "" ]]
return $?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment