Config: Update project flake
This commit is contained in:
146
config/flake.nix
146
config/flake.nix
@ -15,6 +15,7 @@ rec {
|
|||||||
flake-utils,
|
flake-utils,
|
||||||
rust-overlay,
|
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;
|
||||||
@ -23,13 +24,18 @@ rec {
|
|||||||
rust-overlay.overlays.default
|
rust-overlay.overlays.default
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
inherit (pkgs) lib stdenv;
|
||||||
|
|
||||||
|
# ===========================================================================================
|
||||||
|
# Define custom dependencies
|
||||||
|
# ===========================================================================================
|
||||||
|
|
||||||
python = pkgs.python313.withPackages (p:
|
python = pkgs.python313.withPackages (p:
|
||||||
with p; [
|
with p; [
|
||||||
pyside6
|
# numpy
|
||||||
ffmpeg-python
|
# matplotlib
|
||||||
matplotlib
|
# ffmpeg-python
|
||||||
numpy
|
# pyside6
|
||||||
]);
|
]);
|
||||||
|
|
||||||
rust = pkgs.rust-bin.stable.latest.default.override {
|
rust = pkgs.rust-bin.stable.latest.default.override {
|
||||||
@ -67,25 +73,18 @@ rec {
|
|||||||
libc = pkgs.glibc_multi;
|
libc = pkgs.glibc_multi;
|
||||||
bintools = bintools_multilib;
|
bintools = bintools_multilib;
|
||||||
};
|
};
|
||||||
in {
|
|
||||||
# TODO: Add default packages for different languages
|
|
||||||
# TODO: check nixpkgs docs for buildPythonApplication
|
|
||||||
# packages.default = pkgs.buildPythonApplication {
|
|
||||||
# pname = "pyside6_image_viewer";
|
|
||||||
# version = "0.1.0";
|
|
||||||
# };
|
|
||||||
|
|
||||||
devShell = pkgs.mkShell {
|
# ===========================================================================================
|
||||||
name = description;
|
# Specify dependencies
|
||||||
|
# https://nixos.org/manual/nixpkgs/stable/#ssec-stdenv-dependencies-overview
|
||||||
|
# Just for a "nix develop" shell, buildInputs can be used for everything.
|
||||||
|
# ===========================================================================================
|
||||||
|
|
||||||
# Comments on buildInputs, nativeBuildInputs, buildPackages:
|
# Add dependencies to nativeBuildInputs if they are executed during the build:
|
||||||
# https://discourse.nixos.org/t/use-buildinputs-or-nativebuildinputs-for-nix-shell/8464
|
# - Those which are needed on $PATH during the build, for example cmake and pkg-config
|
||||||
# For our "nix develop" shell, buildInputs can be used for everything.
|
# - Setup hooks, for example makeWrapper
|
||||||
|
# - Interpreters needed by patchShebangs for build scripts (with the --build flag), which can be the case for e.g. perl
|
||||||
# Stuff that's linked against.
|
nativeBuildInputs = with pkgs; [
|
||||||
# Architecture will be the host platform.
|
|
||||||
# Packages will be added to $PATH unless "strictDeps = true;".
|
|
||||||
buildInputs = with pkgs; [
|
|
||||||
# Languages:
|
# Languages:
|
||||||
# python
|
# python
|
||||||
# rust
|
# rust
|
||||||
@ -101,19 +100,55 @@ rec {
|
|||||||
# valgrind
|
# valgrind
|
||||||
# gnumake
|
# gnumake
|
||||||
# cmake
|
# cmake
|
||||||
|
# pkg-config
|
||||||
|
|
||||||
|
# Qt:
|
||||||
|
# qt6.wrapQtAppsHook # For the shellHook
|
||||||
|
];
|
||||||
|
|
||||||
|
# Add dependencies to buildInputs if they will end up copied or linked into the final output or otherwise used at runtime:
|
||||||
|
# - Libraries used by compilers, for example zlib
|
||||||
|
# - Interpreters needed by patchShebangs for scripts which are installed, which can be the case for e.g. perl
|
||||||
|
buildInputs = with pkgs; [
|
||||||
|
# C/C++:
|
||||||
# boost
|
# boost
|
||||||
# sfml
|
# sfml
|
||||||
|
|
||||||
# Qt:
|
# Qt:
|
||||||
# qt6.qtbase
|
# qt6.qtbase
|
||||||
# qt6.full
|
# qt6.full
|
||||||
# qt6.wrapQtAppsHook # For the shellHook
|
|
||||||
];
|
];
|
||||||
|
|
||||||
# Stuff ran at build-time (e.g. cmake, autoPatchelfHook).
|
# ===========================================================================================
|
||||||
# Architecture will be the build/target platform (relevant for e.g. cross-compilation).
|
# Define buildable + installable packages
|
||||||
# Packages will be added to $PATH.
|
# ===========================================================================================
|
||||||
nativeBuildInputs = with pkgs; [];
|
|
||||||
|
package = stdenv.mkDerivation {
|
||||||
|
inherit nativeBuildInputs buildInputs;
|
||||||
|
pname = "";
|
||||||
|
version = "1.0.0";
|
||||||
|
src = ./.;
|
||||||
|
|
||||||
|
installPhase = ''
|
||||||
|
mkdir -p $out/bin
|
||||||
|
mv ./BINARY $out/bin
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
in rec {
|
||||||
|
# Provide package for "nix build"
|
||||||
|
defaultPackage = package;
|
||||||
|
defaultApp = flake-utils.lib.mkApp {
|
||||||
|
drv = defaultPackage;
|
||||||
|
};
|
||||||
|
|
||||||
|
# Provide environment for "nix develop"
|
||||||
|
devShell = pkgs.mkShell {
|
||||||
|
inherit nativeBuildInputs buildInputs;
|
||||||
|
name = description;
|
||||||
|
|
||||||
|
# =========================================================================================
|
||||||
|
# Define environment variables
|
||||||
|
# =========================================================================================
|
||||||
|
|
||||||
# Rust stdlib source:
|
# Rust stdlib source:
|
||||||
# RUST_SRC_PATH = "${rust}/lib/rustlib/src/rust/library";
|
# RUST_SRC_PATH = "${rust}/lib/rustlib/src/rust/library";
|
||||||
@ -131,29 +166,80 @@ rec {
|
|||||||
# Dynamic libraries from buildinputs:
|
# Dynamic libraries from buildinputs:
|
||||||
# LD_LIBRARY_PATH = nixpkgs.lib.makeLibraryPath buildInputs;
|
# LD_LIBRARY_PATH = nixpkgs.lib.makeLibraryPath buildInputs;
|
||||||
|
|
||||||
|
# =========================================================================================
|
||||||
|
# Define shell environment
|
||||||
|
# =========================================================================================
|
||||||
|
|
||||||
# Setup the shell when entering the "nix develop" environment (bash script).
|
# Setup the shell when entering the "nix develop" environment (bash script).
|
||||||
shellHook = let
|
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
|
# Use this to specify commands that should be ran after entering fish shell
|
||||||
initProjectShell = pkgs.writeShellScript "init-shell.fish" ''
|
initProjectShell = pkgs.writers.writeFish "init-shell.fish" ''
|
||||||
echo "Entering \"${description}\" environment..."
|
echo "Entering \"${description}\" environment..."
|
||||||
|
|
||||||
# Add shell abbreviations specific to this build environment
|
# Determine the project root, used e.g. in cmake scripts
|
||||||
|
set -g -x FLAKE_PROJECT_ROOT (git rev-parse --show-toplevel)
|
||||||
|
|
||||||
|
# Build the provided NixOS package
|
||||||
|
abbr -a build "nix build -L"
|
||||||
|
|
||||||
# Rust Bevy:
|
# Rust Bevy:
|
||||||
# abbr -a build-release-windows "CARGO_FEATURE_PURE=1 cargo xwin build --release --target x86_64-pc-windows-msvc"
|
# 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
|
in
|
||||||
builtins.concatStringsSep "\n" [
|
builtins.concatStringsSep "\n" [
|
||||||
# Launch into pure fish shell
|
# Launch into pure fish shell
|
||||||
''
|
''
|
||||||
exec "$(type -p fish)" -C "source ${initProjectShell}"
|
exec "$(type -p fish)" -C "source ${initProjectShell} && abbr -a menu '${pkgs.bat}/bin/bat "${initProjectShell}"'"
|
||||||
''
|
''
|
||||||
|
|
||||||
# Qt: Launch into wrapped fish shell
|
# Qt: Launch into wrapped fish shell
|
||||||
# ''
|
# ''
|
||||||
# fishdir=$(mktemp -d)
|
# fishdir=$(mktemp -d)
|
||||||
# makeWrapper "$(type -p fish)" "$fishdir/fish" "''${qtWrapperArgs[@]}"
|
# makeWrapper "$(type -p fish)" "$fishdir/fish" "''${qtWrapperArgs[@]}"
|
||||||
# exec "$fishdir/fish" -C "source ${initProjectShell}"
|
# exec "$fishdir/fish" -C "source ${initProjectShell} && abbr -a menu '${pkgs.bat}/bin/bat "${initProjectShell}"'"
|
||||||
# ''
|
# ''
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user