Created
September 15, 2018 11:38
-
-
Save chpatrick/61a5d486dd0d806bdf07e1b1ddc85ce5 to your computer and use it in GitHub Desktop.
Using CLion with Nix
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 | |
]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you! One minor issue is replacing
cwd
in line 21 withshlex.quote(cwd)
makes it work with spaces.