Skip to content

Instantly share code, notes, and snippets.

@MattAlp
Forked from chpatrick/nix-cmake
Created January 25, 2024 17:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MattAlp/bc7372be987f995c1fbd8112021fcda0 to your computer and use it in GitHub Desktop.
Save MattAlp/bc7372be987f995c1fbd8112021fcda0 to your computer and use it in GitHub Desktop.
Using CLion with Nix
#!/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