Skip to content

Commit

Permalink
Merge pull request #94 from akirak/nixfmt-rfc-style
Browse files Browse the repository at this point in the history
Reformat the code with nixfmt-rfc-style
  • Loading branch information
akirak authored Jul 27, 2024
2 parents ba8a16d + ae977c4 commit 94c3d5b
Show file tree
Hide file tree
Showing 16 changed files with 550 additions and 598 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: Lint via pre-commit-hooks

name: Format check and linting
on:
pull_request:
workflow_dispatch:
Expand Down
126 changes: 28 additions & 98 deletions dev/flake.lock

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

63 changes: 32 additions & 31 deletions dev/flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,42 @@
inputs = {
# nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
systems.url = "github:nix-systems/default";
pre-commit-hooks.url = "github:cachix/git-hooks.nix";
treefmt-nix = {
url = "github:numtide/treefmt-nix";
inputs.nixpkgs.follows = "nixpkgs";
};
# To be overridden during execution
src.url = "github:akirak/flake-templates";
};

outputs = {
self,
systems,
nixpkgs,
pre-commit-hooks,
...
} @ inputs: let
eachSystem = nixpkgs.lib.genAttrs (import systems);
in {
packages = eachSystem (system: {
update-beam = nixpkgs.legacyPackages.${system}.callPackage ./update-beam.nix {};
});
outputs =
{
self,
systems,
nixpkgs,
treefmt-nix,
...
}@inputs:
let
eachSystem = f: nixpkgs.lib.genAttrs (import systems) (system: f nixpkgs.legacyPackages.${system});

checks = eachSystem (system: {
pre-commit-check = pre-commit-hooks.lib.${system}.run {
src = inputs.src.outPath;
hooks = {
actionlint.enable = true;
alejandra.enable = true;
markdownlint.enable = true;
};
};
});
treefmtEval = eachSystem (
pkgs:
treefmt-nix.lib.evalModule pkgs {
projectRootFile = "flake.nix";
programs.nixfmt-rfc-style.enable = true;
}
);
in
{
packages = eachSystem (pkgs: {
update-beam = nixpkgs.legacyPackages.${pkgs.system}.callPackage ./update-beam.nix { };
});

devShells = eachSystem (system: let
pkgs = nixpkgs.legacyPackages.${system};
in {
default = pkgs.mkShell {
inherit (self.checks.${system}.pre-commit-check) shellHook;
};
});
};
formatter = eachSystem (pkgs: treefmtEval.${pkgs.system}.config.build.wrapper);

checks = eachSystem (pkgs: {
formatting = treefmtEval.${pkgs.system}.config.build.check self;
});
};
}
49 changes: 30 additions & 19 deletions dev/update-beam.nix
Original file line number Diff line number Diff line change
@@ -1,22 +1,33 @@
/*
This script helps the user keep Erlang (erlangRxx) and Elixir (elixir_x_xx)
to their latest versions. It performs simple regexp substitutions in flake.nix.
This script helps the user keep Erlang (erlangRxx) and Elixir (elixir_x_xx)
to their latest versions. It performs simple regexp substitutions in flake.nix.
*/
{
lib,
beam,
writeText,
writeShellScript,
}: let
inherit (builtins) attrNames filter match sort head compareVersions;
}:
let
inherit (builtins)
attrNames
filter
match
sort
head
compareVersions
;

latestPackageMatching = pattern: attrs:
latestPackageMatching =
pattern: attrs:
lib.pipe attrs [
(lib.filterAttrs (name: _: match pattern name != null))
(lib.mapAttrsToList (name: value: {
inherit name;
inherit (value) version;
}))
(lib.mapAttrsToList (
name: value: {
inherit name;
inherit (value) version;
}
))
(sort (a: b: compareVersions a.version b.version > 0))
(elems: builtins.elemAt elems 1)
(x: x.name)
Expand All @@ -35,14 +46,14 @@ to their latest versions. It performs simple regexp substitutions in flake.nix.
s/${elixirRegex}/${latestElixir}/
'';
in
writeShellScript "update-beam" ''
git add .
find -name flake.nix | xargs sed -i -r -f ${sed}
writeShellScript "update-beam" ''
git add .
find -name flake.nix | xargs sed -i -r -f ${sed}
if git diff --exit-code
then
exit 1
else
git add .
fi
''
if git diff --exit-code
then
exit 1
else
git add .
fi
''
Loading

0 comments on commit 94c3d5b

Please sign in to comment.