forked from Vinno97/prism
-
Notifications
You must be signed in to change notification settings - Fork 0
/
nix-cmake
28 lines (21 loc) · 788 Bytes
/
nix-cmake
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
#!/usr/bin/env python3
# let's say you have a C++ project in Nix that you want to work on with CLion so that the Nix dependencies are available
# put this script in your project directory
# then, in Settings -> Build, Execution, Deployment -> Toolchains set CMake to this script
# if you need any extra nix-shell arguments, add them to the invocation at the bottom
import os
import sys
import shlex
scriptDir = os.path.dirname(os.path.realpath(__file__))
args = list(map(shlex.quote, sys.argv[1:]))
# Use the cmakeFlags set by Nix - this doesn't work with --build
if "--build" not in args:
args.insert(0, "$cmakeFlags")
cwd = os.getcwd()
cmd = 'cd ' + cwd + ' && cmake ' + ' '.join(args)
os.chdir(scriptDir)
os.execvp("nix-shell", [
'nix-shell',
'--pure',
'--run', cmd
])