1# This module generates the nixos-checkout script, which performs a 2# checkout of the Nixpkgs Git repository. 3 4{ config, lib, pkgs, ... }: 5 6with lib; 7 8let 9 10 nixosCheckout = pkgs.substituteAll { 11 name = "nixos-checkout"; 12 dir = "bin"; 13 isExecutable = true; 14 src = pkgs.writeScript "nixos-checkout" 15 '' 16 #! ${pkgs.stdenv.shell} -e 17 18 if [ "$1" == "-h" ] || [ "$1" == "--help" ]; then 19 echo "Usage: `basename $0` [PREFIX]. See NixOS Manual for more info." 20 exit 0 21 fi 22 23 prefix="$1" 24 if [ -z "$prefix" ]; then prefix=/etc/nixos; fi 25 mkdir -p "$prefix" 26 cd "$prefix" 27 28 if [ -z "$(type -P git)" ]; then 29 echo "installing Git..." 30 nix-env -iA nixos.git 31 fi 32 33 # Move any old nixpkgs directories out of the way. 34 backupTimestamp=$(date "+%Y%m%d%H%M%S") 35 36 if [ -e nixpkgs -a ! -e nixpkgs/.git ]; then 37 mv nixpkgs nixpkgs-$backupTimestamp 38 fi 39 40 # Check out the Nixpkgs sources. 41 if ! [ -e nixpkgs/.git ]; then 42 echo "Creating repository in $prefix/nixpkgs..." 43 git init --quiet nixpkgs 44 else 45 echo "Updating repository in $prefix/nixpkgs..." 46 fi 47 cd nixpkgs 48 git remote add origin git://github.com/NixOS/nixpkgs.git || true 49 git remote add channels git://github.com/NixOS/nixpkgs-channels.git || true 50 git remote set-url origin --push git@github.com:NixOS/nixpkgs.git 51 git remote update 52 git checkout master 53 ''; 54 }; 55 56in 57 58{ 59 environment.systemPackages = [ nixosCheckout ]; 60}