add templates as flake output

This commit is contained in:
ulic-youthlic 2025-05-03 23:23:02 +08:00
parent 385bfedd8f
commit c0d67ed108
Signed by: youthlic
GPG key ID: 63E86C3C14A0D721
11 changed files with 168 additions and 0 deletions

View file

@ -176,6 +176,7 @@
nixos = importApply ./flake/nixos.nix {inherit rootPath outputs;};
home = importApply ./flake/home.nix {inherit rootPath outputs;};
deploy = importApply ./flake/deploy.nix {inherit outputs;};
templates = importApply ./flake/templates.nix {inherit rootPath;};
in {
systems = flake-utils.lib.defaultSystems;
imports = [
@ -183,6 +184,7 @@
nixos
home
deploy
templates
];
perSystem = {
pkgs,

16
flake/templates.nix Normal file
View file

@ -0,0 +1,16 @@
{rootPath, ...}: {
flake-parts-lib,
lib,
...
}: {
options = {
flake = flake-parts-lib.mkSubmoduleOptions {
templates = lib.mkOption {
type = lib.types.lazyAttrsOf lib.types.raw;
};
};
};
config = {
flake.templates = import (rootPath + "/templates");
};
}

6
templates/default.nix Normal file
View file

@ -0,0 +1,6 @@
{
rust = {
path = ./rust;
description = "Rust template.";
};
}

3
templates/rust/.envrc Normal file
View file

@ -0,0 +1,3 @@
watch_file *.nix flake.lock
use flake

2
templates/rust/.gitignore vendored Normal file
View file

@ -0,0 +1,2 @@
.direnv
target

7
templates/rust/Cargo.lock generated Normal file
View file

@ -0,0 +1,7 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 4
[[package]]
name = "rust"
version = "0.1.0"

View file

@ -0,0 +1,6 @@
[package]
name = "rust"
version = "0.1.0"
edition = "2024"
[dependencies]

82
templates/rust/flake.lock generated Normal file
View file

@ -0,0 +1,82 @@
{
"nodes": {
"flake-utils": {
"inputs": {
"systems": "systems"
},
"locked": {
"lastModified": 1731533236,
"narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "11707dc2f618dd54ca8739b309ec4fc024de578b",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1746300365,
"narHash": "sha256-thYTdWqCRipwPRxWiTiH1vusLuAy0okjOyzRx4hLWh4=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "f21e4546e3ede7ae34d12a84602a22246b31f7e0",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixpkgs-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"flake-utils": "flake-utils",
"nixpkgs": "nixpkgs",
"rust-overlay": "rust-overlay"
}
},
"rust-overlay": {
"inputs": {
"nixpkgs": [
"nixpkgs"
]
},
"locked": {
"lastModified": 1746326315,
"narHash": "sha256-IDqSls/r6yBfdOBRSMQ/noTUoigmsKnTQ7TqpsBtN4Y=",
"owner": "oxalica",
"repo": "rust-overlay",
"rev": "dd280c436961ec5adccf0135efe5b66a23d84497",
"type": "github"
},
"original": {
"owner": "oxalica",
"repo": "rust-overlay",
"type": "github"
}
},
"systems": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
}
},
"root": "root",
"version": 7
}

38
templates/rust/flake.nix Normal file
View file

@ -0,0 +1,38 @@
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
flake-utils = {
url = "github:numtide/flake-utils";
};
rust-overlay = {
url = "github:oxalica/rust-overlay";
inputs = {
nixpkgs.follows = "nixpkgs";
};
};
};
outputs = {
flake-utils,
nixpkgs,
rust-overlay,
...
}:
flake-utils.lib.eachDefaultSystem (system: let
pkgs = import nixpkgs {
inherit system;
overlays = [(import rust-overlay)];
};
rustToolchain = pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;
rustPlatform = pkgs.makeRustPlatform {
cargo = rustToolchain;
rustc = rustToolchain;
};
in {
devShells.default = pkgs.mkShell {
packages = with pkgs; [
rust-analyzer
rustToolchain
];
};
});
}

View file

@ -0,0 +1,3 @@
[toolchain]
channel = "stable"
profile = "default"

View file

@ -0,0 +1,3 @@
fn main() {
println!("Hello, world!");
}