Skip to content

Commit

Permalink
refactor(nix): Split into modules
Browse files Browse the repository at this point in the history
  • Loading branch information
srid committed Sep 9, 2024
1 parent ba9d2d1 commit ee6b0c2
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 36 deletions.
41 changes: 5 additions & 36 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -16,43 +16,12 @@
outputs = inputs:
inputs.flake-parts.lib.mkFlake { inherit inputs; } {
systems = import inputs.systems;
imports = [
inputs.treefmt-nix.flakeModule
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."rust-nix-template".crane.args = {
buildInputs = lib.optionals pkgs.stdenv.isDarwin (
with pkgs.darwin.apple_sdk.frameworks; [
IOKit
]
);
};

# Add your auto-formatters here.
# cf. https://nixos.asia/en/treefmt
treefmt.config = {
projectRootFile = "flake.nix";
programs = {
nixpkgs-fmt.enable = true;
rustfmt.enable = true;
};
};
# See ./nix/modules/*.nix for the modules that are imported here.
imports = with builtins;
map
(fn: ./nix/modules/${fn})
(attrNames (readDir ./nix/modules));

devShells.default = pkgs.mkShell {
inputsFrom = [
self'.devShells.rust
config.treefmt.build.devShell
];
packages = [
pkgs.cargo-watch
config.process-compose.cargo-doc-live.outputs.package
];
};
packages.default = self'.packages.rust-nix-template;
};
};
}
15 changes: 15 additions & 0 deletions nix/modules/devshell.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{ inputs, ... }:
{
perSystem = { config, self', pkgs, lib, ... }: {
devShells.default = pkgs.mkShell {
inputsFrom = [
self'.devShells.rust
config.treefmt.build.devShell
];
packages = [
pkgs.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;
};
};
};
}
19 changes: 19 additions & 0 deletions nix/modules/rust.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{ 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."rust-nix-template".crane.args = {
buildInputs = lib.optionals pkgs.stdenv.isDarwin (
with pkgs.darwin.apple_sdk.frameworks; [
IOKit
]
);
};
packages.default = self'.packages.rust-nix-template;
};
}

0 comments on commit ee6b0c2

Please sign in to comment.