Skip to content

Commit ebe1aa3

Browse files
authored
Merge pull request #201 from nix-community/feat/nixfmt
chore: move from alejandra to nixfmt
2 parents 8757285 + 236b6fc commit ebe1aa3

File tree

8 files changed

+148
-133
lines changed

8 files changed

+148
-133
lines changed

flake.nix

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@
3333
};
3434

3535
# Keep the magic invocations to minimum.
36-
outputs = inputs:
36+
outputs =
37+
inputs:
3738
inputs.blueprint {
3839
prefix = "nix/";
3940
inherit inputs;

nix/devshells/default.nix

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,16 @@
55
}:
66
perSystem.self.nixos-facter.overrideAttrs (old: {
77
GOROOT = "${old.passthru.go}/share/go";
8-
nativeBuildInputs =
9-
old.nativeBuildInputs
10-
++ [
11-
pkgs.enumer
12-
pkgs.delve
13-
pkgs.pprof
14-
pkgs.gotools
15-
pkgs.golangci-lint
16-
pkgs.cobra-cli
17-
pkgs.fx # json tui
18-
perSystem.hwinfo.default
19-
];
8+
nativeBuildInputs = old.nativeBuildInputs ++ [
9+
pkgs.enumer
10+
pkgs.delve
11+
pkgs.pprof
12+
pkgs.gotools
13+
pkgs.golangci-lint
14+
pkgs.cobra-cli
15+
pkgs.fx # json tui
16+
perSystem.hwinfo.default
17+
];
2018
shellHook = ''
2119
# this is only needed for hermetic builds
2220
unset GO_NO_VENDOR_CHECKS GOSUMDB GOPROXY GOFLAGS

nix/devshells/docs.nix

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
44
...
55
}:
66
pkgs.mkShellNoCC {
7-
packages = with pkgs;
8-
# Pop an empty shell on systems that aren't supported by godoc
9-
lib.optionals (perSystem.godoc ? default)
10-
([
7+
packages =
8+
with pkgs;
9+
# Pop an empty shell on systems that aren't supported by godoc
10+
lib.optionals (perSystem.godoc ? default) (
11+
[
1112
perSystem.godoc.default
1213
(pkgs.writeScriptBin "gen-reference" ''
1314
out="./docs/content/reference/go_doc"
@@ -23,5 +24,6 @@ pkgs.mkShellNoCC {
2324
++ (with pkgs.python3Packages; [
2425
mike
2526
mkdocs-material
26-
]));
27+
])
28+
);
2729
}

nix/formatter.nix

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@
33
flake,
44
inputs,
55
...
6-
}: let
6+
}:
7+
let
78
mod = inputs.treefmt-nix.lib.evalModule pkgs {
89
projectRootFile = ".git/config";
910

1011
programs =
1112
{
12-
alejandra.enable = true;
13+
nixfmt.enable = true;
1314
deadnix.enable = true;
1415
gofumpt.enable = true;
1516
prettier.enable = true;
@@ -35,7 +36,7 @@
3536
priority = 2;
3637
};
3738

38-
alejandra = {
39+
nixfmt = {
3940
priority = 3;
4041
};
4142

@@ -44,14 +45,22 @@
4445
"--tab-width"
4546
"4"
4647
];
47-
includes = ["*.{css,html,js,json,jsx,md,mdx,scss,ts,yaml}"];
48+
includes = [ "*.{css,html,js,json,jsx,md,mdx,scss,ts,yaml}" ];
4849
};
4950
};
5051
};
5152
};
52-
in
53-
mod.config.build.wrapper
54-
// {
55-
# check formatting as part of `nix flake check`
53+
54+
wrapper = mod.config.build.wrapper // {
5655
passthru.tests.check = mod.config.build.check flake;
57-
}
56+
};
57+
58+
unsupported = pkgs.writeShellApplication {
59+
name = "unsupported-platform";
60+
text = ''
61+
echo "nix fmt is not supported on ${pkgs.hostPlatform.system}";
62+
'';
63+
};
64+
in
65+
# nixfmt-rfc-style is based on Haskell, which is broke on RiscV currently
66+
if pkgs.hostPlatform.isRiscV then unsupported else wrapper

