Skip to content

Commit 5d4569e

Browse files
committed
feat(nix): formatters
Use https://github.com/numtide/treefmt-nix to format codes. Signed-off-by: Leonard Sheng Sheng Lee <[email protected]>
1 parent 49810df commit 5d4569e

File tree

15 files changed

+205
-96
lines changed

15 files changed

+205
-96
lines changed

.github/workflows/pr-check-signed-commits.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
name: Check signed commits in PR
1+
name: Check signed commits in PR
22
on: pull_request_target
33

44
jobs:
55
build:
6-
name: Check signed commits in PR
6+
name: Check signed commits in PR
77
permissions:
88
contents: read
99
pull-requests: write

.github/workflows/update-flake-dependencies.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
FILE_TO_COMMIT: flake.lock
1818
COMMIT_BRANCH: automation/update-flake-dependencies
1919
COMMIT_MESSAGE: "chore(nix): Update Flake dependencies"
20-
run: |
20+
run: |-
2121
# fetch remote state
2222
git fetch
2323
# if branch exists on remote already

flake.lock

Lines changed: 36 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,35 @@
22
inputs = {
33
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
44
systems.url = "github:nix-systems/default";
5+
treefmt-nix.url = "github:numtide/treefmt-nix";
56
};
6-
outputs = { nixpkgs, systems, ... }:
7+
outputs =
8+
{
9+
nixpkgs,
10+
systems,
11+
treefmt-nix,
12+
...
13+
}:
714
let
8-
forAllSystems = function:
9-
nixpkgs.lib.genAttrs (import systems) (
10-
system: function nixpkgs.legacyPackages.${system}
11-
);
15+
forAllSystems =
16+
function: nixpkgs.lib.genAttrs (import systems) (system: function nixpkgs.legacyPackages.${system});
17+
18+
treefmtEval = forAllSystems (pkgs: treefmt-nix.lib.evalModule pkgs ./treefmt.nix);
1219
in
1320
{
21+
formatter = forAllSystems (pkgs: treefmtEval.${pkgs.system}.config.build.wrapper);
22+
23+
checks = forAllSystems (pkgs: {
24+
formatting = treefmtEval.${pkgs.system}.config.build.check (pkgs.path or ./.);
25+
});
26+
1427
devShells = forAllSystems (pkgs: {
1528
default = pkgs.mkShell {
1629
name = "Shell with Go toolchain";
17-
packages = with pkgs; [ go gopls ];
30+
packages = with pkgs; [
31+
go
32+
gopls
33+
];
1834
};
1935
});
2036

nix/home-manager.nix

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
{ pkgs, lib, config, ... }:
1+
{
2+
pkgs,
3+
lib,
4+
config,
5+
...
6+
}:
27
import ./shell-plugins.nix {
38
inherit pkgs;
49
inherit lib;

nix/nixos.nix

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
{ pkgs, lib, config, ... }:
1+
{
2+
pkgs,
3+
lib,
4+
config,
5+
...
6+
}:
27
import ./shell-plugins.nix {
38
inherit pkgs;
49
inherit lib;

nix/shell-plugins.nix

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
{ pkgs, lib, config, is-home-manager, ... }:
1+
{
2+
pkgs,
3+
lib,
4+
config,
5+
is-home-manager,
6+
...
7+
}:
28
with lib;
39
let
410
cfg = config.programs._1password-shell-plugins;
@@ -44,15 +50,13 @@ in
4450
# for which the executable has a supported 1Password Shell Plugin
4551
apply =
4652
package_list:
47-
map
48-
(
49-
package:
50-
if (elem (getExeName package) supported_plugins) then
51-
package
52-
else
53-
abort "${getExeName package} is not a valid 1Password Shell Plugin. A list of supported plugins can be found by running `op plugin list` or at: https://developer.1password.com/docs/cli/shell-plugins/"
54-
)
55-
package_list;
53+
map (
54+
package:
55+
if (elem (getExeName package) supported_plugins) then
56+
package
57+
else
58+
abort "${getExeName package} is not a valid 1Password Shell Plugin. A list of supported plugins can be found by running `op plugin list` or at: https://developer.1password.com/docs/cli/shell-plugins/"
59+
) package_list;
5660
};
5761
};
5862
};
@@ -80,26 +84,20 @@ in
8084
# end
8185
# ```
8286
# where `{pkg}` is the executable name of the package
83-
posixFunctions = map
84-
(package: ''
85-
${package}() {
86-
op plugin run -- ${package} "$@";
87-
}
88-
'')
89-
pkg-exe-names;
90-
fishFunctions = map
91-
(package: ''
92-
function ${package} --wraps "${package}" --description "1Password Shell Plugin for ${package}"
93-
op plugin run -- ${package} $argv
94-
end
95-
'')
96-
pkg-exe-names;
87+
posixFunctions = map (package: ''
88+
${package}() {
89+
op plugin run -- ${package} "$@";
90+
}
91+
'') pkg-exe-names;
92+
fishFunctions = map (package: ''
93+
function ${package} --wraps "${package}" --description "1Password Shell Plugin for ${package}"
94+
op plugin run -- ${package} $argv
95+
end
96+
'') pkg-exe-names;
9797
packages = lib.optional (cfg.package != null) cfg.package ++ cfg.plugins;
9898
in
9999
mkIf cfg.enable (mkMerge [
100-
{
101-
programs.fish.interactiveShellInit = strings.concatStringsSep "\n" fishFunctions;
102-
}
100+
{ programs.fish.interactiveShellInit = strings.concatStringsSep "\n" fishFunctions; }
103101
(optionalAttrs is-home-manager {
104102
programs = {
105103
# for the Bash and Zsh home-manager modules,
@@ -109,20 +107,22 @@ in
109107
};
110108
home = {
111109
inherit packages;
112-
sessionVariables = { OP_PLUGINS_SOURCED = "1"; };
110+
sessionVariables = {
111+
OP_PLUGINS_SOURCED = "1";
112+
};
113113
};
114114
})
115115
(optionalAttrs (!is-home-manager) {
116116
programs = {
117-
bash.interactiveShellInit =
118-
strings.concatStringsSep "\n" posixFunctions;
117+
bash.interactiveShellInit = strings.concatStringsSep "\n" posixFunctions;
119118
zsh.interactiveShellInit = strings.concatStringsSep "\n" posixFunctions;
120119
};
121120
environment = {
122121
systemPackages = packages;
123-
variables = { OP_PLUGINS_SOURCED = "1"; };
122+
variables = {
123+
OP_PLUGINS_SOURCED = "1";
124+
};
124125
};
125126
})
126127
]);
127128
}
128-

