Skip to content

Commit

Permalink
flake/dev: add a convenient devshell
Browse files Browse the repository at this point in the history
  • Loading branch information
GaetanLepage committed Mar 2, 2024
1 parent d149f46 commit 274293f
Show file tree
Hide file tree
Showing 5 changed files with 129 additions and 11 deletions.
2 changes: 1 addition & 1 deletion flake-modules/default.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{inputs, ...}: {
imports = [
./dev.nix
./dev
./helpers.nix
./lib.nix
./legacy-packages.nix
Expand Down
11 changes: 2 additions & 9 deletions flake-modules/dev.nix → flake-modules/dev/default.nix
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
{inputs, ...}: {
imports = [
inputs.pre-commit-hooks.flakeModule
./devshell.nix
];

perSystem = {
pkgs,
config,
...
}: {
devShells.default = pkgs.mkShellNoCC {
shellHook = config.pre-commit.installationScript;
};

perSystem = {pkgs, ...}: {
formatter = pkgs.alejandra;

pre-commit = {
Expand Down
66 changes: 66 additions & 0 deletions flake-modules/dev/devshell.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
{inputs, ...}: {
imports = [
inputs.devshell.flakeModule
];

perSystem = {
pkgs,
config,
system,
...
}: {
devshells.default = {
devshell.startup.pre-commit.text = config.pre-commit.installationScript;

commands = let
# Thanks to this, the user can choose to use `nix-output-monitor` (`nom`) instead of plain `nix`
nix = "$([ '$\{NIXVIM_NOM:-0}' = '1' ] && echo ${pkgs.lib.getExe pkgs.nom} || echo nix)";
in [
{
name = "checks";
help = "Run all nixvim checks";
command = "nix flake check";
}
{
name = "tests";
help = "Run nixvim tests";
command = ''
echo "=> Running nixvim tests for the '${system}' architecture..."
${nix} build .#checks.${system}.tests
'';
}
{
name = "format";
help = "Format the entire codebase";
command = "nix fmt";
}
{
name = "docs";
help = "Build nixvim documentation";
command = ''
echo "=> Building nixvim documentation..."
${nix} build .#docs
'';
}
{
name = "serve-docs";
help = "Build and serve documentation locally";
command = ''
echo -e "=> Building nixvim documentation...\n"
doc_derivation=$(${nix} build .#docs --no-link --print-out-paths)
echo -e "\n=> Documentation succesfully built ('$doc_derivation')"
port=8000
echo -e "\n=> Now open your browser and navigate to 'localhost:$port'\n"
${pkgs.lib.getExe pkgs.python3} -m http.server -d "$doc_derivation"/share/doc
'';
}
];
};
};
}
57 changes: 56 additions & 1 deletion flake.lock

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

4 changes: 4 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
url = "github:hercules-ci/flake-parts";
inputs.nixpkgs-lib.follows = "nixpkgs";
};
devshell = {
url = "github:numtide/devshell";
inputs.nixpkgs.follows = "nixpkgs";
};

flake-compat.url = "https://flakehub.com/f/edolstra/flake-compat/1.tar.gz";

Expand Down

0 comments on commit 274293f

Please sign in to comment.