about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--flake.nix17
-rw-r--r--rust/default.nix42
-rw-r--r--rust/toolchain.nix57
3 files changed, 116 insertions, 0 deletions
diff --git a/flake.nix b/flake.nix
new file mode 100644
index 0000000..dfb50da
--- /dev/null
+++ b/flake.nix
@@ -0,0 +1,17 @@
+# vim: ts=2
+{
+  description = "A collection of nix flake templates for diffrent languages";
+
+  outputs = {self}: {
+    templates.rust = {
+      path = ./rust;
+      description = "A simple Rust/Cargo project";
+      welcomeText = "";
+    };
+    templates.rustToolchain = {
+      path = ./rust/toolchain.nix;
+      description = "A simple Rust/Cargo project with a diffrent toolchain";
+      welcomeText = "";
+    };
+  };
+}
diff --git a/rust/default.nix b/rust/default.nix
new file mode 100644
index 0000000..75e6b2a
--- /dev/null
+++ b/rust/default.nix
@@ -0,0 +1,42 @@
+{
+  description = ""; # TODO fill
+
+  inputs = {
+    nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
+    flake-utils.url = "github:numtide/flake-utils";
+
+    crane = {
+      url = "github:ipetkov/crane";
+      inputs = {
+        nixpkgs.follows = "nixpkgs";
+        flake-utils.follows = "flake-utils";
+      };
+    };
+  };
+
+  outputs = {
+    self,
+    nixpkgs,
+    crane,
+    flake-utils,
+    ...
+  }:
+    flake-utils.lib.eachDefaultSystem (system: let
+      craneLib = crane.lib.${system};
+      craneBuild = craneLib.buildPackage {
+        src = craneLib.cleanCargoSource ./.;
+
+        doCheck = true;
+      };
+      appName = ""; # TODO fill
+    in {
+      packages.default = craneBuild;
+      legacyPackages.default = craneBuild;
+      app.default = {
+        type = "app";
+        program = "${self.packages.${system}.default}/bin/${appName}";
+      };
+    });
+}
+# vim: ts=2
+
diff --git a/rust/toolchain.nix b/rust/toolchain.nix
new file mode 100644
index 0000000..5fdb336
--- /dev/null
+++ b/rust/toolchain.nix
@@ -0,0 +1,57 @@
+{
+  description = "Build a cargo project with a custom toolchain";
+
+  inputs = {
+    nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
+    flake-utils.url = "github:numtide/flake-utils";
+
+    crane = {
+      url = "github:ipetkov/crane";
+      inputs = {
+        inputs.nixpkgs.follows = "nixpkgs";
+        flake-utils.follows = "flake-utils";
+      };
+    };
+
+    rust-overlay = {
+      url = "github:oxalica/rust-overlay";
+      inputs = {
+        nixpkgs.follows = "nixpkgs";
+        flake-utils.follows = "flake-utils";
+      };
+    };
+  };
+
+  outputs = {
+    self,
+    nixpkgs,
+    crane,
+    flake-utils,
+    rust-overlay,
+    ...
+  }:
+    flake-utils.lib.eachDefaultSystem (system: let
+      pkgs = import nixpkgs {
+        inherit system;
+        overlays = [(import rust-overlay)];
+      };
+
+      craneLib = (crane.mkLib pkgs).overrideToolchain (pkgs.rust-bin.selectLatestNightlyWith (toolchain: toolchain.default)); # TODO select toolchain
+
+      craneBuild = craneLib.buildPackage {
+        src = craneLib.cleanCargoSource ./.;
+
+        doCheck = true;
+      };
+      appName = ""; # TODO fill
+    in {
+      packages.default = craneBuild;
+
+      app.default = {
+        type = "app";
+        program = "${self.packages.${system}.default}/bin/${appName}";
+      };
+    });
+}
+# vim: ts=2
+