plugins/circleci/test-fixtures/cli.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ rest_endpoint: api/v2
55
tls_cert: ""
66
tls_insecure: false
77
orb_publishing:
8-
default_namespace: ""
9-
default_vcs_provider: ""
10-
default_owner: ""
8+
default_namespace: ""
9+
default_vcs_provider: ""
10+
default_owner: ""
Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
logins:
2-
- name: https://git.example.com
3-
url: https://git.example.com
4-
token: oyyfsny27bgphldmhvffxhhlmqvdkzjrfslrsj9f
5-
default: true
6-
ssh_host: ""
7-
ssh_key: ""
8-
insecure: false
9-
ssh_certificate_principal: ""
10-
ssh_agent: false
11-
ssh_key_agent_pub: ""
12-
version_check: false
13-
user: example
14-
created: 0
2+
- name: https://git.example.com
3+
url: https://git.example.com
4+
token: oyyfsny27bgphldmhvffxhhlmqvdkzjrfslrsj9f
5+
default: true
6+
ssh_host: ""
7+
ssh_key: ""
8+
insecure: false
9+
ssh_certificate_principal: ""
10+
ssh_agent: false
11+
ssh_key_agent_pub: ""
12+
version_check: false
13+
user: example
14+
created: 0
Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
logins:
2-
- name: git.example.com
3-
url: https://git.example.com
4-
token: oyyfsny27bgphldmhvffxhhlmqvdkzjrfslrsj9f
5-
default: false
6-
ssh_host: git.example.com
7-
ssh_key: ~/.ssh/id_ed25519
8-
insecure: false
9-
user: example
10-
created: 1479340800000
11-
- name: gitea.com
12-
url: https://gitea.com
13-
token: enjkarzu2ca5ffcnvzaczxncuczeoq9utlpqqrzs
14-
default: false
15-
ssh_host: git.example.com
16-
ssh_key: ~/.ssh/id_ed25519
17-
insecure: true
18-
19-
created: 1479340800000
2+
- name: git.example.com
3+
url: https://git.example.com
4+
token: oyyfsny27bgphldmhvffxhhlmqvdkzjrfslrsj9f
5+
default: false
6+
ssh_host: git.example.com
7+
ssh_key: ~/.ssh/id_ed25519
8+
insecure: false
9+
user: example
10+
created: 1479340800000
11+
- name: gitea.com
12+
url: https://gitea.com
13+
token: enjkarzu2ca5ffcnvzaczxncuczeoq9utlpqqrzs
14+
default: false
15+
ssh_host: git.example.com
16+
ssh_key: ~/.ssh/id_ed25519
17+
insecure: true
18+
19+
created: 1479340800000
2020
preferences:
2121
editor: false
2222
flag_defaults:
23-
remote: ""
23+
remote: ""

0 commit comments

Comments
 (0)