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

Follow updated nixpkgs and prefer nixfmt-rfc-style #553

Merged
merged 3 commits into from
Apr 7, 2024
Merged
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
7 changes: 7 additions & 0 deletions cmd/deps/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,14 @@ func main() {
{Path: "typos", Args: []string{"--version"}},
{Path: "gitleaks", Args: []string{"version"}},
{Path: "goreleaser", Args: []string{"--version"}},

// Even if nixfmt returns old version as v0.5.0, the actual code is latest
// https://github.com/NixOS/nixpkgs/pull/292625/files#diff-cf53ba433c9a367969e739cd32bc5a6fb9be271ed0ec604c34a3542a54ff1f5fR9-R12
{Path: "nixfmt", Args: []string{"--version"}},
// store path includes the date, but nix develop is too slow
{Path: "bash", Args: []string{"-c", "which nixfmt"}},
}

// No side-effect commands, but keeping sequential for readability
cmds.SequentialRun()
}
4 changes: 1 addition & 3 deletions cmd/lint/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,12 @@ func main() {
walker := fileutils.GetWalker()

bashPaths := walker.GetAllBash()
nixPaths := walker.GetAllNix()

cmds := runner.Commands{
{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...)},
// nix fmt doesn't have check option: https://github.com/NixOS/nix/issues/6918, so do not include here
{Path: "typos", Args: constants.GetTyposTargetedRoots()},
{Path: "gitleaks", Args: []string{"detect"}},
{Path: "go", Args: []string{"vet", "./..."}},
Expand Down
19 changes: 1 addition & 18 deletions flake.lock

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

90 changes: 44 additions & 46 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
# - `nix flake update --commit-lock-file` # https://nixos.org/manual/nix/stable/command-ref/new-cli/nix3-flake-update.html
nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.11";
edge-nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
plemoljp-nixpkgs.url = "github:NixOS/nixpkgs/fe6c0ea25c89b9efe12d1fcd236c8b1432b36967";
flake-utils.url = "github:numtide/flake-utils";
# https://github.com/nix-community/home-manager/blob/release-23.11/docs/manual/nix-flakes.md
home-manager = {
Expand All @@ -16,28 +15,34 @@
};
};

outputs = { self, nixpkgs, edge-nixpkgs, home-manager, flake-utils, plemoljp-nixpkgs }:
flake-utils.lib.eachDefaultSystem (system:
outputs =
{
self,
nixpkgs,
edge-nixpkgs,
home-manager,
flake-utils,
}:
flake-utils.lib.eachDefaultSystem (
system:
let
pkgs = nixpkgs.legacyPackages.${system};
edge-pkgs = edge-nixpkgs.legacyPackages.${system};
edge-fonts-pkgs = plemoljp-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
# 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
# - https://github.com/NixOS/nixfmt/blob/a81f922a2b362f347a6cbecff5fb14f3052bc25d/README.md#L19
formatter = edge-pkgs.nixpkgs-fmt;
devShells.default = with pkgs;
formatter = edge-pkgs.nixfmt-rfc-style;
devShells.default =
with pkgs;
mkShell {
buildInputs = [
# https://github.com/NixOS/nix/issues/730#issuecomment-162323824
bashInteractive
edge-pkgs.nixpkgs-fmt
edge-pkgs.nixfmt # Using a sub formatter
edge-pkgs.nixfmt-rfc-style
edge-pkgs.nil
# To get sha256 around pkgs.fetchFromGitHub in CLI
nix-prefetch-git
Expand All @@ -62,7 +67,6 @@
modules = [ ./home-manager/kachick.nix ];
extraSpecialArgs = {
inherit edge-pkgs;
inherit edge-fonts-pkgs;
};
};

Expand All @@ -76,7 +80,6 @@
];
extraSpecialArgs = {
inherit edge-pkgs;
inherit edge-fonts-pkgs;
};
};

Expand All @@ -91,51 +94,46 @@
];
extraSpecialArgs = {
inherit edge-pkgs;
inherit edge-fonts-pkgs;
};
};
};

packages.bump_completions =
pkgs.writeShellScriptBin "bump_completions" ''
set -euo pipefail
packages.bump_completions = pkgs.writeShellScriptBin "bump_completions" ''
set -euo pipefail

${edge-pkgs.podman}/bin/podman completion bash > ./dependencies/podman/completions.bash
${edge-pkgs.podman}/bin/podman completion zsh > ./dependencies/podman/completions.zsh
${edge-pkgs.podman}/bin/podman completion fish > ./dependencies/podman/completions.fish
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

${edge-pkgs.podman}/bin/podman completion bash > ./dependencies/podman/completions.bash
${edge-pkgs.podman}/bin/podman completion zsh > ./dependencies/podman/completions.zsh
${edge-pkgs.podman}/bin/podman completion fish > ./dependencies/podman/completions.fish