nix/package.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{perSystem, ...}: perSystem.self.nixos-facter
1+
{ perSystem, ... }: perSystem.self.nixos-facter
Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
args @ {
1+
args@{
22
# We need the following pragma to ensure deadnix doesn't remove inputs.
33
# This package is being called with newScope/callPackage, which means it is only being passed args it defines.
44
# We do not use inputs directly in this file, but need it for passing to the tests.
@@ -10,17 +10,18 @@ args @ {
1010
perSystem,
1111
pkgs,
1212
...
13-
}: let
13+
}:
14+
let
1415
inherit (pkgs) lib;
1516
in
16-
pkgs.callPackage ./package.nix {
17-
hwinfo = perSystem.hwinfo.default;
17+
pkgs.callPackage ./package.nix {
18+
hwinfo = perSystem.hwinfo.default;
1819

19-
# there's no good way of tying in the version to a git tag or branch
20-
# so for simplicity's sake we set the version as the commit revision hash
21-
# we remove the `-dirty` suffix to avoid a lot of unnecessary rebuilds in local dev
22-
versionSuffix = "-${lib.removeSuffix "-dirty" (flake.shortRev or flake.dirtyShortRev)}";
23-
}
24-
// {
25-
passthru.tests = import ./tests args;
26-
}
20+
# there's no good way of tying in the version to a git tag or branch
21+
# so for simplicity's sake we set the version as the commit revision hash
22+
# we remove the `-dirty` suffix to avoid a lot of unnecessary rebuilds in local dev
23+
versionSuffix = "-${lib.removeSuffix "-dirty" (flake.shortRev or flake.dirtyShortRev)}";
24+
}
25+
// {
26+
passthru.tests = import ./tests args;
27+
}

nix/packages/nixos-facter/package.nix

Lines changed: 45 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -9,60 +9,63 @@
99
stdenv,
1010
buildGo124Module,
1111
versionCheckHook,
12-
}: let
12+
}:
13+
let
1314
fs = lib.fileset;
1415
in
15-
buildGo124Module (final: {
16-
pname = "nixos-facter";
17-
version = "0.3.2";
16+
buildGo124Module (final: {
17+
pname = "nixos-facter";
18+
version = "0.3.2";
1819

19-
src = fs.toSource {
20-
root = ../../..;
21-
fileset = fs.unions [
22-
../../../cmd
23-
../../../go.mod
24-
../../../go.sum
25-
../../../main.go
26-
../../../pkg
27-
];
28-
};
20+
src = fs.toSource {
21+
root = ../../..;
22+
fileset = fs.unions [
23+
../../../cmd
24+
../../../go.mod
25+
../../../go.sum
26+
../../../main.go
27+
../../../pkg
28+
];
29+
};
2930

30-
vendorHash = "sha256-A7ZuY8Gc/a0Y8O6UG2WHWxptHstJOxi4n9F8TY6zqiw=";
31+
vendorHash = "sha256-A7ZuY8Gc/a0Y8O6UG2WHWxptHstJOxi4n9F8TY6zqiw=";
3132

32-
buildInputs = [
33-
systemdMinimal
34-
hwinfo
35-
];
33+
buildInputs = [
34+
systemdMinimal
35+
hwinfo
36+
];
3637

37-
nativeBuildInputs = [
38-
gcc
39-
makeWrapper
40-
pkg-config
41-
versionCheckHook
42-
];
38+
nativeBuildInputs = [
39+
gcc
40+
makeWrapper
41+
pkg-config
42+
versionCheckHook
43+
];
4344

44-
ldflags = [
45-
"-s"
46-
"-w"
47-
"-X github.com/numtide/nixos-facter/pkg/build.Name=${final.pname}"
48-
"-X github.com/numtide/nixos-facter/pkg/build.Version=v${final.version}${toString versionSuffix}"
49-
"-X github.com/numtide/nixos-facter/pkg/build.System=${stdenv.hostPlatform.system}"
50-
];
45+
ldflags = [
46+
"-s"
47+
"-w"
48+
"-X github.com/numtide/nixos-facter/pkg/build.Name=${final.pname}"
49+
"-X github.com/numtide/nixos-facter/pkg/build.Version=v${final.version}${toString versionSuffix}"
50+
"-X github.com/numtide/nixos-facter/pkg/build.System=${stdenv.hostPlatform.system}"
51+
];
5152

52-
doInstallCheck = true;
53-
postInstall = let
53+
doInstallCheck = true;
54+
postInstall =
55+
let
5456
binPath = lib.makeBinPath [
5557
systemdMinimal
5658
];
57-
in ''
59+
in
60+
''
5861
wrapProgram "$out/bin/nixos-facter" \
5962
--prefix PATH : "${binPath}"
6063
'';
6164

62-
meta = with lib; {
63-
description = "nixos-facter: declarative nixos-generate-config";
64-
homepage = "https://github.com/numtide/nixos-facter";
65-
license = licenses.mit;
66-
mainProgram = "nixos-facter";
67-
};
68-
})
65+
meta = with lib; {
66+
description = "nixos-facter: declarative nixos-generate-config";
67+
homepage = "https://github.com/numtide/nixos-facter";
68+
license = licenses.mit;
69+
mainProgram = "nixos-facter";
70+
};
71+
})

nix/packages/nixos-facter/tests/default.nix

