mirror of
https://github.com/foo-dogsquared/nixos-config.git
synced 2025-01-30 22:57:55 +00:00
templates/basic-nix-cpp-app: init
This commit is contained in:
parent
03590ad834
commit
85c29f0e63
@ -6,6 +6,10 @@
|
||||
path = ../../templates/basic-devshell;
|
||||
description = "Basic development shell template";
|
||||
};
|
||||
basic-nix-cpp-app = {
|
||||
path = ../../templates/basic-nix-cpp-app;
|
||||
description = "Basic Nix program with C++ API";
|
||||
};
|
||||
basic-nix-module-flake = {
|
||||
path = ../../templates/basic-nix-module-flake;
|
||||
description = "Basic Nix module flake template";
|
||||
|
37
templates/basic-nix-cpp-app/default.nix
Normal file
37
templates/basic-nix-cpp-app/default.nix
Normal file
@ -0,0 +1,37 @@
|
||||
{ stdenv
|
||||
, lib
|
||||
, cmake
|
||||
, meson
|
||||
, ninja
|
||||
, pkg-config
|
||||
, boost
|
||||
, nix
|
||||
, semver-cpp
|
||||
}:
|
||||
|
||||
stdenv.mkDerivation {
|
||||
pname = "app";
|
||||
version = "0.1.0";
|
||||
|
||||
src = ./.;
|
||||
|
||||
nativeBuildInputs = [
|
||||
meson
|
||||
ninja
|
||||
pkg-config
|
||||
];
|
||||
|
||||
buildInputs = [
|
||||
cmake
|
||||
boost
|
||||
nix
|
||||
semver-cpp
|
||||
];
|
||||
|
||||
meta = with lib; {
|
||||
description = "Basic Nix CLI";
|
||||
license = licenses.mit;
|
||||
maintainers = with maintainers; [ foo-dogsquared ];
|
||||
platforms = nix.meta.platforms;
|
||||
};
|
||||
}
|
11
templates/basic-nix-cpp-app/meson.build
Normal file
11
templates/basic-nix-cpp-app/meson.build
Normal file
@ -0,0 +1,11 @@
|
||||
project('app',
|
||||
'cpp',
|
||||
version: '0.1.0',
|
||||
license: 'MIT',
|
||||
meson_version: '>=0.56.0',
|
||||
default_options: [
|
||||
'cpp_std=c++20'
|
||||
]
|
||||
)
|
||||
|
||||
subdir('src')
|
13
templates/basic-nix-cpp-app/shell.nix
Normal file
13
templates/basic-nix-cpp-app/shell.nix
Normal file
@ -0,0 +1,13 @@
|
||||
{ pkgs ? import <nixpkgs> { } }:
|
||||
|
||||
let
|
||||
app = pkgs.callPackage ./. { };
|
||||
in
|
||||
pkgs.mkShell {
|
||||
inputsFrom = [ app ];
|
||||
|
||||
packages = with pkgs; [
|
||||
git
|
||||
clang-tools
|
||||
];
|
||||
}
|
29
templates/basic-nix-cpp-app/src/main.cc
Normal file
29
templates/basic-nix-cpp-app/src/main.cc
Normal file
@ -0,0 +1,29 @@
|
||||
// A nifty little app for resolving flakerefs to the locked input. Because the
|
||||
// C++ API is mostly unstable, this is confirmed to be working with Nix v2.18.2
|
||||
// just for reference.
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
#include <nix/flake/flake.hh>
|
||||
#include <nix/shared.hh>
|
||||
#include <nix/store-api.hh>
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
nix::initNix();
|
||||
|
||||
auto store = nix::openStore();
|
||||
|
||||
try {
|
||||
nix::FlakeRef originalRef =
|
||||
nix::parseFlakeRef(argv[1], std::nullopt, true, false);
|
||||
auto [tree, lockedInput] = originalRef.input.fetch(store);
|
||||
std::cout << lockedInput.to_string() << std::endl;
|
||||
} catch (std::exception &e) {
|
||||
std::cerr << e.what() << std::endl;
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
19
templates/basic-nix-cpp-app/src/meson.build
Normal file
19
templates/basic-nix-cpp-app/src/meson.build
Normal file
@ -0,0 +1,19 @@
|
||||
app_srcs = [
|
||||
'main.cc',
|
||||
]
|
||||
|
||||
NIX_VERSION = '>=2.17'
|
||||
|
||||
deps = [
|
||||
dependency('nix-cmd', version: NIX_VERSION),
|
||||
dependency('nix-main', version: NIX_VERSION),
|
||||
dependency('nix-expr', version: NIX_VERSION),
|
||||
dependency('nix-store', version: NIX_VERSION),
|
||||
]
|
||||
|
||||
executable('app',
|
||||
app_srcs,
|
||||
dependencies: deps,
|
||||
install: true,
|
||||
link_args: '-Wl,-lnixfetchers'
|
||||
)
|
Loading…
Reference in New Issue
Block a user