1

Update environment

This commit is contained in:
2025-06-30 21:13:58 +02:00
parent 845bb5f46e
commit 0324a7054f
3 changed files with 209 additions and 128 deletions

View File

@ -1 +1 @@
./cmake-build-debug/compile_commands.json ./cmake-build-release/compile_commands.json

100
flake.lock generated
View File

@ -1,52 +1,15 @@
{ {
"nodes": { "nodes": {
"devshell": {
"inputs": {
"flake-utils": "flake-utils",
"nixpkgs": "nixpkgs"
},
"locked": {
"lastModified": 1713532798,
"narHash": "sha256-wtBhsdMJA3Wa32Wtm1eeo84GejtI43pMrFrmwLXrsEc=",
"owner": "numtide",
"repo": "devshell",
"rev": "12e914740a25ea1891ec619bb53cf5e6ca922e40",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "devshell",
"type": "github"
}
},
"flake-utils": { "flake-utils": {
"inputs": { "inputs": {
"systems": "systems" "systems": "systems"
}, },
"locked": { "locked": {
"lastModified": 1701680307, "lastModified": 1731533236,
"narHash": "sha256-kAuep2h5ajznlPMD9rnQyffWG8EM/C73lejGofXvdM8=", "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=",
"owner": "numtide", "owner": "numtide",
"repo": "flake-utils", "repo": "flake-utils",
"rev": "4022d587cbbfd70fe950c1e2083a02621806a725", "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"flake-utils_2": {
"inputs": {
"systems": "systems_2"
},
"locked": {
"lastModified": 1710146030,
"narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -57,59 +20,46 @@
}, },
"nixpkgs": { "nixpkgs": {
"locked": { "locked": {
"lastModified": 1704161960, "lastModified": 1751180975,
"narHash": "sha256-QGua89Pmq+FBAro8NriTuoO/wNaUtugt29/qqA8zeeM=", "narHash": "sha256-BKk4yDiXr4LdF80OTVqYJ53Q74rOcA/82EClXug8xsY=",
"owner": "NixOS", "owner": "NixOS",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "63143ac2c9186be6d9da6035fa22620018c85932", "rev": "a48741b083d4f36dd79abd9f760c84da6b4dc0e5",
"type": "github" "type": "github"
}, },
"original": { "original": {
"owner": "NixOS", "id": "nixpkgs",
"ref": "nixpkgs-unstable", "type": "indirect"
"repo": "nixpkgs",
"type": "github"
}
},
"nixpkgs_2": {
"locked": {
"lastModified": 1717112898,
"narHash": "sha256-7R2ZvOnvd9h8fDd65p0JnB7wXfUvreox3xFdYWd1BnY=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "6132b0f6e344ce2fe34fc051b72fb46e34f668e0",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixpkgs-unstable",
"repo": "nixpkgs",
"type": "github"
} }
}, },
"root": { "root": {
"inputs": { "inputs": {
"devshell": "devshell", "flake-utils": "flake-utils",
"flake-utils": "flake-utils_2", "nixpkgs": "nixpkgs",
"nixpkgs": "nixpkgs_2" "rust-overlay": "rust-overlay"
} }
}, },
"systems": { "rust-overlay": {
"inputs": {
"nixpkgs": [
"nixpkgs"
]
},
"locked": { "locked": {
"lastModified": 1681028828, "lastModified": 1751251399,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", "narHash": "sha256-y+viCuy/eKKpkX1K2gDvXIJI/yzvy6zA3HObapz9XZ0=",
"owner": "nix-systems", "owner": "oxalica",
"repo": "default", "repo": "rust-overlay",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", "rev": "b22d5ee8c60ed1291521f2dde48784edd6bf695b",
"type": "github" "type": "github"
}, },
"original": { "original": {
"owner": "nix-systems", "owner": "oxalica",
"repo": "default", "repo": "rust-overlay",
"type": "github" "type": "github"
} }
}, },
"systems_2": { "systems": {
"locked": { "locked": {
"lastModified": 1681028828, "lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",

227
flake.nix
View File

@ -1,87 +1,218 @@
{ rec {
description = "C/C++ Environment"; description = "C++ Brainfuck Interpreter";
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; inputs = {
inputs.flake-utils.url = "github:numtide/flake-utils"; nixpkgs.url = "nixpkgs"; # Use nixpkgs from system registry
inputs.devshell.url = "github:numtide/devshell"; flake-utils.url = "github:numtide/flake-utils";
rust-overlay.url = "github:oxalica/rust-overlay";
rust-overlay.inputs.nixpkgs.follows = "nixpkgs";
};
outputs = { outputs = {
self, self,
nixpkgs, nixpkgs,
flake-utils, flake-utils,
devshell, rust-overlay,
}: }:
# Create a shell (and possibly package) for each possible system, not only x86_64-linux
flake-utils.lib.eachDefaultSystem (system: let flake-utils.lib.eachDefaultSystem (system: let
pkgs = import nixpkgs { pkgs = import nixpkgs {
inherit system; inherit system;
config.allowUnfree = true; # For clion config.allowUnfree = true;
overlays = [devshell.overlays.default]; overlays = [
rust-overlay.overlays.default
];
}; };
# NOTE: Usual 64 bit compilers that don't collide inherit (pkgs) lib stdenv;
python = pkgs.python313.withPackages (p:
with p; [
pyside6
ffmpeg-python
matplotlib
numpy
]);
rust = pkgs.rust-bin.stable.latest.default.override {
extensions = ["rust-src"]; # Include the Rust stdlib source (for IntelliJ)
};
# 64 bit C/C++ compilers that don't collide (use the same libc)
bintools = pkgs.wrapBintoolsWith { bintools = pkgs.wrapBintoolsWith {
bintools = pkgs.bintools.bintools; bintools = pkgs.bintools.bintools; # Unwrapped bintools
libc = pkgs.glibc; libc = pkgs.glibc;
}; };
gcc13 = pkgs.hiPrio (pkgs.wrapCCWith { gcc = pkgs.hiPrio (pkgs.wrapCCWith {
cc = pkgs.gcc13.cc; cc = pkgs.gcc.cc; # Unwrapped gcc
libc = pkgs.glibc; libc = pkgs.glibc;
bintools = bintools; bintools = bintools;
}); });
clang16 = pkgs.wrapCCWith { clang = pkgs.wrapCCWith {
cc = pkgs.clang_16.cc; cc = pkgs.clang.cc; # Unwrapped clang
libc = pkgs.glibc; libc = pkgs.glibc;
bintools = bintools; bintools = bintools;
}; };
# NOTE: Multilib compilers that don't collide # Multilib C/C++ compilers that don't collide (use the same libc)
bintools_multi = pkgs.wrapBintoolsWith { bintools_multilib = pkgs.wrapBintoolsWith {
bintools = pkgs.bintools.bintools; # Get the unwrapped bintools from the wrapper bintools = pkgs.bintools.bintools; # Unwrapped bintools
libc = pkgs.glibc_multi; libc = pkgs.glibc_multi;
}; };
gcc13_multi = pkgs.hiPrio (pkgs.wrapCCWith { gcc_multilib = pkgs.hiPrio (pkgs.wrapCCWith {
cc = pkgs.gcc13.cc; # Get the unwrapped gcc from the wrapper cc = pkgs.gcc.cc; # Unwrapped gcc
libc = pkgs.glibc_multi; libc = pkgs.glibc_multi;
bintools = bintools_multi; bintools = bintools_multilib;
}); });
clang16_multi = pkgs.wrapCCWith { clang_multilib = pkgs.wrapCCWith {
cc = pkgs.clang_16.cc; cc = pkgs.clang.cc; # Unwrapped clang
libc = pkgs.glibc_multi; libc = pkgs.glibc_multi;
bintools = bintools_multi; bintools = bintools_multilib;
}; };
in {
# devShell = pkgs.devshell.mkShell ...
devShell = pkgs.devshell.mkShell {
name = "C/C++ Environment";
packages = with pkgs; [ # Stuff ran at build-time (e.g. cmake, autoPatchelfHook).
# Compilers # Architecture will be the build/target platform (relevant for e.g. cross-compilation).
# Packages will be added to $PATH.
nativeBuildInputs = with pkgs; [];
# Stuff that's linked against.
# Architecture will be the host platform.
# Packages will be added to $PATH unless "strictDeps = true;".
buildInputs = with pkgs; [
# Languages:
# python
# rust
bintools bintools
gcc13 gcc
clang16 clang
# bintools_multi # bintools_multilib
# gcc13_multi # gcc_multilib
# clang15_multi # clang_multilib
# Native buildinputs # C/C++:
gdb
valgrind
gnumake gnumake
cmake cmake
# nasm # boost
# sfml
# Development # Qt:
# bear # To generate compilation database # qt6.qtbase
gdb # qt6.full
cling # To try out my bullshit implementations # qt6.wrapQtAppsHook # For the shellHook
clang-tools_18
# doxygen # Generate docs + graphs
]; ];
in {
# TODO: Add default packages for different languages
# TODO: check nixpkgs docs for buildPythonApplication
# packages.${system}.default = pkgs.buildPythonApplication {
# pname = "pyside6_image_viewer";
# version = "0.1.0";
# };
commands = [ packages.${system}.default = stdenv.mkDerivation {
# { pname = "bfuck";
# name = "ide"; version = "1.0.0";
# help = "Run clion for project"; src = ./.;
# command = "clion &>/dev/null ./ &"; inherit nativeBuildInputs buildInputs;
# } };
devShell = pkgs.mkShell {
name = description;
# Comments on buildInputs, nativeBuildInputs, buildPackages:
# https://discourse.nixos.org/t/use-buildinputs-or-nativebuildinputs-for-nix-shell/8464
# For our "nix develop" shell, buildInputs can be used for everything.
inherit nativeBuildInputs buildInputs;
# Rust stdlib source:
# RUST_SRC_PATH = "${rust}/lib/rustlib/src/rust/library";
# Custom dynamic libraries:
# LD_LIBRARY_PATH = builtins.concatStringsSep ":" [
# # Rust Bevy GUI app
# "${pkgs.xorg.libX11}/lib"
# "${pkgs.xorg.libXcursor}/lib"
# "${pkgs.xorg.libXrandr}/lib"
# "${pkgs.xorg.libXi}/lib"
# "${pkgs.libGL}/lib"
# ];
# Dynamic libraries from buildinputs:
# LD_LIBRARY_PATH = nixpkgs.lib.makeLibraryPath buildInputs;
# Setup the shell when entering the "nix develop" environment (bash script).
shellHook = let
mkCmakeScript = type: let
typeLower = lib.toLower type;
in
pkgs.writers.writeFish "cmake-${typeLower}.fish" ''
cd $FLAKE_PROJECT_ROOT
echo "Removing build directory ./cmake-build-${typeLower}/"
rm -rf ./cmake-build-${typeLower}
echo "Creating build directory"
mkdir cmake-build-${typeLower}
cd cmake-build-${typeLower}
echo "Running cmake"
cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE="${type}" -DCMAKE_EXPORT_COMPILE_COMMANDS="On" ..
echo "Linking compile_commands.json"
cd ..
ln -sf ./cmake-build-${typeLower}/compile_commands.json ./compile_commands.json
'';
cmakeDebug = mkCmakeScript "Debug";
cmakeRelease = mkCmakeScript "Release";
mkBuildScript = type: let
typeLower = lib.toLower type;
in
pkgs.writers.writeFish "cmake-build.fish" ''
cd $FLAKE_PROJECT_ROOT/cmake-build-${typeLower}
echo "Running cmake"
cmake --build .
'';
buildDebug = mkBuildScript "Debug";
buildRelease = mkBuildScript "Release";
# Use this to specify commands that should be ran after entering fish shell
initProjectShell = pkgs.writers.writeFish "init-shell.fish" ''
echo "Entering \"${description}\" environment..."
# Determine the project root, used e.g. in cmake scripts
set -g -x FLAKE_PROJECT_ROOT (git rev-parse --show-toplevel)
# Add shell abbreviations specific to this build environment
# Rust Bevy:
# abbr -a build-release-windows "CARGO_FEATURE_PURE=1 cargo xwin build --release --target x86_64-pc-windows-msvc"
# C/C++:
abbr -a cmake-debug "${cmakeDebug}"
abbr -a cmake-release "${cmakeRelease}"
abbr -a build-debug "${buildDebug}"
abbr -a build-release "${buildRelease}"
'';
in
builtins.concatStringsSep "\n" [
# Launch into pure fish shell
''
exec "$(type -p fish)" -C "source ${initProjectShell} && abbr -a menu '${pkgs.bat}/bin/bat "${initProjectShell}"'"
''
# Qt: Launch into wrapped fish shell
# ''
# fishdir=$(mktemp -d)
# makeWrapper "$(type -p fish)" "$fishdir/fish" "''${qtWrapperArgs[@]}"
# exec "$fishdir/fish" -C "source ${initProjectShell} && abbr -a menu '${pkgs.bat}/bin/bat "${initProjectShell}"'"
# ''
]; ];
}; };
}); });