Skip to content

Commit 30ba93e

Browse files
committed
allow bootstrapping a dev environment from 21.05
1 parent 24f1672 commit 30ba93e

File tree

2 files changed

+62
-4
lines changed

2 files changed

+62
-4
lines changed

dev-setup

+9-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
#!/usr/bin/env bash
22
echo "This will set up the channels dir and show the export command to set the NIX_PATH accordingly." >&2
3-
echo "You can also use 'nix develop --impure' to open the dev shell and run build_channels_dir from there." >&2
4-
# ensure PWD is the directory this script resides in (allows calls like ../dev-setup or $HOME/fc-nixos/dev-setup)
5-
cd "$(dirname "$(readlink -f "$0")")"
6-
nix develop --impure "$@" --command dev_setup
3+
4+
if [[ "$(nixos-version)" =~ ^"21" ]]; then
5+
./dev-setup-from-21.05
6+
else
7+
# ensure PWD is the directory this script resides in (allows calls like ../dev-setup or $HOME/fc-nixos/dev-setup)
8+
echo "You can also use 'nix develop --impure' to open the dev shell and run build_channels_dir from there." >&2
9+
cd "$(dirname "$(readlink -f "$0")")"
10+
nix develop --impure "$@" --command dev_setup
11+
fi

dev-setup-from-21.05

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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

Comments
 (0)