This commit is contained in:
jmarkin 2025-05-04 17:54:40 +03:00
parent eeec60f095
commit ca061b728b
12 changed files with 53 additions and 154 deletions

View file

@ -1,64 +1,20 @@
{
description = "A template for Nix based C++ project setup.";
description = "Minimal starting project for nix-based maturin package development";
inputs = {
# Pointing to the current stable release of nixpkgs. You can
# customize this to point to an older version or unstable if you
# like everything shining.
#
# E.g.
#
# nixpkgs.url = "github:NixOS/nixpkgs/unstable";
nixpkgs.url = "github:NixOS/nixpkgs/23.05";
utils.url = "github:numtide/flake-utils";
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-parts.url = "github:hercules-ci/flake-parts";
flake-parts.inputs.nixpkgs-lib.follows = "nixpkgs";
};
outputs = { self, nixpkgs, ... }@inputs: inputs.utils.lib.eachSystem [
# Add the system/architecture you would like to support here. Note that not
# all packages in the official nixpkgs support all platforms.
"x86_64-linux" "i686-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin"
] (system: let
pkgs = import nixpkgs {
inherit system;
outputs = { self, flake-parts, rust-overlay, ... }@inputs:
flake-parts.lib.mkFlake { inherit inputs; } {
systems = [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin" ];
# Add overlays here if you need to override the nixpkgs
# official packages.
overlays = [];
# Uncomment this if you need unfree software (e.g. cuda) for
# your project.
#
# config.allowUnfree = true;
imports = [ ./nix/development.nix ];
perSystem = { system, config, pkgs, ... }: {
formatter = pkgs.nixpkgs-fmt;
};
};
in {
devShells.default = pkgs.mkShell rec {
# Update the name to something that suites your project.
name = "my-c++-project";
packages = with pkgs; [
# Development Tools
llvmPackages_14.clang
cmake
cmakeCurses
# Development time dependencies
gtest
# Build time and Run time dependencies
spdlog
abseil-cpp
];
# Setting up the environment variables you need during
# development.
shellHook = let
icon = "f121";
in ''
export PS1="$(echo -e '\u${icon}') {\[$(tput sgr0)\]\[\033[38;5;228m\]\w\[$(tput sgr0)\]\[\033[38;5;15m\]} (${name}) \\$ \[$(tput sgr0)\]"
'';
};
packages.default = pkgs.callPackage ./default.nix {};
});
}

View file

@ -1,8 +1,6 @@
# vi: ft=bash
# shellcheck shell=bash
use flake;
# If .env missing; restore from .env.example and validate
# See https://github.com/direnv/direnv/wiki/.envrc-Boilerplate
@ -26,3 +24,6 @@ fi
export LSP_AUTOSTART=1
dotenv_if_exists || direnv status # https://direnv.net/man/direnv-stdlib.1.html
use flake;

View file

@ -15,8 +15,8 @@
imports = [ ./nix/development.nix ];
perSystem = { system, config, pkgs-dev, ... }: {
formatter = pkgs-dev.nixfmt-classic;
perSystem = { system, config, pkgs, ... }: {
formatter = pkgs.nixpkgs-fmt;
};
};
}

View file

@ -1,4 +1,8 @@
{...}:
{ inputs, ... }:
let
self = inputs.self;
nixpkgs = inputs.nixpkgs;
in
{
flake.overlays.dev = nixpkgs.lib.composeManyExtensions [
# NOTE: Put development overlays here.
@ -13,8 +17,12 @@
devShells.default = pkgs-dev.mkShell {
packages = [
pkgs-dev.nil
pkgs-dev.stylua
pkgs-dev.lua-language-server
pkgs-dev.lua
];
};
};

View file

@ -1,8 +1,6 @@
# vi: ft=bash
# shellcheck shell=bash
use flake;
# If .env missing; restore from .env.example and validate
# See https://github.com/direnv/direnv/wiki/.envrc-Boilerplate
@ -26,3 +24,5 @@ fi
export LSP_AUTOSTART=1
dotenv_if_exists || direnv status # https://direnv.net/man/direnv-stdlib.1.html
use flake;

View file

@ -15,8 +15,8 @@
imports = [ ./nix/development.nix ];
perSystem = { system, config, pkgs-dev, ... }: {
formatter = pkgs-dev.nixpkgs-fmt;
perSystem = { system, config, pkgs, ... }: {
formatter = pkgs.nixpkgs-fmt;
};
};
}

View file

@ -1,2 +0,0 @@
if __name__ == "__main__":
print(f"Hello!, 123")

View file

@ -62,6 +62,8 @@ in
'';
packages = [
pkgs-dev.nil
python.pkgs.venvShellHook
python.pkgs.pip
@ -71,11 +73,7 @@ in
pkgs-dev.pre-commit
];
shellHook = ''
export PS1="$(echo -e '\uf3e2') {\[$(tput sgr0)\]\[\033[38;5;228m\]\w\[$(tput sgr0)\]\[\033[38;5;15m\]} (${name}) \\$ \[$(tput sgr0)\]"
export PYTHONPATH="$(pwd):$PYTHONPATH"
'';
};
};
}

