Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace nixpkgs-fmt with nixfmt #520

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"nix.enableLanguageServer": true,
"nix.serverSettings": {
"nil": {
"formatting": { "command": ["nixpkgs-fmt"] }
"formatting": { "command": ["nixfmt"] }
}
},
"gopls": {
Expand Down
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
3 changes: 2 additions & 1 deletion cmd/lint/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ func main() {
{Path: "dprint", Args: []string{"check"}},
{Path: "shfmt", Args: append([]string{"--language-dialect", "bash", "--diff"}, bashPaths...)},
{Path: "shellcheck", Args: bashPaths},
{Path: "nixpkgs-fmt", Args: append([]string{"--check"}, nixPaths...)},
// nix fmt doesn't have check option: https://github.com/NixOS/nix/issues/6918
{Path: "nixfmt", Args: append([]string{"--check"}, nixPaths...)},
{Path: "typos", Args: constants.GetTyposTargetedRoots()},
{Path: "gitleaks", Args: []string{"detect"}},
{Path: "go", Args: []string{"vet", "./..."}},
Expand Down
98 changes: 47 additions & 51 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,24 @@
let
pkgs = nixpkgs.legacyPackages.${system};
my-pkgs = my-nixpkgs.legacyPackages.${system};
in
rec {
in rec {
# Q. Why nixfmt? Not nixpkgs-fmt and alejandra?
# A. nixfmt will be official
# - https://github.com/NixOS/nixfmt/issues/153
# - https://github.com/NixOS/nixfmt/issues/129
# - https://github.com/NixOS/rfcs/pull/166
formatter = pkgs.nixfmt;
devShells.default = with pkgs;
mkShell {
buildInputs = [
# https://github.com/NixOS/nix/issues/730#issuecomment-162323824
bashInteractive
nixfmt
nil

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

packages.homeConfigurations =
{
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 +108,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
21 changes: 18 additions & 3 deletions home-manager/bash.nix
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,28 @@
shellAliases = {
# git alias cannot get the interactive feature, so aliasing in shell layer
# https://unix.stackexchange.com/questions/212872/how-to-get-last-n-commands-from-history#comment1125605_212873
glc = "git commit -a -m \"\\`$(fc -ln -1 | grep -Po '(\\S.*)')\\`\"";
glc = ''git commit -a -m "\`$(fc -ln -1 | grep -Po '(\S.*)')\`"'';
};

historySize = 100000;
historyFile = "${config.xdg.stateHome}/bash/history";
historyFileSize = 4200000;
historyControl = [ "erasedups" "ignoredups" "ignorespace" ];
# NOTE: I didn't check it should have different globs as zsh or not, at least the sepelator is not same.
historyIgnore = [ "cd" "pushd" "popd" "z" "ls" "ll" "la" "rm" "rmdir" "git show" "exit" "glc" ];
historyIgnore = [
"cd"
"pushd"
"popd"
"z"
"ls"
"ll"
"la"
"rm"
"rmdir"
"git show"
"exit"
"glc"
];

# Switch to another shell when bash used as a login shell
profileExtra = ''
Expand All @@ -94,7 +107,9 @@
initExtra = ''
# https://github.com/starship/starship/blob/0d98c4c0b7999f5a8bd6e7db68fd27b0696b3bef/docs/uk-UA/advanced-config/README.md#change-window-title
function set_win_title() {
echo -ne "\033]0; $(${lib.getBin pkgs.coreutils}/bin/basename "$PWD") \007"
echo -ne "\033]0; $(${
lib.getBin pkgs.coreutils
}/bin/basename "$PWD") \007"
}
# shellcheck disable=SC2034
starship_precmd_user_func="set_win_title"
Expand Down
83 changes: 39 additions & 44 deletions home-manager/common.nix
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@

# home.username = "<UPDATE_ME_IN_FLAKE>";
# TODO: How to cover lima? The default is /home/kachick.local
home.homeDirectory = if pkgs.stdenv.isDarwin then "/Users/${config.home.username}" else "/home/${config.home.username}";
home.homeDirectory = if pkgs.stdenv.isDarwin then
"/Users/${config.home.username}"
else
"/home/${config.home.username}";

# https://github.com/nix-community/home-manager/blob/master/modules/misc/xdg.nix
xdg.enable = true;
Expand All @@ -32,7 +35,8 @@
home = {
sessionVariables = {
# https://unix.stackexchange.com/questions/4859/visual-vs-editor-what-s-the-difference
EDITOR = "${pkgs.micro}/bin/micro"; # If you forgot the keybind: https://github.com/zyedidia/micro/blob/c15abea64c20066fc0b4c328dfabd3e6ba3253a0/runtime/help/defaultkeys.md
EDITOR =
"${pkgs.micro}/bin/micro"; # If you forgot the keybind: https://github.com/zyedidia/micro/blob/c15abea64c20066fc0b4c328dfabd3e6ba3253a0/runtime/help/defaultkeys.md
VISUAL = "code -w";
PAGER = "less";

Expand All @@ -48,7 +52,8 @@
# https://github.com/coreos/bugs/issues/365#issuecomment-105638617
LESSCHARSET = "utf-8";

STACK_XDG = "https://github.com/commercialhaskell/stack/blob/72f0a1273dd1121740501a159988fc23df2fb362/doc/stack_root.md?plain=1#L7-L11";
STACK_XDG =
"https://github.com/commercialhaskell/stack/blob/72f0a1273dd1121740501a159988fc23df2fb362/doc/stack_root.md?plain=1#L7-L11";
};

sessionPath = [
Expand Down Expand Up @@ -82,14 +87,10 @@
# See following reference
# - https://github.com/nix-community/nix-direnv/blob/ed2cb75553b4864e3c931a48e3a2cd43b93152c5/README.md?plain=1#L368-L373
# - https://github.com/kachick/ruby-ulid/pull/410
nix-direnv = {
enable = true;
};
nix-direnv = { enable = true; };
};

programs.zoxide = {
enable = true;
};
programs.zoxide = { enable = true; };

# https://nixos.wiki/wiki/Home_Manager
# - Prefer XDG_*
Expand All @@ -98,9 +99,11 @@
# Do not alias *.nix into `xdg.configFile`, it actually cannot be used because of using many relative dirs
# So you should call `home-manager switch` with `-f ~/repos/dotfiles/USER_NAME.nix`

xdg.configFile."alacritty/alacritty.toml".source = ../config/alacritty/alacritty-unix.toml;
xdg.configFile."alacritty/alacritty.toml".source =
../config/alacritty/alacritty-unix.toml;
xdg.configFile."alacritty/unix.toml".source = ../config/alacritty/unix.toml;
xdg.configFile."alacritty/common.toml".source = ../config/alacritty/common.toml;
xdg.configFile."alacritty/common.toml".source =
../config/alacritty/common.toml;
xdg.configFile."alacritty/themes" = {
source = ../config/alacritty/themes;
recursive = true;
Expand All @@ -111,35 +114,29 @@

# No home-manager module exists https://github.com/nix-community/home-manager/issues/2890
# TODO: Automate that needs to call `Install-Module -Name PSFzfHistory` first
xdg.configFile."powershell/Microsoft.PowerShell_profile.ps1".source = ../config/powershell/Profile.ps1;
xdg.configFile."powershell/Microsoft.PowerShell_profile.ps1".source =
../config/powershell/Profile.ps1;

xdg.dataFile."tmpbin/.keep".text = "";

home.file.".hushlogin".text = "This file disables daily login message. Not depend on this text.";
home.file.".hushlogin".text =
"This file disables daily login message. Not depend on this text.";

# Should have `root = true` in the file. - https://github.com/kachick/anylang-template/blob/45d7ef685ac4fd3836c3b32b8ce8fb45e909b771/.editorconfig#L1
# Intentionally avoided to use https://github.com/nix-community/home-manager/blob/f58889c07efa8e1328fdf93dc1796ec2a5c47f38/modules/misc/editorconfig.nix
home.file.".editorconfig".source =
pkgs.fetchFromGitHub
{
owner = "kachick";
repo = "anylang-template";
rev = "45d7ef685ac4fd3836c3b32b8ce8fb45e909b771";
sha256 = "sha256-F8xP4xCIS1ybvRm1xGB2USekGWKKxz0nokpY6gRxKBE=";
}
+ "/.editorconfig"
;

xdg.configFile."irb/irbrc".source =
pkgs.fetchFromGitHub
{
owner = "kachick";
repo = "irb-power_assert";
rev = "98ad68b4c391bb30adee1ba119cb6c6ed5bd0bfc";
sha256 = "sha256-Su3jaPELaBKa+CJpNp6OzOb/6/wwGk7JDxP/w9wVBtM=";
}
+ "/examples/.irbrc"
;
home.file.".editorconfig".source = pkgs.fetchFromGitHub {
owner = "kachick";
repo = "anylang-template";
rev = "45d7ef685ac4fd3836c3b32b8ce8fb45e909b771";
sha256 = "sha256-F8xP4xCIS1ybvRm1xGB2USekGWKKxz0nokpY6gRxKBE=";
} + "/.editorconfig";

xdg.configFile."irb/irbrc".source = pkgs.fetchFromGitHub {
owner = "kachick";
repo = "irb-power_assert";
rev = "98ad68b4c391bb30adee1ba119cb6c6ed5bd0bfc";
sha256 = "sha256-Su3jaPELaBKa+CJpNp6OzOb/6/wwGk7JDxP/w9wVBtM=";
} + "/examples/.irbrc";

# typos does not have feature global config, this is used in git hooks for https://github.com/kachick/dotfiles/issues/412
xdg.configFile."typos/_typos.toml".text = ''
Expand All @@ -154,7 +151,8 @@
enable = true;

# https://github.com/junegunn/fzf/blob/d579e335b5aa30e98a2ec046cb782bbb02bc28ad/README.md#respecting-gitignore
defaultCommand = "${pkgs.fd}/bin/fd --type f --strip-cwd-prefix --hidden --follow --exclude .git";
defaultCommand =
"${pkgs.fd}/bin/fd --type f --strip-cwd-prefix --hidden --follow --exclude .git";

# CTRL+T
fileWidgetCommand = defaultCommand;
Expand All @@ -171,9 +169,7 @@
};

# https://github.com/nix-community/home-manager/blob/master/modules/programs/starship.nix
programs.starship = {
enable = true;
};
programs.starship = { enable = true; };

# https://github.com/nix-community/home-manager/blob/master/modules/programs/mise.nix
programs.mise = {
Expand All @@ -183,7 +179,8 @@
plugins = {
# It is not registered in asdf-vm/plugins and does not appear to be actively maintained. So specify the ref here
# https://github.com/tvon/asdf-podman/tree/974e0fbb6051aaea0a685d8b14587113dfba9173
podman = "https://github.com/tvon/asdf-podman.git#974e0fbb6051aaea0a685d8b14587113dfba9173";
podman =
"https://github.com/tvon/asdf-podman.git#974e0fbb6051aaea0a685d8b14587113dfba9173";
};
};
};
Expand Down Expand Up @@ -225,16 +222,14 @@
splitright = true;
statusline = true;
syntax = true;
"ft:ruby" = {
tabsize = 2;
};
"ft:ruby" = { tabsize = 2; };

# Embed candidates are https://github.com/zyedidia/micro/tree/c15abea64c20066fc0b4c328dfabd3e6ba3253a0/runtime/colorschemes
colorscheme = "twilight"; # "default" is NFM, prefer solarized for dark blue
colorscheme =
"twilight"; # "default" is NFM, prefer solarized for dark blue
};
};


# https://github.com/nix-community/home-manager/blob/master/modules/programs/vim.nix
# https://nixos.wiki/wiki/Vim
programs.vim = {
Expand Down
Loading
Loading