|
| 1 | +#!/usr/bin/env bash |
| 2 | +# Usage: eval `./dev-setup2` |
| 3 | +set -e |
| 4 | + |
| 5 | +# ensure PWD is the directory this script resides in (allows calls like ../dev-setup or $HOME/fc-nixos/dev-setup) |
| 6 | +cd "$(dirname "$(readlink -f "$0")")" |
| 7 | + |
| 8 | +base=$PWD |
| 9 | +# preserve nixos-config |
| 10 | +config=$(nix-instantiate --find-file nixos-config 2>/dev/null) || true |
| 11 | + |
| 12 | +# bootstrapping with what we find on the system |
| 13 | +if [[ ! -e /tmp/nixos-2411-bootstrap/nixpkgs ]]; then |
| 14 | + rm -rf /tmp/nixos-2411-bootstrap |
| 15 | + mkdir /tmp/nixos-2411-bootstrap |
| 16 | + cd /tmp/nixos-2411-bootstrap |
| 17 | + curl -o nixpkgs.tar.gz -L https://github.com/flyingcircusio/nixpkgs/archive/refs/heads/nixos-24.11.tar.gz |
| 18 | + tar xf nixpkgs.tar.gz |
| 19 | + ln -s nixpkgs-nixos-24.11 nixpkgs |
| 20 | +fi |
| 21 | +cd $base |
| 22 | +NIX_PATH="/tmp/nixos-2411-bootstrap" |
| 23 | +export NIX_PATH |
| 24 | +channels=`nix-build -Q --quiet versions.nix -A allUpstreams --no-out-link` |
| 25 | +if [[ -z $channels ]]; then |
| 26 | + echo "$0: failed to build nixpkgs+overlay" >&2 |
| 27 | + exit 1 |
| 28 | +fi |
| 29 | +mkdir -p channels |
| 30 | +find $channels -maxdepth 1 -type l | while read channel; do |
| 31 | + target="channels/${channel##*/}" |
| 32 | + # don't toucn anything which is not a link into the nix store |
| 33 | + if [[ ! -L $target && -d $target ]]; then |
| 34 | + echo "$0: warning: $target appears to be a local dev checkout" >&2 |
| 35 | + continue |
| 36 | + elif [[ -L $target && $(readlink $target) != /nix/store/* ]]; then |
| 37 | + echo "$0: warning: $target appears to be a local dev checkout" >&2 |
| 38 | + continue |
| 39 | + fi |
| 40 | + ln -fs $channel channels |
| 41 | +done |
| 42 | +if ! [[ -e channels/fc ]]; then |
| 43 | + ln -s .. channels/fc |
| 44 | +fi |
| 45 | + |
| 46 | +NIX_PATH="$base/channels" |
| 47 | +if [[ -n "$config" ]]; then |
| 48 | + NIX_PATH="${NIX_PATH}:nixos-config=$config" |
| 49 | +else |
| 50 | + NIX_PATH="${NIX_PATH}:nixos-config=${base}/nixos" |
| 51 | +fi |
| 52 | + |
| 53 | +echo "export NIX_PATH=$NIX_PATH" |
0 commit comments