move templates
This commit is contained in:
@@ -48,6 +48,7 @@
|
|||||||
(./home + "/jonas@comfy-station")
|
(./home + "/jonas@comfy-station")
|
||||||
(./home + "/jonas@monolith")
|
(./home + "/jonas@monolith")
|
||||||
(import-tree ./modules)
|
(import-tree ./modules)
|
||||||
|
(import-tree ./templates)
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
1
templates/_cmake-c/.gitignore
vendored
Normal file
1
templates/_cmake-c/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
build
|
||||||
10
templates/_cmake-c/CMakeLists.txt
Normal file
10
templates/_cmake-c/CMakeLists.txt
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
cmake_minimum_required(VERSION 3.15)
|
||||||
|
|
||||||
|
project(Hello
|
||||||
|
DESCRIPTION "Hello World"
|
||||||
|
LANGUAGES C
|
||||||
|
)
|
||||||
|
|
||||||
|
add_executable(hello src/main.c)
|
||||||
|
|
||||||
|
install(TARGETS hello)
|
||||||
56
templates/_cmake-c/flake.nix
Normal file
56
templates/_cmake-c/flake.nix
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
{
|
||||||
|
description = "Cmake C Flake";
|
||||||
|
|
||||||
|
inputs = {
|
||||||
|
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
|
||||||
|
flake-parts.url = "github:hercules-ci/flake-parts";
|
||||||
|
};
|
||||||
|
|
||||||
|
outputs = inputs @ {
|
||||||
|
self,
|
||||||
|
flake-parts,
|
||||||
|
...
|
||||||
|
}:
|
||||||
|
flake-parts.lib.mkFlake {inherit inputs;} (
|
||||||
|
top: {
|
||||||
|
imports = [];
|
||||||
|
|
||||||
|
flake = {
|
||||||
|
overlays.default = final: prev: {
|
||||||
|
my-derivation = final.callPackage ./nix/derivation.nix {};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
systems = [
|
||||||
|
"x86_64-linux"
|
||||||
|
];
|
||||||
|
|
||||||
|
perSystem = {
|
||||||
|
self',
|
||||||
|
pkgs,
|
||||||
|
system,
|
||||||
|
...
|
||||||
|
}: {
|
||||||
|
_module.args.pkgs = import inputs.nixpkgs {
|
||||||
|
inherit system;
|
||||||
|
overlays = [self.overlays.default];
|
||||||
|
};
|
||||||
|
|
||||||
|
packages.default = pkgs.my-derivation;
|
||||||
|
|
||||||
|
devShells.default = pkgs.mkShell {
|
||||||
|
packages = [
|
||||||
|
pkgs.cmake-language-server
|
||||||
|
pkgs.cmake-format
|
||||||
|
pkgs.clang-tools
|
||||||
|
pkgs.gdb
|
||||||
|
];
|
||||||
|
inputsFrom = [self'.packages.default];
|
||||||
|
shellHook = ''
|
||||||
|
export CMAKE_EXPORT_COMPILE_COMMANDS=ON
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
17
templates/_cmake-c/nix/derivation.nix
Normal file
17
templates/_cmake-c/nix/derivation.nix
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
{
|
||||||
|
cmake,
|
||||||
|
stdenv,
|
||||||
|
...
|
||||||
|
}:
|
||||||
|
stdenv.mkDerivation (finalAttrs: {
|
||||||
|
pname = "my-derivation";
|
||||||
|
version = "0.1.0";
|
||||||
|
src = ../.;
|
||||||
|
nativeBuildInputs = [cmake];
|
||||||
|
buildInputs = [];
|
||||||
|
|
||||||
|
meta = {
|
||||||
|
description = "Hello World Binary";
|
||||||
|
mainProgram = "hello";
|
||||||
|
};
|
||||||
|
})
|
||||||
6
templates/_cmake-c/src/main.c
Normal file
6
templates/_cmake-c/src/main.c
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
puts("Hello, Flake!");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
17
templates/_rust/.envrc
Normal file
17
templates/_rust/.envrc
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
# ^ make editor happy
|
||||||
|
|
||||||
|
#
|
||||||
|
# Use https://direnv.net/ to automatically load the dev shell.
|
||||||
|
#
|
||||||
|
|
||||||
|
if ! has nix_direnv_version || ! nix_direnv_version 3.0.4; then
|
||||||
|
source_url "https://raw.githubusercontent.com/nix-community/nix-direnv/3.0.4/direnvrc" "sha256-DzlYZ33mWF/Gs8DDeyjr8mnVmQGx7ASYqA5WlxwvBG4="
|
||||||
|
fi
|
||||||
|
|
||||||
|
watch_file nix/**
|
||||||
|
watch_file -- **/*.nix
|
||||||
|
# Adding files to git includes them in a flake
|
||||||
|
# But it is also a bit much reloading.
|
||||||
|
# watch_file .git/index .git/HEAD
|
||||||
|
use flake . --show-trace
|
||||||
3
templates/_rust/.gitignore
vendored
Normal file
3
templates/_rust/.gitignore
vendored
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
.direnv/
|
||||||
|
target/
|
||||||
|
result/
|
||||||
11
templates/_rust/Cargo.toml
Normal file
11
templates/_rust/Cargo.toml
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
[package]
|
||||||
|
name = "hello"
|
||||||
|
description = "A test rust binary"
|
||||||
|
publish = false
|
||||||
|
version = "0.1.0"
|
||||||
|
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
[[bin]]
|
||||||
|
name = "hello"
|
||||||
|
path = "src/main.rs"
|
||||||
61
templates/_rust/flake.nix
Normal file
61
templates/_rust/flake.nix
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
{
|
||||||
|
description = "Rust-Hello";
|
||||||
|
|
||||||
|
inputs = {
|
||||||
|
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
|
||||||
|
rust-overlay = {
|
||||||
|
url = "github:oxalica/rust-overlay";
|
||||||
|
inputs.nixpkgs.follows = "nixpkgs";
|
||||||
|
};
|
||||||
|
flake-utils.url = "github:numtide/flake-utils";
|
||||||
|
crate2nix = {
|
||||||
|
url = "github:nix-community/crate2nix";
|
||||||
|
inputs.nixpkgs.follows = "nixpkgs";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
outputs = inputs @ {
|
||||||
|
crate2nix,
|
||||||
|
flake-utils,
|
||||||
|
nixpkgs,
|
||||||
|
rust-overlay,
|
||||||
|
...
|
||||||
|
}:
|
||||||
|
flake-utils.lib.eachDefaultSystem (
|
||||||
|
system: let
|
||||||
|
# Overlay pkgs with rust-bin
|
||||||
|
overlays = [(import rust-overlay)];
|
||||||
|
pkgs = import nixpkgs {
|
||||||
|
inherit system overlays;
|
||||||
|
};
|
||||||
|
|
||||||
|
# Use rust-bin to generate the toolchain from rust-toolchain.toml
|
||||||
|
rust-toolchain = pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;
|
||||||
|
|
||||||
|
buildRustCrateForPkgs = _:
|
||||||
|
pkgs.buildRustCrate.override {
|
||||||
|
rustc = rust-toolchain; # Use rustc from toolchain
|
||||||
|
cargo = rust-toolchain; # Use cargo from toolchain
|
||||||
|
};
|
||||||
|
|
||||||
|
# Cargo.nix for IFD
|
||||||
|
generatedCargoNix = crate2nix.tools.${system}.generatedCargoNix {
|
||||||
|
name = "rustnix";
|
||||||
|
src = ./.;
|
||||||
|
};
|
||||||
|
|
||||||
|
cargoNix = import generatedCargoNix {
|
||||||
|
inherit pkgs buildRustCrateForPkgs;
|
||||||
|
};
|
||||||
|
in {
|
||||||
|
packages = rec {
|
||||||
|
hello = cargoNix.rootCrate.build;
|
||||||
|
default = hello;
|
||||||
|
};
|
||||||
|
|
||||||
|
devShell = pkgs.mkShell {
|
||||||
|
buildInputs = [rust-toolchain];
|
||||||
|
};
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
3
templates/_rust/rust-toolchain.toml
Normal file
3
templates/_rust/rust-toolchain.toml
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
[toolchain]
|
||||||
|
channel = "1.85.0"
|
||||||
|
components = [ "rustfmt", "rustc-dev", "rust-analyzer", "rust-src"]
|
||||||
3
templates/_rust/src/main.rs
Normal file
3
templates/_rust/src/main.rs
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
fn main() {
|
||||||
|
println!("{}", "Hello, world!");
|
||||||
|
}
|
||||||
6
templates/cmake-c.nix
Normal file
6
templates/cmake-c.nix
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
_: {
|
||||||
|
flake.templates.cmake-c = {
|
||||||
|
path = ./_cmake-c;
|
||||||
|
description = "A simple cmake c project.";
|
||||||
|
};
|
||||||
|
}
|
||||||
21
templates/mergeTemplateOptions.nix
Normal file
21
templates/mergeTemplateOptions.nix
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
# Flake module that declares flake.templates outputs and how to merge it
|
||||||
|
{
|
||||||
|
lib,
|
||||||
|
flake-parts-lib,
|
||||||
|
...
|
||||||
|
}: let
|
||||||
|
inherit (lib) mkOption types;
|
||||||
|
inherit (flake-parts-lib) mkSubmoduleOptions;
|
||||||
|
in {
|
||||||
|
options = {
|
||||||
|
flake = mkSubmoduleOptions {
|
||||||
|
templates = mkOption {
|
||||||
|
type = types.lazyAttrsOf types.unspecified;
|
||||||
|
default = {};
|
||||||
|
description = ''
|
||||||
|
Templates that will be put in the self flake.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
13
templates/rust.nix
Normal file
13
templates/rust.nix
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
_: {
|
||||||
|
flake.templates.rust = {
|
||||||
|
path = ./_rust;
|
||||||
|
description = "A simple rust binary template";
|
||||||
|
welcomeText = ''
|
||||||
|
# Rust template
|
||||||
|
This is a simple rust binary template.
|
||||||
|
To build the project run `cargo build`.
|
||||||
|
To run the project run `cargo run`.
|
||||||
|
Before running nix build, make sure to run `cargo generate-lockfile` first.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user