${edge-pkgs.dprint}/bin/dprint completions bash > ./dependencies/dprint/completions.bash
${edge-pkgs.dprint}/bin/dprint completions zsh > ./dependencies/dprint/completions.zsh
${edge-pkgs.dprint}/bin/dprint completions fish > ./dependencies/dprint/completions.fish
'';
${edge-pkgs.dprint}/bin/dprint completions bash > ./dependencies/dprint/completions.bash
${edge-pkgs.dprint}/bin/dprint completions zsh > ./dependencies/dprint/completions.zsh
${edge-pkgs.dprint}/bin/dprint completions fish > ./dependencies/dprint/completions.fish
'';

packages.check_no_dirty_xz_in_nix_store =
pkgs.writeShellApplication {
name = "check_no_dirty_xz_in_nix_store";
runtimeInputs = with pkgs; [ fd ];
text = ''
# nix store should have xz: https://github.com/NixOS/nixpkgs/blob/b96bc828b81140dd3fb096b4e66a6446d6d5c9dc/doc/stdenv/stdenv.chapter.md?plain=1#L177
# You can't use --max-results instead of --has-results even if you want the log, it always returns true
fd '^\w+-xz-[0-9\.]+\.drv' --search-path /nix/store --has-results
packages.check_no_dirty_xz_in_nix_store = pkgs.writeShellApplication {
name = "check_no_dirty_xz_in_nix_store";
runtimeInputs = with pkgs; [ fd ];
text = ''
# nix store should have xz: https://github.com/NixOS/nixpkgs/blob/b96bc828b81140dd3fb096b4e66a6446d6d5c9dc/doc/stdenv/stdenv.chapter.md?plain=1#L177
# You can't use --max-results instead of --has-results even if you want the log, it always returns true
fd '^\w+-xz-[0-9\.]+\.drv' --search-path /nix/store --has-results

# Why toggling errexit and return code here: https://github.com/kachick/times_kachick/issues/278
set +o errexit
fd '^\w+-xz-5\.6\.[01]\.drv' --search-path /nix/store --has-results
fd_return_code="$?" # Do not directly use the $? to prevent feature broken if inserting another command before check
set -o errexit
[[ "$fd_return_code" -eq 1 ]]
'';
meta = {
description = "Prevent #530 (around CVE-2024-3094)";
};
# Why toggling errexit and return code here: https://github.com/kachick/times_kachick/issues/278
set +o errexit
fd '^\w+-xz-5\.6\.[01]\.drv' --search-path /nix/store --has-results
fd_return_code="$?" # Do not directly use the $? to prevent feature broken if inserting another command before check
set -o errexit
[[ "$fd_return_code" -eq 1 ]]
'';
meta = {
description = "Prevent #530 (around CVE-2024-3094)";
};
};

apps = {
# example: `nix run .#home-manager -- switch -n -b backup --flake .#kachick`
# https://github.com/NixOS/nix/issues/6448#issuecomment-1132855605
home-manager = flake-utils.lib.mkApp {
drv = home-manager.defaultPackage.${system};
};
home-manager = flake-utils.lib.mkApp { drv = home-manager.defaultPackage.${system}; };

bump_completions = {
type = "app";
Expand All @@ -147,6 +145,6 @@
program = "${packages.check_no_dirty_xz_in_nix_store}/bin/check_no_dirty_xz_in_nix_store";
};
};
});
}
);
}

56 changes: 40 additions & 16 deletions home-manager/bash.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
{ config, lib, pkgs, edge-pkgs, ... }:
{
config,
lib,
pkgs,
edge-pkgs,
...
}:

{
services.gpg-agent.enableBashIntegration = true;
Expand Down Expand Up @@ -68,9 +74,25 @@
historySize = 100000;
historyFile = "${config.xdg.stateHome}/bash/history";
historyFileSize = 4200000;
historyControl = [ "erasedups" "ignoredups" "ignorespace" ];
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" ];
historyIgnore = [
"cd"
"pushd"
"popd"
"z"
"ls"
"ll"
"la"
"rm"
"rmdir"
"git show"
"exit"
];

# Switch to another shell when bash used as a login shell
profileExtra = ''
Expand All @@ -84,23 +106,25 @@
'';

# Extracting because embedded here requires complex escape with nix multiline.
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"
}
# shellcheck disable=SC2034
starship_precmd_user_func="set_win_title"
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"
}
# shellcheck disable=SC2034
starship_precmd_user_func="set_win_title"

eval "$(${lib.getExe edge-pkgs.mise} activate bash)"
eval "$(${lib.getExe edge-pkgs.mise} activate bash)"

source "${edge-pkgs.fzf-git-sh}/share/fzf-git-sh/fzf-git.sh"
source "${edge-pkgs.fzf-git-sh}/share/fzf-git-sh/fzf-git.sh"

source "${../dependencies/podman/completions.bash}"
source "${../dependencies/dprint/completions.bash}"
source "${../dependencies/podman/completions.bash}"
source "${../dependencies/dprint/completions.bash}"

source "${config.xdg.configHome}/posix_shells/shared_functions.sh"
'' + builtins.readFile ./initExtra.bash;
source "${config.xdg.configHome}/posix_shells/shared_functions.sh"
''
+ builtins.readFile ./initExtra.bash;

logoutExtra = ''
# when leaving the console clear the screen to increase privacy
Expand Down
Loading
Loading