From 24c5d44c4b0f225e9c74880fa73d400790ac3c92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Santos=20Reis?= Date: Tue, 17 Sep 2024 16:54:02 +0100 Subject: [PATCH 1/7] Add initial nix support --- .gitignore | 4 + Cargo.toml | 10 ++ flake.lock | 191 +++++++++++++++++++++++++++++++++++++ flake.nix | 27 ++++++ nix/modules/devshell.nix | 20 ++++ nix/modules/formatting.nix | 17 ++++ nix/modules/rust.nix | 20 ++++ nix/modules/template.nix | 8 ++ rust-toolchain.toml | 2 + 9 files changed, 299 insertions(+) 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 create mode 100644 nix/modules/template.nix create mode 100644 rust-toolchain.toml diff --git a/.gitignore b/.gitignore index 4d69c73..21e879b 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,7 @@ archive src/graphql/generated.rs target + +# direnv +.envrc +.direnv diff --git a/Cargo.toml b/Cargo.toml index ce52d2a..bfd6b2c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,6 +6,16 @@ edition = "2021" license = "Apache-2.0" description = "A Rust Server Implementation of the Mesh Spec for Mina" +[workspace] +members = [ + "./", + "./mesh_generated", +] +default-members = [ + "./", + "./mesh_generated", +] + [build-dependencies] anyhow = "1.0.86" cynic-codegen = "3.7.3" diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..a110bce --- /dev/null +++ b/flake.lock @@ -0,0 +1,191 @@ +{ + "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", + "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": { + "flake": false, + "locked": { + "lastModified": 1725243956, + "narHash": "sha256-0A5ZP8uDCyBdYUzayZfy6JFdTefP79oZVAjyqA/yuSI=", + "owner": "oxalica", + "repo": "rust-overlay", + "rev": "a10c8092d5f82622be79ed4dd12289f72011f850", + "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..6fff6f0 --- /dev/null +++ b/flake.nix @@ -0,0 +1,27 @@ +{ + 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-flake.url = "github:juspay/rust-flake"; + rust-flake.inputs.nixpkgs.follows = "nixpkgs"; + 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..fe5903c --- /dev/null +++ b/nix/modules/devshell.nix @@ -0,0 +1,20 @@ +{ 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 + 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; + }; +} diff --git a/nix/modules/template.nix b/nix/modules/template.nix new file mode 100644 index 0000000..23bae52 --- /dev/null +++ b/nix/modules/template.nix @@ -0,0 +1,8 @@ +{ inputs, ... }: + +{ + flake.templates.default = { + description = "A batteries-included Rust project template for Nix"; + path = builtins.path { path = inputs.self; }; + }; +} diff --git a/rust-toolchain.toml b/rust-toolchain.toml new file mode 100644 index 0000000..292fe49 --- /dev/null +++ b/rust-toolchain.toml @@ -0,0 +1,2 @@ +[toolchain] +channel = "stable" From 6e24262a1cda0580b906316ea5e9a3d6abdbc6cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Santos=20Reis?= Date: Wed, 2 Oct 2024 12:33:13 +0100 Subject: [PATCH 2/7] Add nixfmt to devshell.nix --- nix/modules/devshell.nix | 1 + 1 file changed, 1 insertion(+) diff --git a/nix/modules/devshell.nix b/nix/modules/devshell.nix index fe5903c..fcfbdc7 100644 --- a/nix/modules/devshell.nix +++ b/nix/modules/devshell.nix @@ -12,6 +12,7 @@ ]; packages = with pkgs; [ nixd # Nix language server + nixfmt # Nix formatter cargo-watch config.process-compose.cargo-doc-live.outputs.package ]; From f789d4bf081f5f443dc09e79e99f2b7ae3cbdf2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Santos=20Reis?= Date: Wed, 2 Oct 2024 12:33:31 +0100 Subject: [PATCH 3/7] Add rust-overlay to flake.lock and flake.nix --- flake.lock | 17 ++++++++++++----- flake.nix | 3 +++ 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/flake.lock b/flake.lock index a110bce..b77be47 100644 --- a/flake.lock +++ b/flake.lock @@ -110,6 +110,7 @@ "nixpkgs": "nixpkgs", "process-compose-flake": "process-compose-flake", "rust-flake": "rust-flake", + "rust-overlay": "rust-overlay", "systems": "systems", "treefmt-nix": "treefmt-nix" } @@ -120,7 +121,9 @@ "nixpkgs": [ "nixpkgs" ], - "rust-overlay": "rust-overlay" + "rust-overlay": [ + "rust-overlay" + ] }, "locked": { "lastModified": 1725924735, @@ -137,13 +140,17 @@ } }, "rust-overlay": { - "flake": false, + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, "locked": { - "lastModified": 1725243956, - "narHash": "sha256-0A5ZP8uDCyBdYUzayZfy6JFdTefP79oZVAjyqA/yuSI=", + "lastModified": 1727836133, + "narHash": "sha256-JE0zciM5IGWvK8J/pE2VldNBf7oyMH5WrU8tZArefbg=", "owner": "oxalica", "repo": "rust-overlay", - "rev": "a10c8092d5f82622be79ed4dd12289f72011f850", + "rev": "02321540b0c8000b36889b1b974d1fec585b25a4", "type": "github" }, "original": { diff --git a/flake.nix b/flake.nix index 6fff6f0..f6f4a80 100644 --- a/flake.nix +++ b/flake.nix @@ -4,8 +4,11 @@ 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"; From 19a085a28de2683cbae772a52c231da6f0d2d0b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Santos=20Reis?= Date: Wed, 2 Oct 2024 12:37:11 +0100 Subject: [PATCH 4/7] Refactor workspace configuration in Cargo.toml --- Cargo.toml | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 5a3c13b..1c4834d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,16 +6,6 @@ edition = "2021" license = "Apache-2.0" description = "A Rust Server Implementation of the Mesh Spec for Mina" -[workspace] -members = [ - "./", - "./mesh_generated", -] -default-members = [ - "./", - "./mesh_generated", -] - [build-dependencies] anyhow = "1.0.86" cynic-codegen = "3.7.3" From 866bd7ba1957fcd6a8c27c57fe6aab1ca36b55ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Santos=20Reis?= Date: Wed, 2 Oct 2024 12:37:15 +0100 Subject: [PATCH 5/7] Remove unused template.nix file --- nix/modules/template.nix | 8 -------- 1 file changed, 8 deletions(-) delete mode 100644 nix/modules/template.nix diff --git a/nix/modules/template.nix b/nix/modules/template.nix deleted file mode 100644 index 23bae52..0000000 --- a/nix/modules/template.nix +++ /dev/null @@ -1,8 +0,0 @@ -{ inputs, ... }: - -{ - flake.templates.default = { - description = "A batteries-included Rust project template for Nix"; - path = builtins.path { path = inputs.self; }; - }; -} From 4a31b0a39346a4fa19c19117e2bb28dbe95caee7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Santos=20Reis?= Date: Wed, 2 Oct 2024 12:49:23 +0100 Subject: [PATCH 6/7] Update cspell.json to include flake.* and nix/** in the list of ignored files --- cspell.json | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/cspell.json b/cspell.json index 5909b12..390723c 100644 --- a/cspell.json +++ b/cspell.json @@ -16,7 +16,10 @@ "src/graphql/schema/mina_schema.graphql", "sql/**", "static/scalar.standalone.min.js", - "target/**" + "target/**", + "flake.*", + "nix/**" ], - "useGitignore": true + "useGitignore": true, + "enabled": true } From b04cf76484057254c6494ac02399e40198cf319c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Santos=20Reis?= Date: Wed, 2 Oct 2024 12:54:14 +0100 Subject: [PATCH 7/7] Update cspell.json to include .gitignore in the list of ignored files --- cspell.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cspell.json b/cspell.json index 390723c..2542756 100644 --- a/cspell.json +++ b/cspell.json @@ -18,7 +18,8 @@ "static/scalar.standalone.min.js", "target/**", "flake.*", - "nix/**" + "nix/**", + ".gitignore" ], "useGitignore": true, "enabled": true