commit b696670112787496c5413b5b1c8570039e695783 Author: Daniel Flanagan Date: Wed Feb 12 10:15:25 2025 -0600 chore: init nix flake and cargo workspace diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..9b35cbd --- /dev/null +++ b/.envrc @@ -0,0 +1,2 @@ +nix_direnv_manual_reload +use flake diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..86c240d --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +/target +/result +/.direnv +/.pre-commit-config.yaml diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..2a6a1de --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,7 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "lyt" +version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..848a9ab --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,3 @@ +[workspace] +resolver = "2" +members = ["lyt"] diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..f69c033 --- /dev/null +++ b/flake.lock @@ -0,0 +1,87 @@ +{ + "nodes": { + "flake-compat": { + "flake": false, + "locked": { + "lastModified": 1696426674, + "narHash": "sha256-kvjfFW7WAETZlt09AgDn1MrtKzP7t90Vf7vypd3OL1U=", + "owner": "edolstra", + "repo": "flake-compat", + "rev": "0f9255e01c2351cc7d116c072cb317785dd33b33", + "type": "github" + }, + "original": { + "owner": "edolstra", + "repo": "flake-compat", + "type": "github" + } + }, + "git-hooks": { + "inputs": { + "flake-compat": "flake-compat", + "gitignore": "gitignore", + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1737465171, + "narHash": "sha256-R10v2hoJRLq8jcL4syVFag7nIGE7m13qO48wRIukWNg=", + "owner": "cachix", + "repo": "git-hooks.nix", + "rev": "9364dc02281ce2d37a1f55b6e51f7c0f65a75f17", + "type": "github" + }, + "original": { + "owner": "cachix", + "repo": "git-hooks.nix", + "type": "github" + } + }, + "gitignore": { + "inputs": { + "nixpkgs": [ + "git-hooks", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1709087332, + "narHash": "sha256-HG2cCnktfHsKV0s4XW83gU3F57gaTljL9KNSuG6bnQs=", + "owner": "hercules-ci", + "repo": "gitignore.nix", + "rev": "637db329424fd7e46cf4185293b9cc8c88c95394", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "gitignore.nix", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1739206421, + "narHash": "sha256-PwQASeL2cGVmrtQYlrBur0U20Xy07uSWVnFup2PHnDs=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "44534bc021b85c8d78e465021e21f33b856e2540", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-24.11", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "git-hooks": "git-hooks", + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..1a06450 --- /dev/null +++ b/flake.nix @@ -0,0 +1,14 @@ +{ + inputs.nixpkgs.url = "github:nixos/nixpkgs/nixos-24.11"; + inputs.git-hooks.url = "github:cachix/git-hooks.nix"; + inputs.git-hooks.inputs.nixpkgs.follows = "nixpkgs"; + outputs = inputs: let + inherit (import nix/boilerplate.nix inputs) call genPkgs; + in { + # overlays = import nix/overlays.nix; + packages = call (import nix/packages.nix); + checks = call (import nix/checks.nix); + devShells = call (import nix/shells.nix); + formatter = genPkgs (p: p.alejandra); + }; +} diff --git a/lyt/Cargo.toml b/lyt/Cargo.toml new file mode 100644 index 0000000..5246ad8 --- /dev/null +++ b/lyt/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "lyt" +version = "0.1.0" +edition = "2021" + +[dependencies] diff --git a/lyt/src/main.rs b/lyt/src/main.rs new file mode 100644 index 0000000..e7a11a9 --- /dev/null +++ b/lyt/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + println!("Hello, world!"); +} diff --git a/nix/boilerplate.nix b/nix/boilerplate.nix new file mode 100644 index 0000000..9c03126 --- /dev/null +++ b/nix/boilerplate.nix @@ -0,0 +1,17 @@ +inputs @ { + nixpkgs, + self, + ... +}: let + forSelfOverlay = + if builtins.hasAttr "overlays" self && builtins.hasAttr "forSelf" self.overlays + then self.overlays.forSelf + else (_: p: p); +in rec { + # TODO: Iterate all Nix's supported systems? + systems = ["aarch64-linux" "x86_64-linux" "x86_64-darwin" "aarch64-darwin"]; + forSystems = nixpkgs.lib.genAttrs systems; + pkgsFor = system: ((import nixpkgs {inherit system;}).extend forSelfOverlay); + genPkgs = func: (forSystems (system: func (pkgsFor system))); + call = imported: genPkgs (pkgs: imported (inputs // {inherit pkgs;})); +} diff --git a/nix/checks.nix b/nix/checks.nix new file mode 100644 index 0000000..6d6b07b --- /dev/null +++ b/nix/checks.nix @@ -0,0 +1,25 @@ +{ + pkgs, + git-hooks, + ... +}: { + git-hooks = git-hooks.lib.${pkgs.system}.run { + src = ./..; + hooks = { + alejandra.enable = true; + cargo-check.enable = true; + convco.enable = true; + cargo-test = { + enable = true; + name = "cargo-test"; + entry = "cargo test"; + # types = ["rust"]; + # language = "rust"; + pass_filenames = false; + stages = ["pre-commit"]; + }; + clippy.enable = true; + rustfmt.enable = true; + }; + }; +} diff --git a/nix/packages.nix b/nix/packages.nix new file mode 100644 index 0000000..87118cf --- /dev/null +++ b/nix/packages.nix @@ -0,0 +1,14 @@ +{pkgs, ...}: let + inherit (builtins) fromTOML readFile; + pname = "lyt"; + src = ./..; + main-package = pkgs.rustPlatform.buildRustPackage { + inherit pname src; + version = (fromTOML (readFile "${src}/${pname}/Cargo.toml")).package.version; + cargoHash = "sha256-ZrT35F8EoawLgJVcp15kBLGkQZkhi1dxkYEAsV1ZlaU="; + useFetchCargoVendor = true; + }; +in { + ${pname} = main-package; + default = main-package; +} diff --git a/nix/shells.nix b/nix/shells.nix new file mode 100644 index 0000000..7e4499c --- /dev/null +++ b/nix/shells.nix @@ -0,0 +1,21 @@ +{ + self, + pkgs, + ... +}: let + inherit (pkgs) system; +in { + default = pkgs.mkShell { + inherit (self.checks.${system}.git-hooks) shellHook; + inputsFrom = [self.packages.${system}.default]; + packages = with pkgs; [ + convco + rustPackages.clippy + typescript-language-server + rust-analyzer + rustfmt + nixd + lldb + ]; + }; +}