Starter project for your C++ application with nix as a package manager
If you don't know what nix package manager is, please look at the FAQ section
Configured to work when used both as a regular nix derivation, and as a
flake. In both cases, the version of nixpkgs
is used from flake.lock
(JSON file).
That way, we get some of the flake advantages even when using it as a regular derivation.
Similar to nixpkgs
, project leverages the custom kotur-nixpkgs
channel for all package requirements that are not available within nixpkgs
. One such example is the python package
dinosay
, which is being used to display
the welcome message at the moment of entering dev shell with nix-shell
command.
default.nix
- Definition for the package being defined by this repo, list of dependencies (nix packages)shell.nix
- Usesdefault.nix
to read shell definition and exposes it to the userflake.nix
- Enables using the package as a flakeflake.lock
- Locked version of packages (mainly nixpkgs) which are used both for default flake use-case
In this section, you can find various commands that can help you use the full potential of tools used within the project
- Building the package
nix-build
- default waynix build
- flakes way
- Enter the development environment (shell)
nix-shell
- default way, use --pure to enter shell in pure modenix develop
- flakes way, use -i to ignore the environment
nix flake update
- Updatesflake.lock
file (used both byflake.nix
anddefault.nix
)nix fmt
- Format nix files based on a formatter specified inflake.nix
file
Flakes are still an experimental feature of Nix, to add flake support look at the flakes documentation
Building with CMake from dev shell
After entering the dev environment, you can use the standard CMake procedure to build the project.
mkdir build && cd build
cmake .. -DCMAKE_BUILD_TYPE=Debug
make -j$(nproc)
NOTE: Compile commands are automatically generated with nix build
, or nix-build
.
In order to have autocompletion for the project, you can leverage compile_commands.json
which can be exported by
following the steps described bellow
-
Open two terminal/shell instances and
cd
into the project -
In both terminals enter the development shell (look how in Nix commands section)
-
In terminal one type
mini_compile_commands_server.py
-
In terminal two use the standard CMake build procedure without the final (gnu) make command
-
In terminal one, terminate the app with
SIGINT
by pressingCtrl+c
-
compile_commands.json
file should be generated at the root of the project -
Close terminal one, continue using or close terminal two
List of frequiently asked questions: