blob: ffd16ed6a7c000e7f522fed19a3c4bf13cd59337 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
#!/usr/bin/env bash
set -e
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
# When this script is used as is, SCRIPT_DIR is ok. If it's used as
# part of kernelDevTools, we have to inject the path to the flake.
if [ -z "$FLAKE_DIR" ]; then
FLAKE_DIR="$SCRIPT_DIR"
fi
gcc_flag=false
# Parse command-line options
TEMP=$(getopt -o '' --longoptions gcc -- "$@")
eval set -- "$TEMP"
# Extract options into variables
while true; do
case "$1" in
--gcc)
gcc_flag=true
shift
;;
--)
shift
break
;;
*)
echo "Error: Invalid option"
echo "Usage: $0 [--gcc]"
exit 1
;;
esac
done
OLDEST_VERSION=$(git tag --contains=HEAD | grep -oE 'v[0-9]+\.[0-9]+' | sort | head -n1)
if [ -z "$OLDEST_VERSION" ]; then
tput bold
echo -n "Failed to recognize kernel version."
tput sgr0
echo " This could have different reasons:"
echo
echo "1. This is not a Git checkout of the Linux kernel sources. To checkout Linux, try:"
echo " \$ linux-checkout linux-src"
echo
echo "2. The repository has no remote that contains the version tags. Try:"
echo " \$ git remote add stable git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git"
echo " \$ git fetch stable"
exit 1
fi
ATTRIBUTE="linux_$(echo "$OLDEST_VERSION" | tr -d 'v' | tr '.' '_')"
if $gcc_flag; then
ATTRIBUTE=${ATTRIBUTE}_gcc
fi
echo -n "Entering environment "
tput bold
echo -n "$ATTRIBUTE"
tput sgr0 # reset
echo ". This might take a moment. Exit via ^D."
exec nix develop "$FLAKE_DIR"\#"$ATTRIBUTE" --command "$SHELL"
|