Skip to content

Commit

Permalink
chore(flake): switch to flake.parts module system
Browse files Browse the repository at this point in the history
  • Loading branch information
qlonik committed Jul 14, 2024
1 parent 361890d commit 3757810
Show file tree
Hide file tree
Showing 3 changed files with 115 additions and 92 deletions.
51 changes: 33 additions & 18 deletions flake.lock

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

149 changes: 80 additions & 69 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,77 +2,92 @@
description = "Development environment for prose";

outputs =
{
self,
nixpkgs,
systems,
treefmt-nix,
pre-commit-hooks,
}:
let
eachSystem = f: nixpkgs.lib.genAttrs (import systems) (system: f nixpkgs.legacyPackages.${system});
treefmtEval = eachSystem (pkgs: treefmt-nix.lib.evalModule pkgs ./treefmt.nix);
in
{
inputs@{ flake-parts, ... }:
flake-parts.lib.mkFlake { inherit inputs; } {
imports = [
inputs.treefmt-nix.flakeModule
inputs.pre-commit-hooks.flakeModule
];

packages.x86_64-linux.hello = nixpkgs.legacyPackages.x86_64-linux.hello;
systems = [
"x86_64-linux"
"aarch64-linux"
"x86_64-darwin"
"aarch64-darwin"
];

packages.x86_64-linux.default = self.packages.x86_64-linux.hello;
perSystem =
# Per-system attributes can be defined here. The self' and inputs'
# module parameters provide easy access to attributes of the same
# system. For description of all other function arguments, see
# `https://flake.parts/module-arguments#persystem-module-parameters`.
{
config,
self',
inputs',
pkgs,
system,
...
}:
{
packages.hello = pkgs.hello;
packages.default = self'.packages.hello;

devShells.x86_64-linux.default = nixpkgs.legacyPackages.x86_64-linux.mkShell {
devShells.default = pkgs.mkShell {
packages = with pkgs; [
curl
docker
envsubst
fluxcd
getopt
git
go
go-task
hostname
istioctl
jq
kubectl
minikube
neovim
nodejs
nodePackages.pnpm
nodePackages.prettier
open-policy-agent
protobuf_25
protoc-gen-go
protoc-gen-go-grpc
(python3.withPackages (ps: [
ps.matplotlib
ps.numpy
ps.srsly
]))
pipenv
ripgrep
vegeta
yq-go
zstd
];

packages = with nixpkgs.legacyPackages.x86_64-linux; [
curl
docker
envsubst
fluxcd
getopt
git
go
go-task
hostname
istioctl
jq
kubectl
minikube
neovim
nodejs
nodePackages.pnpm
nodePackages.prettier
open-policy-agent
protobuf_25
protoc-gen-go
protoc-gen-go-grpc
(python3.withPackages (ps: [
ps.matplotlib
ps.numpy
ps.srsly
]))
pipenv
ripgrep
vegeta
yq-go
zstd
];
buildInputs = config.pre-commit.settings.enabledPackages;

buildInputs = self.checks.x86_64-linux.pre-commit-check.enabledPackages;
shellHook = ''
${config.pre-commit.installationScript}
shellHook = ''
${self.checks.x86_64-linux.pre-commit-check.shellHook}
alias v='ls -alhF --color'
alias kc='kubectl'
'';
};
alias v='ls -alhF --color'
alias kc='kubectl'
'';
};

# for `nix fmt`
formatter = eachSystem (pkgs: treefmtEval.${pkgs.system}.config.build.wrapper);
# can use via `nix fmt`
treefmt = {
# Used to find the project root
projectRootFile = "flake.nix";
# pre-commit runs treefmt as a check, so we should not run it again
flakeCheck = false;
} // (import ./treefmt.nix { config = config.treefmt; });

# for `nix flake check`
checks = eachSystem (pkgs: {
pre-commit-check = pre-commit-hooks.lib.${pkgs.system}.run {
src = ./.;
hooks = {
# can use via `nix flake check`
pre-commit.settings.hooks = {
regenerate-pre-commit-config = {
enable = true;
name = "Regenerate `.pre-commit-config.yaml` file";
Expand All @@ -93,18 +108,14 @@
fail_fast = true;
always_run = true;
};

treefmt = {
enable = true;
package = pkgs.lib.mkBefore treefmtEval.${pkgs.system}.config.build.wrapper;
};
treefmt.enable = true;
};
};
});
};

inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
flake-parts.url = "github:hercules-ci/flake-parts";
treefmt-nix.url = "github:numtide/treefmt-nix";
treefmt-nix.inputs.nixpkgs.follows = "nixpkgs";
pre-commit-hooks.url = "github:cachix/pre-commit-hooks.nix";
Expand Down
7 changes: 2 additions & 5 deletions treefmt.nix
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
{ pkgs, options, ... }:
{ config }:
{
# Used to find the project root
projectRootFile = "flake.nix";

settings.global.excludes = [ ".archive/**" ];

programs.statix.enable = true;
Expand Down Expand Up @@ -42,7 +39,7 @@
programs.prettier.excludes = [
"pnpm-lock.yaml"
"charts/*/templates/*.yaml"
] ++ options.programs.biome.includes.default;
] ++ config.programs.biome.includes;

programs.shellcheck.enable = true;
programs.shfmt.enable = true;
Expand Down

0 comments on commit 3757810

Please sign in to comment.