summary refs log blame commit diff
path: root/build.sh
blob: 27d0e1143105abd716a5b05d21b865ca367b46e8 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
                        
                                                                 


                                                             
                                                                                                                                      

                       
                                                               
                                                                             
                                         
                                                                                                                                  
                                                                              
                                                                 
                                              
    
                                                                                           
                                         
                                                                               
                                                 
                                              
                                         
        
  
#!/usr/bin/env nix-shell
#!nix-shell -i bash -p git nixos-install-tools nix-output-monitor
if [ $# -ne 2 ]; then
    echo "Usage: $0 <root> <config>"
    echo "NOTE: hardware config will be generated from root!"
    echo "Defined configs:"
    cat flake.nix | grep '.lib.nixosSystem' | sed 's/ =.*//' | sed 's/^[ \t]*//;s/[ \t]*$//' | while read cfg; do echo " - $cfg"; done
    exit 1
fi
if [ "$1" = "/" ]; then
    [ -f "host/${2}/pre-rebuild.sh" ] && host/$2/pre-rebuild.sh
    nixos-generate-config --show-hardware-config > hardware-configuration.nix
    git add -f hardware-configuration.nix
    nom build .#nixosConfigurations.${2}.config.system.build.toplevel && sudo nixos-rebuild switch --flake .#${HOSTNAME} || exit 1
    nixos-rebuild switch --flake ".#${2}" -j`nproc` --upgrade-all -L || exit 1
    [ -f "host/${2}/post-rebuild.sh" ] && host/$2/post-rebuild.sh
    git rm --cached hardware-configuration.nix
    exit
else
    nixos-generate-config --show-hardware-config --root "${1}" > hardware-configuration.nix
    git add -f hardware-configuration.nix
    nom build .#nixosConfigurations.${2}.config.system.build.toplevel || exit 1
    nixos-install --root "${1}" --flake ".#${2}" 
    git rm --cached hardware-configuration.nix
    cp . "${1}/Rory-Open-Architecture" -r
    exit
fi