Skip to content

Commit

Permalink
Merge pull request #12 from tsandrini/rfc_formatter
Browse files Browse the repository at this point in the history
refactor(formatting): switch to nixfmt-rfc-style
  • Loading branch information
tsandrini authored Mar 15, 2024
2 parents fa1babd + ec28835 commit 01923c1
Show file tree
Hide file tree
Showing 71 changed files with 1,019 additions and 918 deletions.
18 changes: 9 additions & 9 deletions flake.lock

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

206 changes: 108 additions & 98 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -30,118 +30,128 @@
];
};

outputs = inputs @ {flake-parts, ...}:
flake-parts.lib.mkFlake {inherit inputs;} {
imports = with inputs; [treefmt-nix.flakeModule devenv.flakeModule];
outputs =
inputs@{ flake-parts, ... }:
flake-parts.lib.mkFlake { inherit inputs; } {
imports = with inputs; [
treefmt-nix.flakeModule
devenv.flakeModule
];
systems = import inputs.systems;

flake = {
templates = let
welcomeText = ''
Hi! You've just created a fresh new flakes project using the
practical-flakes-template. You can start by looking around or
running the development environment either via direnv (`direnv allow`)
or `nix develop .#dev --impure`.
Furthermore don't forget to rename your project using
`rename-project . myAwesomeNewProject`
For more info refer to
https://github.com/tsandrini/practical-flakes-template/
'';
in {
default = inputs.self.templates.main;
main = {
inherit welcomeText;
path = ./templates/main;
description = "Highly opinionated nix flakes starter template that focuses on modularity.";
};
templates =
let
welcomeText = ''
Hi! You've just created a fresh new flakes project using the
practical-flakes-template. You can start by looking around or
running the development environment either via direnv (`direnv allow`)
or `nix develop .#dev --impure`.
Furthermore don't forget to rename your project using
`rename-project . myAwesomeNewProject`
For more info refer to
https://github.com/tsandrini/practical-flakes-template/
'';
in
{
default = inputs.self.templates.main;
main = {
inherit welcomeText;
path = ./templates/main;
description = "Highly opinionated nix flakes starter template that focuses on modularity.";
};

minimal = {
inherit welcomeText;
path = ./templates/minimal;
description = "Minimal version of the highly opiniated nix flakes starter template.";
};
minimal = {
inherit welcomeText;
path = ./templates/minimal;
description = "Minimal version of the highly opiniated nix flakes starter template.";
};

isolated = {
inherit welcomeText;
path = ./templates/isolated;
description = "Isolated (./nix) version of the highly opiniated nix flakes starter template.";
};
isolated = {
inherit welcomeText;
path = ./templates/isolated;
description = "Isolated (./nix) version of the highly opiniated nix flakes starter template.";
};

isolated-minimal = {
inherit welcomeText;
path = ./templates/isolated-minimal;
description = "Isolated (./nix) and minimal version of the highly opiniated nix flakes starter template.";
};
isolated-minimal = {
inherit welcomeText;
path = ./templates/isolated-minimal;
description = "Isolated (./nix) and minimal version of the highly opiniated nix flakes starter template.";
};

home = {
inherit welcomeText;
path = ./templates/home;
description = "Full version of the highly opiniated nix flakes starter template that includes prewired home-manager";
home = {
inherit welcomeText;
path = ./templates/home;
description = "Full version of the highly opiniated nix flakes starter template that includes prewired home-manager";
};
};
};
};

perSystem = {
config,
pkgs,
...
}: {
treefmt = {
package = pkgs.treefmt;
flakeCheck = true;
flakeFormatter = true;
projectRootFile = ./flake.nix;
programs = {
alejandra.enable = true;
deadnix.enable = true;
statix.enable = true;
prettier.enable = true;
perSystem =
{ config, pkgs, ... }:
{
treefmt = {
package = pkgs.treefmt;
flakeCheck = true;
flakeFormatter = true;
projectRootFile = ./flake.nix;
programs = {
deadnix.enable = true;
statix.enable = true;
prettier.enable = true;
nixfmt-rfc-style.enable = true;
# NOTE Choose a different formatter if you'd like to
# nixfmt.enable = true;
# alejandra.enable = true;
};
};
};

devenv.shells.dev = {
packages = with pkgs; [
# -- NIX UTILS --
nil # Yet another language server for Nix
alejandra # The Uncompromising Nix Code Formatter
statix # Lints and suggestions for the nix programming language
deadnix # Find and remove unused code in .nix source files
nix-output-monitor # Processes output of Nix commands to show helpful and pretty information

# -- GIT RELATED UTILS --
commitizen # Tool to create committing rules for projects, auto bump versions, and generate changelogs
cz-cli # The commitizen command line utility
fh # The official FlakeHub CLI
gh # GitHub CLI tool

# -- LANGUAGE RELATED UTILS --
markdownlint-cli # Command line interface for MarkdownLint
nodePackages.prettier # Prettier is an opinionated code formatter
typos # Source code spell checker
config.treefmt.build.wrapper # one CLI to format the code tree
];

languages.nix.enable = true;
difftastic.enable = true;
devcontainer.enable = true; #
devenv.flakesIntegration = true;

pre-commit = {
hooks = {
treefmt.enable = true;

commitizen.enable = true;
markdownlint.enable = true;
typos.enable = true;
actionlint.enable = true;
};
settings = {
treefmt.package = config.treefmt.build.wrapper;
devenv.shells.dev = {
packages = with pkgs; [
# -- NIX UTILS --
nil # Yet another language server for Nix
statix # Lints and suggestions for the nix programming language
deadnix # Find and remove unused code in .nix source files
nix-output-monitor # Processes output of Nix commands to show helpful and pretty information
nixfmt-rfc-style # An opinionated formatter for Nix
# NOTE Choose a different formatter if you'd like to
# nixfmt # An opinionated formatter for Nix
# alejandra # The Uncompromising Nix Code Formatter

# -- GIT RELATED UTILS --
commitizen # Tool to create committing rules for projects, auto bump versions, and generate changelogs
cz-cli # The commitizen command line utility
fh # The official FlakeHub CLI
gh # GitHub CLI tool

# -- LANGUAGE RELATED UTILS --
markdownlint-cli # Command line interface for MarkdownLint
nodePackages.prettier # Prettier is an opinionated code formatter
typos # Source code spell checker
config.treefmt.build.wrapper # one CLI to format the code tree
];

languages.nix.enable = true;
difftastic.enable = true;
devcontainer.enable = true;
devenv.flakesIntegration = true;

pre-commit = {
hooks = {
treefmt.enable = true;

commitizen.enable = true;
markdownlint.enable = true;
typos.enable = true;
actionlint.enable = true;
};
settings = {
treefmt.package = config.treefmt.build.wrapper;
};
};
};
};
};
};
}
46 changes: 26 additions & 20 deletions templates/home/flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -39,29 +39,35 @@
];
};

outputs = inputs @ {flake-parts, ...}: let
inherit (inputs) nixpkgs;
inherit (lib.practicalFlakes) mapModules flatten;
outputs =
inputs@{ flake-parts, ... }:
let
inherit (inputs) nixpkgs;
inherit (lib.practicalFlakes) mapModules flatten;

# You should ideally use relative paths in each individual part from ./parts,
# however, if needed you can use the `projectPath` variable that is passed
# to every flakeModule to properly anchor your absolute paths.
projectPath = ./.;
# You should ideally use relative paths in each individual part from ./parts,
# however, if needed you can use the `projectPath` variable that is passed
# to every flakeModule to properly anchor your absolute paths.
projectPath = ./.;

# We extend the base <nixpkgs> library with our own custom helpers as well
# as override any of the nixpkgs default functions that we'd like
# to override. This instance is then passed to every part in ./parts so that
# you can use it in your custom modules
lib = nixpkgs.lib.extend (self: _super: {
practicalFlakes = import ./lib {
inherit inputs projectPath;
pkgs = nixpkgs;
lib = self;
# We extend the base <nixpkgs> library with our own custom helpers as well
# as override any of the nixpkgs default functions that we'd like
# to override. This instance is then passed to every part in ./parts so that
# you can use it in your custom modules
lib = nixpkgs.lib.extend (
self: _super: {
practicalFlakes = import ./lib {
inherit inputs projectPath;
pkgs = nixpkgs;
lib = self;
};
}
);
specialArgs = {
inherit lib projectPath;
};
});
specialArgs = {inherit lib projectPath;};
in
flake-parts.lib.mkFlake {inherit inputs specialArgs;} {
in
flake-parts.lib.mkFlake { inherit inputs specialArgs; } {
# We recursively traverse all of the flakeModules in ./parts and import only
# the final modules, meaning that you can have an arbitrary nested structure
# that suffices your needs. For example
Expand Down
37 changes: 22 additions & 15 deletions templates/home/lib/_bootstrap-lib.nix
Original file line number Diff line number Diff line change
@@ -1,23 +1,30 @@
# --- lib/_bootstrap-lib.nix
{lib, ...}:
{ lib, ... }:
with lib;
with builtins; rec {
with builtins;
rec {
# This file should provide the bare minimum to bootstrap the lib, namely the
# mapModules' function to enable properly loading the library files and its
# functions

mapFilterAttrs' = pred: f: attrs: filterAttrs pred (mapAttrs' f attrs);
mapFilterAttrs' =
pred: f: attrs:
filterAttrs pred (mapAttrs' f attrs);

mapModules' = dir: fn:
mapFilterAttrs'
(n: v: v != null && !(hasPrefix "_" n) && !(hasPrefix ".git" n)) (n: v: let
path = "${toString dir}/${n}";
in
if v == "directory" && pathExists "${path}/default.nix"
then nameValuePair n (fn path)
else if v == "directory"
then nameValuePair n (mapModules' path fn)
else if v == "regular" && n != "default.nix" && hasSuffix ".nix" n
then nameValuePair (removeSuffix ".nix" n) (fn path)
else nameValuePair "" null) (readDir dir);
mapModules' =
dir: fn:
mapFilterAttrs' (n: v: v != null && !(hasPrefix "_" n) && !(hasPrefix ".git" n)) (
n: v:
let
path = "${toString dir}/${n}";
in
if v == "directory" && pathExists "${path}/default.nix" then
nameValuePair n (fn path)
else if v == "directory" then
nameValuePair n (mapModules' path fn)
else if v == "regular" && n != "default.nix" && hasSuffix ".nix" n then
nameValuePair (removeSuffix ".nix" n) (fn path)
else
nameValuePair "" null
) (readDir dir);
}
Loading

0 comments on commit 01923c1

Please sign in to comment.