Skip to content

Commit

Permalink
Use nixfmt as a sub formatter
Browse files Browse the repository at this point in the history
Partially import #520

Closes #520
  • Loading branch information
kachick committed Mar 25, 2024
1 parent fe97706 commit 79e3069
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 51 deletions.
3 changes: 2 additions & 1 deletion cmd/fmt/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ func main() {
cmds := runner.Commands{
{Path: "dprint", Args: []string{"fmt"}},
{Path: "shfmt", Args: append([]string{"--language-dialect", "bash", "--write"}, bashPaths...)},
{Path: "nixpkgs-fmt", Args: nixPaths},
// nix fmt doesn't respect .gitignore, without paths, .direnv included: https://github.com/NixOS/nixfmt/issues/151
{Path: "nix", Args: append([]string{"fmt"}, nixPaths...)},
{Path: "typos", Args: append(constants.GetTyposTargetedRoots(), "--write-changes")},
{Path: "go", Args: []string{"fmt", "./..."}},
}
Expand Down
1 change: 1 addition & 0 deletions cmd/lint/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ func main() {
{Path: "dprint", Args: []string{"check"}},
{Path: "shfmt", Args: append([]string{"--language-dialect", "bash", "--diff"}, bashPaths...)},
{Path: "shellcheck", Args: bashPaths},
// nix fmt doesn't have check option: https://github.com/NixOS/nix/issues/6918
{Path: "nixpkgs-fmt", Args: append([]string{"--check"}, nixPaths...)},
{Path: "typos", Args: constants.GetTyposTargetedRoots()},
{Path: "gitleaks", Args: []string{"detect"}},
Expand Down
97 changes: 48 additions & 49 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,25 @@
my-pkgs = my-nixpkgs.legacyPackages.${system};
in
rec {
# Q. Why nixpkgs-fmt? Not nixfmt? and alejandra?
# A. nixfmt will be official, but too opinionated and non stable now
# - https://github.com/NixOS/nixfmt/issues/153
# - https://github.com/NixOS/nixfmt/issues/129
# - https://github.com/NixOS/rfcs/pull/166
# - https://github.com/NixOS/nixfmt/blob/a81f922a2b362f347a6cbecff5fb14f3052bc25d/README.md#L19
formatter = pkgs.nixpkgs-fmt;
devShells.default = with pkgs;
mkShell {
buildInputs = [
# https://github.com/NixOS/nix/issues/730#issuecomment-162323824
bashInteractive
nixpkgs-fmt
nixfmt # Using a sub formatter
nil

dprint
shellcheck
shfmt
nil
nixpkgs-fmt
gitleaks
cargo-make
typos
Expand All @@ -47,57 +55,49 @@
];
};

packages.homeConfigurations =

This comment has been minimized.

Copy link
@kachick

kachick Mar 25, 2024

Author Owner

wrong commit

{
kachick = home-manager.lib.homeManagerConfiguration {
inherit pkgs;
modules = [
./home-manager/kachick.nix
];
extraSpecialArgs = {
inherit my-pkgs;
};
};
packages.homeConfigurations = {
kachick = home-manager.lib.homeManagerConfiguration {
inherit pkgs;
modules = [ ./home-manager/kachick.nix ];
extraSpecialArgs = { inherit my-pkgs; };
};

github-actions = home-manager.lib.homeManagerConfiguration {
inherit pkgs;
modules = [
# Prefer "kachick" over "common" only here.
# Using values as much as possible as actual values to create a robust CI
./home-manager/kachick.nix
{ home.username = "runner"; }
];
extraSpecialArgs = {
inherit my-pkgs;
};
};
github-actions = home-manager.lib.homeManagerConfiguration {
inherit pkgs;
modules = [
# Prefer "kachick" over "common" only here.
# Using values as much as possible as actual values to create a robust CI
./home-manager/kachick.nix
{ home.username = "runner"; }
];
extraSpecialArgs = { inherit my-pkgs; };
};

user = home-manager.lib.homeManagerConfiguration {
inherit pkgs;
modules = [
./home-manager/common.nix
{
# "user" is default in podman-machine-default
home.username = "user";
}
];
extraSpecialArgs = {
inherit my-pkgs;
};
};
user = home-manager.lib.homeManagerConfiguration {
inherit pkgs;
modules = [
./home-manager/common.nix
{
# "user" is default in podman-machine-default
home.username = "user";
}
];
extraSpecialArgs = { inherit my-pkgs; };
};
};

packages.bump_completions = pkgs.writeShellScriptBin "bump_completions" ''
set -euo pipefail
packages.bump_completions =
pkgs.writeShellScriptBin "bump_completions" ''
set -euo pipefail
${pkgs.podman}/bin/podman completion bash > ./dependencies/podman/completions.bash
${pkgs.podman}/bin/podman completion zsh > ./dependencies/podman/completions.zsh
${pkgs.podman}/bin/podman completion fish > ./dependencies/podman/completions.fish
${pkgs.podman}/bin/podman completion bash > ./dependencies/podman/completions.bash
${pkgs.podman}/bin/podman completion zsh > ./dependencies/podman/completions.zsh
${pkgs.podman}/bin/podman completion fish > ./dependencies/podman/completions.fish
${pkgs.dprint}/bin/dprint completions bash > ./dependencies/dprint/completions.bash
${pkgs.dprint}/bin/dprint completions zsh > ./dependencies/dprint/completions.zsh
${pkgs.dprint}/bin/dprint completions fish > ./dependencies/dprint/completions.fish
'';
${pkgs.dprint}/bin/dprint completions bash > ./dependencies/dprint/completions.bash
${pkgs.dprint}/bin/dprint completions zsh > ./dependencies/dprint/completions.zsh
${pkgs.dprint}/bin/dprint completions fish > ./dependencies/dprint/completions.fish
'';

apps = {
# example: `nix run .#home-manager -- switch -n -b backup --flake .#kachick`
Expand All @@ -111,7 +111,6 @@
program = "${packages.bump_completions}/bin/bump_completions";
};
};
}
);
});
}

2 changes: 1 addition & 1 deletion home-manager/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ nix-prefetch-git --url https://github.com/oh-my-fish/plugin-foreign-env.git --re
See [this comment](https://gist.github.com/Scoder12/0538252ed4b82d65e59115075369d34d?permalink_comment_id=4999658#gistcomment-4999658)

```bash
nix-instantiate --eval -E 'builtins.fromJSON (builtins.readFile ./test.json)'
nix-instantiate --eval -E 'builtins.fromJSON (builtins.readFile ./dprint.json)' | nixfmt
```

## How to make executable? `.text =` makes a sym, that links to non executable file
Expand Down

0 comments on commit 79e3069

Please sign in to comment.