Commit 5290666
Changed files (19)
modules
flake-parts
modules/flake-parts/templates.nix
@@ -0,0 +1,3 @@
+{
+ imports = [../../templates];
+}
templates/common/nix/package.nix
@@ -0,0 +1,2 @@
+{hello}:
+hello
templates/common/nix/shell.nix
@@ -0,0 +1,12 @@
+(import (
+ let
+ lock = builtins.fromJSON (builtins.readFile ./flake.lock);
+ nodeName = lock.nodes.root.inputs.flake-compat;
+ in
+ fetchTarball {
+ url =
+ lock.nodes.${nodeName}.locked.url
+ or "https://github.com/NixOS/flake-compat/archive/${lock.nodes.${nodeName}.locked.rev}.tar.gz";
+ sha256 = lock.nodes.${nodeName}.locked.narHash;
+ }
+) {src = ../.;}).shellNix
templates/common/nix/treefmt.nix
@@ -0,0 +1,5 @@
+{
+ projectRootFile = "flake.nix";
+
+ programs.alejandra.enable = true;
+}
templates/common/.envrc
@@ -0,0 +1,1 @@
+use flake
templates/common/.gitignore
@@ -0,0 +1,4 @@
+# Nix
+.direnv
+result
+result-*
templates/common/flake.nix
@@ -0,0 +1,40 @@
+{
+ inputs = {
+ nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
+
+ flake-utils.url = "github:numtide/flake-utils";
+
+ flake-compat.url = "github:NixOS/flake-compat";
+
+ treefmt-nix = {
+ url = "github:numtide/treefmt-nix";
+ inputs.nixpkgs.follows = "nixpkgs";
+ };
+ };
+
+ outputs = {
+ self,
+ nixpkgs,
+ flake-utils,
+ treefmt-nix,
+ ...
+ }:
+ flake-utils.lib.eachDefaultSystem (system: let
+ pkgs = nixpkgs.legacyPackages.${system};
+ treefmt = (treefmt-nix.lib.evalModule pkgs ./nix/treefmt.nix).config.build;
+ in {
+ formatter = treefmt.wrapper;
+
+ checks.formatting = treefmt.check self;
+
+ packages = {
+ default = pkgs.callPackage ./nix/package.nix {};
+ };
+
+ devShell = pkgs.mkShell {
+ nativeBuildInputs = with pkgs; [
+ hello
+ ];
+ };
+ });
+}
templates/rust/nix/package.nix
@@ -0,0 +1,12 @@
+{craneLib}: let
+ commonArgs = {
+ src = craneLib.cleanCargoSource ../.;
+ strictDeps = true;
+ buildInputs = [
+ ];
+ };
+in
+ craneLib.buildPackage (commonArgs
+ // {
+ cargoArtifacts = craneLib.buildDepsOnly commonArgs;
+ })
templates/rust/nix/shell.nix
@@ -0,0 +1,12 @@
+(import (
+ let
+ lock = builtins.fromJSON (builtins.readFile ./flake.lock);
+ nodeName = lock.nodes.root.inputs.flake-compat;
+ in
+ fetchTarball {
+ url =
+ lock.nodes.${nodeName}.locked.url
+ or "https://github.com/NixOS/flake-compat/archive/${lock.nodes.${nodeName}.locked.rev}.tar.gz";
+ sha256 = lock.nodes.${nodeName}.locked.narHash;
+ }
+) {src = ../.;}).shellNix
templates/rust/nix/treefmt.nix
@@ -0,0 +1,9 @@
+{
+ projectRootFile = "flake.nix";
+
+ programs.alejandra.enable = true;
+
+ programs.rustfmt.enable = true;
+
+ programs.taplo.enable = true;
+}
templates/rust/src/main.rs
@@ -0,0 +1,3 @@
+fn main() {
+ println!("Hello, world!");
+}
templates/rust/.envrc
@@ -0,0 +1,1 @@
+use flake
templates/rust/.gitignore
@@ -0,0 +1,7 @@
+# Rust
+/target
+
+# Nix
+.direnv
+result
+result-*
templates/rust/Cargo.lock
@@ -0,0 +1,7 @@
+# This file is automatically @generated by Cargo.
+# It is not intended for manual editing.
+version = 4
+
+[[package]]
+name = "nix_template"
+version = "0.1.0"
templates/rust/Cargo.toml
@@ -0,0 +1,6 @@
+[package]
+name = "nix_template"
+version = "0.1.0"
+edition = "2024"
+
+[dependencies]
templates/rust/flake.nix
@@ -0,0 +1,51 @@
+{
+ inputs = {
+ nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
+
+ flake-utils.url = "github:numtide/flake-utils";
+
+ flake-compat.url = "github:NixOS/flake-compat";
+
+ crane.url = "github:ipetkov/crane";
+
+ treefmt-nix = {
+ url = "github:numtide/treefmt-nix";
+ inputs.nixpkgs.follows = "nixpkgs";
+ };
+ };
+
+ outputs = {
+ self,
+ nixpkgs,
+ flake-utils,
+ crane,
+ treefmt-nix,
+ ...
+ }:
+ flake-utils.lib.eachDefaultSystem (system: let
+ pkgs = nixpkgs.legacyPackages.${system};
+
+ craneLib = crane.mkLib pkgs;
+
+ treefmt = (treefmt-nix.lib.evalModule pkgs ./nix/treefmt.nix).config.build;
+ in {
+ formatter = treefmt.wrapper;
+
+ checks.formatting = treefmt.check self;
+
+ packages = {
+ default = pkgs.callPackage ./nix/package.nix {inherit craneLib;};
+ };
+
+ devShells.default = pkgs.mkShell {
+ nativeBuildInputs = with pkgs; [
+ cargo
+ rustc
+
+ rustfmt
+ rust-analyzer
+ taplo
+ ];
+ };
+ });
+}
templates/rust/taplo.toml
@@ -0,0 +1,9 @@
+[formatting]
+reorder_keys = false
+
+[[rule]]
+include = ["**/Cargo.toml"]
+keys = ["dependencies"]
+
+[rule.formatting]
+reorder_keys = true
templates/.gitattributes
@@ -0,0 +1,2 @@
+* linguist-vendored
+*.nix -linguist-vendored
templates/default.nix
@@ -0,0 +1,15 @@
+{
+ flake.templates = rec {
+ default = common;
+
+ common = {
+ path = ./common;
+ description = "Basic Nix template";
+ };
+
+ rust = {
+ path = ./rust;
+ description = "Basic Rust project Nix template with crane";
+ };
+ };
+}