-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add nixfmt, use as default over nixpkgs-fmt
- Loading branch information
1 parent
a69482f
commit 3ede8d7
Showing
3 changed files
with
203 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
FROM nixos/nix:2.23.1 | ||
LABEL maintainer="Chris Martin <[email protected]>" | ||
RUN echo "experimental-features = nix-command flakes" > /etc/nix/nix.conf | ||
RUN nix profile install --impure 'github:NixOS/nixfmt?rev=698954723ecec3f91770460ecae762ce590f2d9e' | ||
RUN nix profile install --impure 'nixpkgs#gnused' | ||
RUN mkdir -p /code | ||
WORKDIR /code | ||
CMD ["nixfmt", "--help"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,194 @@ | ||
enabled: true | ||
name: nixfmt | ||
version_cmd: | | ||
nixfmt --version | sed 's/^nixfmt \(.*\)$/\1/' | ||
command: | ||
- nixfmt | ||
supports_arg_sep: true | ||
supports_multiple_files: true | ||
include: | ||
- "**/*.nix" | ||
documentation: | ||
- https:/NixOS/nixfmt#readme | ||
metadata: | ||
languages: | ||
- Nix | ||
tests: | ||
- name: Online demo | ||
contents: | | ||
let | ||
/* | ||
* What you're seeing here is our nix formatter. It's quite opinionated: | ||
*/ | ||
sample-01 = { lib }: | ||
{ | ||
list = [ | ||
elem1 | ||
elem2 | ||
elem3 | ||
] ++ lib.optionals stdenv.isDarwin [ | ||
elem4 | ||
elem5 | ||
]; # and not quite finished | ||
}; # it will preserve your newlines | ||
sample-02 = { stdenv, lib }: | ||
{ | ||
list = | ||
[ | ||
elem1 | ||
elem2 | ||
elem3 | ||
] | ||
++ lib.optionals stdenv.isDarwin [ elem4 elem5 ] | ||
++ lib.optionals stdenv.isLinux [ elem6 ] | ||
; | ||
}; | ||
# but it can handle all nix syntax, | ||
# and, in fact, all of nixpkgs in <20s. | ||
# The javascript build is quite a bit slower. | ||
sample-03 = { stdenv, system }: | ||
assert system == "i686-linux"; | ||
stdenv.mkDerivation { }; | ||
# these samples are all from https:/nix-community/nix-fmt/tree/master/samples | ||
sample-simple = # Some basic formatting | ||
{ | ||
empty_list = [ ]; | ||
inline_list = [ 1 2 3 ]; | ||
multiline_list = [ | ||
1 | ||
2 | ||
3 | ||
4 | ||
]; | ||
inline_attrset = { x = "y"; }; | ||
multiline_attrset = { | ||
a = 3; | ||
b = 5; | ||
}; | ||
# some comment over here | ||
fn = x: x + x; | ||
relpath = ./hello; | ||
abspath = /hello; | ||
# URLs get converted from strings | ||
url = "https://foobar.com"; | ||
atoms = [ true false null ]; | ||
# Combined | ||
listOfAttrs = [ | ||
{ | ||
attr1 = 3; | ||
attr2 = "fff"; | ||
} | ||
{ | ||
attr1 = 5; | ||
attr2 = "ggg"; | ||
} | ||
]; | ||
# long expression | ||
attrs = { | ||
attr1 = short_expr; | ||
attr2 = | ||
if true then big_expr else big_expr; | ||
}; | ||
} | ||
; | ||
in | ||
[ sample-01 sample-02 sample-03 ] | ||
restyled: | | ||
let | ||
# * What you're seeing here is our nix formatter. It's quite opinionated: | ||
sample-01 = | ||
{ lib }: | ||
{ | ||
list = | ||
[ | ||
elem1 | ||
elem2 | ||
elem3 | ||
] | ||
++ lib.optionals stdenv.isDarwin [ | ||
elem4 | ||
elem5 | ||
]; # and not quite finished | ||
}; # it will preserve your newlines | ||
sample-02 = | ||
{ stdenv, lib }: | ||
{ | ||
list = | ||
[ | ||
elem1 | ||
elem2 | ||
elem3 | ||
] | ||
++ lib.optionals stdenv.isDarwin [ | ||
elem4 | ||
elem5 | ||
] | ||
++ lib.optionals stdenv.isLinux [ elem6 ]; | ||
}; | ||
# but it can handle all nix syntax, | ||
# and, in fact, all of nixpkgs in <20s. | ||
# The javascript build is quite a bit slower. | ||
sample-03 = | ||
{ stdenv, system }: | ||
assert system == "i686-linux"; | ||
stdenv.mkDerivation { }; | ||
# these samples are all from https:/nix-community/nix-fmt/tree/master/samples | ||
sample-simple = # Some basic formatting | ||
{ | ||
empty_list = [ ]; | ||
inline_list = [ | ||
1 | ||
2 | ||
3 | ||
]; | ||
multiline_list = [ | ||
1 | ||
2 | ||
3 | ||
4 | ||
]; | ||
inline_attrset = { | ||
x = "y"; | ||
}; | ||
multiline_attrset = { | ||
a = 3; | ||
b = 5; | ||
}; | ||
# some comment over here | ||
fn = x: x + x; | ||
relpath = ./hello; | ||
abspath = /hello; | ||
# URLs get converted from strings | ||
url = "https://foobar.com"; | ||
atoms = [ | ||
true | ||
false | ||
null | ||
]; | ||
# Combined | ||
listOfAttrs = [ | ||
{ | ||
attr1 = 3; | ||
attr2 = "fff"; | ||
} | ||
{ | ||
attr1 = 5; | ||
attr2 = "ggg"; | ||
} | ||
]; | ||
# long expression | ||
attrs = { | ||
attr1 = short_expr; | ||
attr2 = if true then big_expr else big_expr; | ||
}; | ||
}; | ||
in | ||
[ | ||
sample-01 | ||
sample-02 | ||
sample-03 | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters