2024-03-04 22:20:16 +01:00
|
|
|
#! /usr/bin/env nix-shell
|
2023-11-23 12:03:02 +01:00
|
|
|
#! nix-shell -p python3 -i 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
|
|
|
|
|
|
|
|
# Adapted script from https://gist.github.com/chpatrick/61a5d486dd0d806bdf07e1b1ddc85ce5
|
|
|
|
|
|
|
|
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")
|
|
|
|
args.append("--no-warn-unused-cli")
|
|
|
|
|
|
|
|
cwd = shlex.quote(os.getcwd())
|
|
|
|
cmd = 'cd ' + cwd + ' && cmake ' + ' '.join(args)
|
|
|
|
|
|
|
|
os.chdir(scriptDir)
|
2024-03-04 22:20:16 +01:00
|
|
|
os.execvp("nix-shell", [
|
2023-11-23 12:03:02 +01:00
|
|
|
'nix-shell',
|
|
|
|
'--pure',
|
|
|
|
'--run', cmd
|
|
|
|
])
|