diff --git a/.gitignore b/.gitignore index 29296fef..726d2d63 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,2 @@ result .direnv - - -# Added by cargo - -/target diff --git a/backend/.gitignore b/backend/.gitignore new file mode 100644 index 00000000..41d423bc --- /dev/null +++ b/backend/.gitignore @@ -0,0 +1,2 @@ +# Added by cargo +/target diff --git a/Cargo.lock b/backend/Cargo.lock similarity index 100% rename from Cargo.lock rename to backend/Cargo.lock diff --git a/Cargo.toml b/backend/Cargo.toml similarity index 100% rename from Cargo.toml rename to backend/Cargo.toml diff --git a/backend/default.nix b/backend/default.nix new file mode 100644 index 00000000..2a28878d --- /dev/null +++ b/backend/default.nix @@ -0,0 +1,27 @@ +{ + perSystem = { self', pkgs, lib, ... }: + let + src = lib.sourceFilesBySuffices ./. [ ".rs" ".toml" "Cargo.lock" ]; + inherit (lib.importTOML (src + "/Cargo.toml")) package; + in + { + packages = { + ${package.name} = pkgs.rustPlatform.buildRustPackage { + pname = package.name; + inherit (package) version; + inherit src; + cargoLock.lockFile = (src + "/Cargo.lock"); + }; + default = self'.packages.${package.name}; + }; + + devShells.backend = pkgs.mkShell { + inherit (package) name; + inputsFrom = [ self'.packages.${package.name} ]; + packages = with pkgs; [ + rust-analyzer + nil + ]; + }; + }; +} diff --git a/src/main.rs b/backend/src/main.rs similarity index 100% rename from src/main.rs rename to backend/src/main.rs diff --git a/flake.nix b/flake.nix index 17d73ece..76a28664 100644 --- a/flake.nix +++ b/flake.nix @@ -9,39 +9,24 @@ outputs = inputs: inputs.flake-parts.lib.mkFlake { inherit inputs; } { systems = import inputs.systems; - imports = [ inputs.treefmt-nix.flakeModule ]; + imports = [ + inputs.treefmt-nix.flakeModule + ./backend + ]; - perSystem = { self', pkgs, lib, ... }: - let - src = lib.sourceFilesBySuffices inputs.self [ ".rs" ".toml" "Cargo.lock" ]; - inherit (lib.importTOML (src + "/Cargo.toml")) package; - in - { - packages = { - ${package.name} = pkgs.rustPlatform.buildRustPackage { - pname = package.name; - inherit (package) version; - inherit src; - cargoLock.lockFile = (src + "/Cargo.lock"); - }; - default = self'.packages.${package.name}; - }; - - devShells.default = pkgs.mkShell { - inherit (package) name; - inputsFrom = [ self'.packages.${package.name} ]; - packages = with pkgs; [ - rust-analyzer - nil - ]; - }; + perSystem = { self', pkgs, lib, ... }: { + devShells.default = pkgs.mkShell { + inputsFrom = [ + self'.devShells.backend + ]; + }; - # Run `nix fmt` to format the source tree. - treefmt = { - projectRootFile = "flake.nix"; - programs.nixpkgs-fmt.enable = true; - programs.rustfmt.enable = true; - }; + # Run `nix fmt` to format the source tree. + treefmt = { + projectRootFile = "flake.nix"; + programs.nixpkgs-fmt.enable = true; + programs.rustfmt.enable = true; }; + }; }; }