View file

@ -1,8 +1,6 @@
# vi: ft=bash
# shellcheck shell=bash
use flake;
# If .env missing; restore from .env.example and validate
# See https://github.com/direnv/direnv/wiki/.envrc-Boilerplate
@ -26,3 +24,6 @@ fi
export LSP_AUTOSTART=1
dotenv_if_exists || direnv status # https://direnv.net/man/direnv-stdlib.1.html
use flake;

View file

@ -1,7 +1,6 @@
# This is based on viper's article https://ayats.org/blog/nix-rustup
{
description = "Minimal starting project for nix-based maturin package development";
description = "Minimal starting project for nix-based rust development";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
@ -16,70 +15,8 @@
imports = [ ./nix/development.nix ];
perSystem = { system, config, pkgs-dev, ... }: {
formatter = pkgs-dev.nixfmt-classic;
perSystem = { system, config, pkgs, ... }: {
formatter = pkgs.nixpkgs-fmt;
};
};
# The main development environment
devShells.default =
let
pkgs = import nixpkgs {
inherit system;
overlays = [
devshell.overlays.default
rust-overlay.overlays.default
];
};
toolchain = pkgs.rust-bin.fromRustupToolchainFile ./toolchain.toml;
pythonEnv = pkgs.python3.withPackages (ps: with ps; [
numpy
]);
in
pkgs.devshell.mkShell {
name = "maturin-basics";
commands = with pkgs; [
{ name = "maturin"; package = maturin; }
{ name = "python"; package = pythonEnv; }
];
packages = [
toolchain
pkgs.rust-analyzer-unwrapped
];
env = [
{
name = "RUST_SRC_PATH";
value = "${toolchain}/lib/rustlib/src/rust/library";
}
];
};
# The development environment for testing the resulting python package.
devShells.test =
let
pkgs = import nixpkgs {
inherit system;
overlays = [ devshell.overlays.default self.overlays.default ];
};
in
pkgs.devshell.mkShell {
name = "maturin-basics-test";
commands = with pkgs; [
{
name = "python";
package = pkgs.python3.withPackages (ps: with ps; [
maturin-basics
]);
}
];
};
});
}

View file

@ -1,9 +1,9 @@
{ rust-overlay, inputs, ... }:
{ inputs, ... }:
let
self = inputs.self;
rust-overlay = inputs.rust-overlay;
nixpkgs = inputs.nixpkgs;
toolchain = pkgs.rust-bin.fromRustupToolchainFile ../toolchain.toml;
in
{
flake.overlays.dev = nixpkgs.lib.composeManyExtensions [
@ -18,17 +18,17 @@ in
overlays = [ self.overlays.dev ];
};
devShells.default = pkgs-dev.mkShell {
packages = [
toolchain
pkgs-dev.rust-analyzer-unwrapped
];
env = [
{
name = "RUST_SRC_PATH";
value = "${toolchain}/lib/rustlib/src/rust/library";
}
];
};
devShells.default =
let
toolchain = pkgs-dev.rust-bin.fromRustupToolchainFile ../toolchain.toml;
in
pkgs-dev.mkShell {
packages = [
toolchain
pkgs-dev.nil
pkgs-dev.rust-analyzer-unwrapped
];
RUST_SRC_PATH = "${toolchain}/lib/rustlib/src/rust/library";
};
};
}