Lines changed: 52 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -4,73 +4,74 @@
44
system,
55
perSystem,
66
...
7-
}: let
7+
}:
8+
let
89
# we have to import diskoLib like this because there are some impure default imports e.g. <nixpkgs>
910
diskoLib = import "${inputs.disko}/lib" {
1011
inherit (pkgs) lib;
1112
makeTest = import "${inputs.nixpkgs}/nixos/tests/make-test-python.nix";
1213
eval-config = import "${inputs.nixpkgs}/nixos/lib/eval-config.nix";
1314
};
1415
in
15-
# for now we only run the tests in x86_64-linux since we don't have access to a bare-metal ARM box or a VM that supports nested
16-
# virtualisation which makes the test take forever and ultimately fail
17-
pkgs.lib.optionalAttrs pkgs.stdenv.isx86_64 {
18-
golangci-lint = perSystem.self.nixos-facter.overrideAttrs (old: {
19-
nativeBuildInputs = old.nativeBuildInputs ++ [pkgs.golangci-lint];
20-
buildPhase = ''
21-
HOME=$TMPDIR
22-
golangci-lint run
23-
'';
24-
installPhase = ''
25-
touch $out
26-
'';
27-
doInstallCheck = false;
28-
doCheck = false;
29-
});
16+
# for now we only run the tests in x86_64-linux since we don't have access to a bare-metal ARM box or a VM that supports nested
17+
# virtualisation which makes the test take forever and ultimately fail
18+
pkgs.lib.optionalAttrs pkgs.stdenv.isx86_64 {
19+
golangci-lint = perSystem.self.nixos-facter.overrideAttrs (old: {
20+
nativeBuildInputs = old.nativeBuildInputs ++ [ pkgs.golangci-lint ];
21+
buildPhase = ''
22+
HOME=$TMPDIR
23+
golangci-lint run
24+
'';
25+
installPhase = ''
26+
touch $out
27+
'';
28+
doInstallCheck = false;
29+
doCheck = false;
30+
});
3031

31-
basic = diskoLib.testLib.makeDiskoTest {
32-
inherit pkgs;
33-
name = "basic";
34-
disko-config = ./disko.nix;
35-
extraSystemConfig = {
36-
environment.systemPackages = [
37-
perSystem.self.nixos-facter
38-
];
39-
};
32+
basic = diskoLib.testLib.makeDiskoTest {
33+
inherit pkgs;
34+
name = "basic";
35+
disko-config = ./disko.nix;
36+
extraSystemConfig = {
37+
environment.systemPackages = [
38+
perSystem.self.nixos-facter
39+
];
40+
};
4041

41-
extraTestScript = ''
42-
import json
42+
extraTestScript = ''
43+
import json
4344
44-
report = json.loads(machine.succeed("nixos-facter --ephemeral 2>&1"))
45+
report = json.loads(machine.succeed("nixos-facter --ephemeral 2>&1"))
4546
46-
with subtest("Capture system"):
47-
assert report['system'] == '${system}'
47+
with subtest("Capture system"):
48+
assert report['system'] == '${system}'
4849
49-
with subtest("Capture virtualisation"):
50-
virt = report['virtualisation']
51-
# kvm for systems that support it, otherwise the vm test should present itself as qemu
52-
# todo double-check this is the same for intel
53-
assert virt in ("kvm", "qemu"), f"expected virtualisation to be either kvm or qemu, got {virt}"
50+
with subtest("Capture virtualisation"):
51+
virt = report['virtualisation']
52+
# kvm for systems that support it, otherwise the vm test should present itself as qemu
53+
# todo double-check this is the same for intel
54+
assert virt in ("kvm", "qemu"), f"expected virtualisation to be either kvm or qemu, got {virt}"
5455
55-
with subtest("Capture swap entries"):
56-
assert 'swap' in report, "'swap' not found in the report"
56+
with subtest("Capture swap entries"):
57+
assert 'swap' in report, "'swap' not found in the report"
5758
58-
swap = report['swap']
59+
swap = report['swap']
5960
60-
expected = [
61-
{ 'type': 'partition', 'size': 1048572, 'used': 0, 'priority': -2 },
62-
{ 'type': 'partition', 'size': 10236, 'used': 0, 'priority': 100 }
63-
]
61+
expected = [
62+
{ 'type': 'partition', 'size': 1048572, 'used': 0, 'priority': -2 },
63+
{ 'type': 'partition', 'size': 10236, 'used': 0, 'priority': 100 }
64+
]
6465
65-
assert len(swap) == len(expected), f"expected {len(expected)} swap entries, found {len(swap)}"
66+
assert len(swap) == len(expected), f"expected {len(expected)} swap entries, found {len(swap)}"
6667
67-
for i in range(2):
68-
assert swap[i]['path'].startswith("/dev/disk/by-uuid/"), f"expected a stable device path: {swap[i]['path']}"
68+
for i in range(2):
69+
assert swap[i]['path'].startswith("/dev/disk/by-uuid/"), f"expected a stable device path: {swap[i]['path']}"
6970
70-
# delete for easier comparison
71-
del swap[i]['path']
71+
# delete for easier comparison
72+
del swap[i]['path']
7273
73-
assert swap[i] == expected[i], "swap[{i}] mismatch"
74-
'';
75-
};
76-
}
74+
assert swap[i] == expected[i], "swap[{i}] mismatch"
75+
'';
76+
};
77+
}

0 commit comments

Comments
 (0)