From 8d19c46478cc21420f9666e89b8c878adef80ac9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Santos=20Reis?= Date: Wed, 2 Oct 2024 13:57:27 +0100 Subject: [PATCH] Add nix support (#31) --- .gitignore | 4 + cspell.json | 8 +- flake.lock | 198 +++++++++++++++++++++++++++++++++++++ flake.nix | 30 ++++++ nix/modules/devshell.nix | 21 ++++ nix/modules/formatting.nix | 17 ++++ nix/modules/rust.nix | 20 ++++ 7 files changed, 296 insertions(+), 2 deletions(-) create mode 100644 flake.lock create mode 100644 flake.nix create mode 100644 nix/modules/devshell.nix create mode 100644 nix/modules/formatting.nix create mode 100644 nix/modules/rust.nix diff --git a/.gitignore b/.gitignore index 83c3772..81c5288 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,7 @@ archive src/graphql/generated.rs sql_scripts target + +# direnv +.envrc +.direnv diff --git a/cspell.json b/cspell.json index 5909b12..2542756 100644 --- a/cspell.json +++ b/cspell.json @@ -16,7 +16,11 @@ "src/graphql/schema/mina_schema.graphql", "sql/**", "static/scalar.standalone.min.js", - "target/**" + "target/**", + "flake.*", + "nix/**", + ".gitignore" ], - "useGitignore": true + "useGitignore": true, + "enabled": true } diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..b77be47 --- /dev/null +++ b/flake.lock @@ -0,0 +1,198 @@ +{ + "nodes": { + "cargo-doc-live": { + "locked": { + "lastModified": 1724704668, + "narHash": "sha256-kJFYXlWUodg5WhJ0NuvrP0mCvOT/2AOIo8oGeYLXocs=", + "owner": "srid", + "repo": "cargo-doc-live", + "rev": "b09d5d258d2498829e03014931fc19aed499b86f", + "type": "github" + }, + "original": { + "owner": "srid", + "repo": "cargo-doc-live", + "type": "github" + } + }, + "crane": { + "inputs": { + "nixpkgs": [ + "rust-flake", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1718474113, + "narHash": "sha256-UKrfy/46YF2TRnxTtKCYzqf2f5ZPRRWwKCCJb7O5X8U=", + "owner": "ipetkov", + "repo": "crane", + "rev": "0095fd8ea00ae0a9e6014f39c375e40c2fbd3386", + "type": "github" + }, + "original": { + "owner": "ipetkov", + "repo": "crane", + "type": "github" + } + }, + "flake-parts": { + "inputs": { + "nixpkgs-lib": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1725234343, + "narHash": "sha256-+ebgonl3NbiKD2UD0x4BszCZQ6sTfL4xioaM49o5B3Y=", + "owner": "hercules-ci", + "repo": "flake-parts", + "rev": "567b938d64d4b4112ee253b9274472dc3a346eb6", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "flake-parts", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1725816686, + "narHash": "sha256-0Kq2MkQ/sQX1rhWJ/ySBBQlBJBUK8mPMDcuDhhdBkSU=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "add0443ee587a0c44f22793b8c8649a0dbc3bb00", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1725103162, + "narHash": "sha256-Ym04C5+qovuQDYL/rKWSR+WESseQBbNAe5DsXNx5trY=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "12228ff1752d7b7624a54e9c1af4b222b3c1073b", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "process-compose-flake": { + "locked": { + "lastModified": 1724606023, + "narHash": "sha256-rdGeNa/lCS8E1lXzPqgl+vZUUvnbEZT11Bqkx5jfYug=", + "owner": "Platonic-Systems", + "repo": "process-compose-flake", + "rev": "f6ce9481df9aec739e4e06b67492401a5bb4f0b1", + "type": "github" + }, + "original": { + "owner": "Platonic-Systems", + "repo": "process-compose-flake", + "type": "github" + } + }, + "root": { + "inputs": { + "cargo-doc-live": "cargo-doc-live", + "flake-parts": "flake-parts", + "nixpkgs": "nixpkgs", + "process-compose-flake": "process-compose-flake", + "rust-flake": "rust-flake", + "rust-overlay": "rust-overlay", + "systems": "systems", + "treefmt-nix": "treefmt-nix" + } + }, + "rust-flake": { + "inputs": { + "crane": "crane", + "nixpkgs": [ + "nixpkgs" + ], + "rust-overlay": [ + "rust-overlay" + ] + }, + "locked": { + "lastModified": 1725924735, + "narHash": "sha256-pMrezXpLk6WPhHKJmFekoga6rQZPgfpwYABbJtMESEY=", + "owner": "juspay", + "repo": "rust-flake", + "rev": "c5c73ff9f4daa7dcc22b8089ea2a57420db60016", + "type": "github" + }, + "original": { + "owner": "juspay", + "repo": "rust-flake", + "type": "github" + } + }, + "rust-overlay": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1727836133, + "narHash": "sha256-JE0zciM5IGWvK8J/pE2VldNBf7oyMH5WrU8tZArefbg=", + "owner": "oxalica", + "repo": "rust-overlay", + "rev": "02321540b0c8000b36889b1b974d1fec585b25a4", + "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" + } + }, + "treefmt-nix": { + "inputs": { + "nixpkgs": "nixpkgs_2" + }, + "locked": { + "lastModified": 1725271838, + "narHash": "sha256-VcqxWT0O/gMaeWTTjf1r4MOyG49NaNxW4GHTO3xuThE=", + "owner": "numtide", + "repo": "treefmt-nix", + "rev": "9fb342d14b69aefdf46187f6bb80a4a0d97007cd", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "treefmt-nix", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..f6f4a80 --- /dev/null +++ b/flake.nix @@ -0,0 +1,30 @@ +{ + inputs = { + nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable"; + flake-parts.url = "github:hercules-ci/flake-parts"; + flake-parts.inputs.nixpkgs-lib.follows = "nixpkgs"; + systems.url = "github:nix-systems/default"; + rust-overlay.url = "github:oxalica/rust-overlay"; + rust-overlay.inputs.nixpkgs.follows = "nixpkgs"; + rust-flake.url = "github:juspay/rust-flake"; + rust-flake.inputs.nixpkgs.follows = "nixpkgs"; + rust-flake.inputs.rust-overlay.follows = "rust-overlay"; + process-compose-flake.url = "github:Platonic-Systems/process-compose-flake"; + cargo-doc-live.url = "github:srid/cargo-doc-live"; + + # Dev tools + treefmt-nix.url = "github:numtide/treefmt-nix"; + }; + + outputs = inputs: + inputs.flake-parts.lib.mkFlake { inherit inputs; } { + systems = import inputs.systems; + + # See ./nix/modules/*.nix for the modules that are imported here. + imports = with builtins; + map + (fn: ./nix/modules/${fn}) + (attrNames (readDir ./nix/modules)); + + }; +} diff --git a/nix/modules/devshell.nix b/nix/modules/devshell.nix new file mode 100644 index 0000000..fcfbdc7 --- /dev/null +++ b/nix/modules/devshell.nix @@ -0,0 +1,21 @@ +{ inputs, ... }: +{ + perSystem = { config, self', pkgs, lib, ... }: { + devShells.default = pkgs.mkShell { + name = "rust-nix-mina_mesh-shell"; + inputsFrom = [ + self'.devShells.rust + config.treefmt.build.devShell + ]; + nativeBuildInputs = with pkgs; [ + sqlx-cli + ]; + packages = with pkgs; [ + nixd # Nix language server + nixfmt # Nix formatter + cargo-watch + config.process-compose.cargo-doc-live.outputs.package + ]; + }; + }; +} diff --git a/nix/modules/formatting.nix b/nix/modules/formatting.nix new file mode 100644 index 0000000..318cbae --- /dev/null +++ b/nix/modules/formatting.nix @@ -0,0 +1,17 @@ +{ inputs, ... }: +{ + imports = [ + inputs.treefmt-nix.flakeModule + ]; + perSystem = { config, self', pkgs, lib, ... }: { + # Add your auto-formatters here. + # cf. https://nixos.asia/en/treefmt + treefmt.config = { + projectRootFile = "flake.nix"; + programs = { + nixpkgs-fmt.enable = true; + rustfmt.enable = true; + }; + }; + }; +} diff --git a/nix/modules/rust.nix b/nix/modules/rust.nix new file mode 100644 index 0000000..d2abebc --- /dev/null +++ b/nix/modules/rust.nix @@ -0,0 +1,20 @@ +{ inputs, ... }: +{ + imports = [ + inputs.rust-flake.flakeModules.default + inputs.rust-flake.flakeModules.nixpkgs + inputs.process-compose-flake.flakeModule + inputs.cargo-doc-live.flakeModule + ]; + perSystem = { config, self', pkgs, lib, ... }: { + rust-project.crates."mina_mesh".crane.args = { + buildInputs = lib.optionals pkgs.stdenv.isDarwin ( + with pkgs.darwin.apple_sdk.frameworks; [ + IOKit + ] + ); + nativeBuildInputs = [ pkgs.openssl ]; + }; + packages.default = self'.packages.mina_mesh; + }; +}