Skip to content

Commit

Permalink
Add nix support (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
joaosreis authored Oct 2, 2024
1 parent d514feb commit 8d19c46
Show file tree
Hide file tree
Showing 7 changed files with 296 additions and 2 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,7 @@ archive
src/graphql/generated.rs
sql_scripts
target

# direnv
.envrc
.direnv
8 changes: 6 additions & 2 deletions cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
198 changes: 198 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 30 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -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));

};
}
21 changes: 21 additions & 0 deletions nix/modules/devshell.nix
Original file line number Diff line number Diff line change
@@ -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
];
};
};
}
17 changes: 17 additions & 0 deletions nix/modules/formatting.nix
Original file line number Diff line number Diff line change
@@ -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;
};
};
};
}
20 changes: 20 additions & 0 deletions nix/modules/rust.nix
Original file line number Diff line number Diff line change
@@ -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;
};
}

0 comments on commit 8d19c46

Please sign in to comment.