Skip to content

Commit

Permalink
feat: dynamic structure for templates in flake.nix
Browse files Browse the repository at this point in the history
  • Loading branch information
Swarsel committed Dec 31, 2024
1 parent efd667c commit f4f98b2
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 59 deletions.
126 changes: 76 additions & 50 deletions SwarselSystems.org
Original file line number Diff line number Diff line change
Expand Up @@ -171,55 +171,6 @@ In =outputs = inputs@ [...]=, the =inputs@= makes it so that all inputs are auto
};
}
#+end_src
** Pre-commit-hooks (Checks)
:PROPERTIES:
:CUSTOM_ID: h:cbd5002c-e0fa-434a-951b-e05b179e4e3f
:END:

This file defines a number of checks that can either be run by calling =nix flake check= or while in a =nix-shell= or =nix develop=. This helps me make sure that my flake confirms to my self-imposed standards. The GitHub actions perform less checks than are being done here (they are only checking the formatting, as well as =statix= and =deadnix=)

#+begin_src nix :tangle checks/default.nix
{ self, inputs, pkgs, system, ... }:
{
pre-commit-check = inputs.pre-commit-hooks.lib.${system}.run {
src = "${self}";
hooks = {
check-added-large-files.enable = true;
check-case-conflicts.enable = true;
check-executables-have-shebangs.enable = true;
check-shebang-scripts-are-executable.enable = false;
check-merge-conflicts.enable = true;
deadnix.enable = true;
detect-private-keys.enable = true;
end-of-file-fixer.enable = true;
fix-byte-order-marker.enable = true;
flake-checker.enable = true;
forbid-new-submodules.enable = true;
mixed-line-endings.enable = true;
nixpkgs-fmt.enable = true;
statix.enable = true;
trim-trailing-whitespace.enable = true;

destroyed-symlinks = {
enable = true;
entry = "${inputs.pre-commit-hooks.checks.${system}.pre-commit-hooks}/bin/destroyed-symlinks";
};

shellcheck = {
enable = true;
entry = "${pkgs.shellcheck}/bin/shellcheck --shell=bash";
};

shfmt = {
enable = true;
entry = "${pkgs.shfmt}/bin/shfmt -i 4 -sr -d -s -l";
};

};
};
}
#+end_src

** Inputs
:PROPERTIES:
:CUSTOM_ID: h:8a411ee2-a58e-4b5b-99bd-4ba772f8f0a2
Expand Down Expand Up @@ -464,7 +415,7 @@ In this section I am creating some attributes that define general concepts of my
}
);

templates = import ./templates;
templates = import ./templates { inherit lib; };

checks = lib.swarselsystems.forAllSystems (system:
let
Expand All @@ -475,6 +426,72 @@ In this section I am creating some attributes that define general concepts of my

#+end_src

** Pre-commit-hooks (Checks)
:PROPERTIES:
:CUSTOM_ID: h:cbd5002c-e0fa-434a-951b-e05b179e4e3f
:END:

This file defines a number of checks that can either be run by calling =nix flake check= or while in a =nix-shell= or =nix develop=. This helps me make sure that my flake confirms to my self-imposed standards. The GitHub actions perform less checks than are being done here (they are only checking the formatting, as well as =statix= and =deadnix=)

#+begin_src nix :tangle checks/default.nix
{ self, inputs, pkgs, system, ... }:
{
pre-commit-check = inputs.pre-commit-hooks.lib.${system}.run {
src = "${self}";
hooks = {
check-added-large-files.enable = true;
check-case-conflicts.enable = true;
check-executables-have-shebangs.enable = true;
check-shebang-scripts-are-executable.enable = false;
check-merge-conflicts.enable = true;
deadnix.enable = true;
detect-private-keys.enable = true;
end-of-file-fixer.enable = true;
fix-byte-order-marker.enable = true;
flake-checker.enable = true;
forbid-new-submodules.enable = true;
mixed-line-endings.enable = true;
nixpkgs-fmt.enable = true;
statix.enable = true;
trim-trailing-whitespace.enable = true;

destroyed-symlinks = {
enable = true;
entry = "${inputs.pre-commit-hooks.checks.${system}.pre-commit-hooks}/bin/destroyed-symlinks";
};

shellcheck = {
enable = true;
entry = "${pkgs.shellcheck}/bin/shellcheck --shell=bash";
};

shfmt = {
enable = true;
entry = "${pkgs.shfmt}/bin/shfmt -i 4 -sr -d -s -l";
};

};
};
}
#+end_src

** Templates

This file defines the templates that are being exposed by the flake. These can be used by running =nix flake init -t github:Swarsel/.dotfiles#<TEMPLATE_NAME>=.


#+begin_src nix :tangle templates/default.nix
{ lib, ... }:
let
templateNames = [
"python"
"rust"
];
in
lib.swarselsystems.mkTemplates templateNames

#+end_src

** nixosConfigurations
:PROPERTIES:
:CUSTOM_ID: h:9c9b9e3b-8771-44fa-ba9e-5056ae809655
Expand Down Expand Up @@ -4391,6 +4408,15 @@ A breakdown of each function:
})
names);

mkTemplates = names: builtins.listToAttrs (map
(name: {
inherit name;
value = {
path = "${self}/templates/${name}";
description = "${name} project ";
};
}) names);

eachMonitor = _: monitor: {
inherit (monitor) name;
value = builtins.removeAttrs monitor [ "workspace" "name" "output" ];
Expand Down
2 changes: 1 addition & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@
}
);

templates = import ./templates;
templates = import ./templates { inherit lib; };

checks = lib.swarselsystems.forAllSystems (system:
let
Expand Down
10 changes: 10 additions & 0 deletions lib/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,16 @@
})
names);

mkTemplates = names: builtins.listToAttrs (map
(name: {
inherit name;
value = {
path = "${self}/templates/${name}";
description = "${name} project ";
};
})
names);

eachMonitor = _: monitor: {
inherit (monitor) name;
value = builtins.removeAttrs monitor [ "workspace" "name" "output" ];
Expand Down
16 changes: 8 additions & 8 deletions templates/default.nix
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
rec {
python = {
path = ./python;
description =
"Python Project";
};
default = python;
}
{ lib, ... }:
let
templateNames = [
"python"
"rust"
];
in
lib.swarselsystems.mkTemplates templateNames

0 comments on commit f4f98b2

Please sign in to comment.