From 985e784e626d1fa36356bd0e10a70206720d81f9 Mon Sep 17 00:00:00 2001 From: Nydragon Date: Tue, 21 May 2024 18:59:35 +0900 Subject: [PATCH] templates: add a basic and rust template --- flake.nix | 17 ++++++++++-- templates/basic/.envrc | 1 + templates/basic/.gitignore | 1 + templates/basic/flake.nix | 29 +++++++++++++++++++ templates/default.nix | 29 +++++++++++++++++++ templates/rust/flake.nix | 57 ++++++++++++++++++++++++++++++++++++++ 6 files changed, 131 insertions(+), 3 deletions(-) create mode 100644 templates/basic/.envrc create mode 100644 templates/basic/.gitignore create mode 100644 templates/basic/flake.nix create mode 100644 templates/default.nix create mode 100644 templates/rust/flake.nix diff --git a/flake.nix b/flake.nix index d0408eb..daef06f 100644 --- a/flake.nix +++ b/flake.nix @@ -10,7 +10,8 @@ }; }; - outputs = inputs@{ self, nixpkgs, home-manager }: + outputs = + inputs@{ self, nixpkgs, ... }: let inherit (self) outputs; @@ -22,13 +23,23 @@ }; lib = nixpkgs.lib; - in { + in + { nixosConfigurations = { xps9510 = lib.nixosSystem { inherit system; modules = [ ./hosts/xps9510/configuration.nix ]; - specialArgs = { inherit inputs outputs system pkgs; }; + specialArgs = { + inherit + inputs + outputs + system + pkgs + ; + }; }; }; + + templates = import ./templates { self = self.templates; }; }; } diff --git a/templates/basic/.envrc b/templates/basic/.envrc new file mode 100644 index 0000000..44610e5 --- /dev/null +++ b/templates/basic/.envrc @@ -0,0 +1 @@ +use flake; diff --git a/templates/basic/.gitignore b/templates/basic/.gitignore new file mode 100644 index 0000000..9b42106 --- /dev/null +++ b/templates/basic/.gitignore @@ -0,0 +1 @@ +.direnv/ diff --git a/templates/basic/flake.nix b/templates/basic/flake.nix new file mode 100644 index 0000000..460bb42 --- /dev/null +++ b/templates/basic/flake.nix @@ -0,0 +1,29 @@ +{ + description = "A very basic flake"; + + inputs = { + nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable"; + utils.url = "github:numtide/flake-utils"; + }; + + outputs = + { + self, + nixpkgs, + utils, + }: + utils.lib.eachDefaultSystem ( + system: + let + pkgs = nixpkgs.legacyPackages.${system}; + in + { + devShell = pkgs.mkShell { buildInputs = with pkgs; [ ]; }; + + packages.${system} = { + hello = pkgs.hello; + default = self.packages.hello; + }; + } + ); +} diff --git a/templates/default.nix b/templates/default.nix new file mode 100644 index 0000000..07d9e36 --- /dev/null +++ b/templates/default.nix @@ -0,0 +1,29 @@ +{ self }: +{ + basic = { + path = ./basic; + description = "A basic template"; + welcomeText = '' + # A basic flake + + ## More Info + - [Nix Reference Manual](https://nixos.org/manual/nix/stable/command-ref/new-cli/nix3-flake) + ''; + }; + + rust = { + path = ./rust; + description = "A basic rust cargo template"; + welcomeText = '' + # A basic rust cargo template + + Maybe consider setting a license in ./flake.nix + + ## More Info + - [Rust language](https://www.rust-lang.org/) - https://www.rust-lang.org/ + - [Rust on the NixOS Wiki](https://nixos.wiki/wiki/Rust) - https://nixos.wiki/wiki/Rust + ''; + }; + + defaultTemplate = self.basic; +} diff --git a/templates/rust/flake.nix b/templates/rust/flake.nix new file mode 100644 index 0000000..f84476c --- /dev/null +++ b/templates/rust/flake.nix @@ -0,0 +1,57 @@ +{ + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + flake-utils.url = "github:numtide/flake-utils"; + rust-overlay.url = "github:oxalica/rust-overlay"; + }; + outputs = + { + self, + nixpkgs, + flake-utils, + rust-overlay, + ... + }: + flake-utils.lib.eachDefaultSystem ( + system: + let + manifest = (pkgs.lib.importTOML ./Cargo.toml).package; + pname = manifest.name; + + overlays = [ (import rust-overlay) ]; + pkgs = import nixpkgs { inherit system overlays; }; + + rustVersion = pkgs.rust-bin.stable.latest.default; + + rustPlatform = pkgs.makeRustPlatform { + cargo = rustVersion; + rustc = rustVersion; + }; + + rustBuild = rustPlatform.buildRustPackage { + inherit pname; + version = manifest.version; + src = ./.; + cargoLock.lockFile = ./Cargo.lock; + + meta = { + description = manifest.description; + #license = nixpkgs.lib.licenses.unlicense; + maintainers = [ ]; + }; + }; + in + { + packages = { + ${pname} = rustBuild; + default = self.packages.${pname}; + }; + + devShell = pkgs.mkShell { + buildInputs = [ (rustVersion.override { extensions = [ "rust-src" ]; }) ]; + + shellHook = ''''; + }; + } + ); +}