Skip to content

Commit 0ff3584

Browse files
authored
Clean up Nix Flake and packaging (#24)
* refactor(nix): split package.nix from flake.nix * chore(nix): split checks; add more * ci: run all nix checks * ci: build in debug mode * chore(nix): use versionCheckHook this makes sure the version test is always run, and on the right package * chore(nix): nix-filter -> lib.fileset * feat(nix): support stable nix * ci: fix clippy check
1 parent 1ec360f commit 0ff3584

File tree

7 files changed

+132
-136
lines changed

7 files changed

+132
-136
lines changed

.github/workflows/ci.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@ jobs:
4141

4242
- name: Run build
4343
run: |
44-
nix build --print-build-logs .#check-version-test
44+
nix build --print-build-logs .#nix-forecast-debug
4545
46-
format:
47-
name: Formatting
46+
format-and-lint:
47+
name: Format and lint
4848

4949
runs-on: ubuntu-latest
5050

@@ -60,11 +60,11 @@ jobs:
6060

6161
- name: Run flake checks
6262
run: |
63-
nix build --print-build-logs .#check-formatting
63+
nix flake check --print-build-logs --show-trace
6464
6565
release-gate:
6666
name: CI Release gate
67-
needs: [build, format]
67+
needs: [build, format-and-lint]
6868

6969
if: ${{ always() }}
7070

.github/workflows/clippy.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ jobs:
4040
- name: Run clippy
4141
id: clippy-run
4242
run: |
43-
nix build --print-build-logs .#check-clippy
43+
nix build --print-build-logs .#checks.x86_64-linux.clippy
4444
[ -L result ] || exit 1
4545
echo "sarif-file=$(readlink -f result)" >> "$GITHUB_OUTPUT"
4646

default.nix

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
pkgs ? import nixpkgs {
3+
inherit system;
4+
config = { };
5+
overlays = [ ];
6+
},
7+
lib ? pkgs.lib,
8+
nixpkgs ? <nixpkgs>,
9+
system ? builtins.currentSystem,
10+
}:
11+
12+
let
13+
nixForecastPackages = lib.makeScope pkgs.newScope (lib.flip (import ./overlay.nix) pkgs);
14+
in
15+
{
16+
inherit (nixForecastPackages) nix-forecast;
17+
}

flake.lock

Lines changed: 0 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 42 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
11
{
22
description = "Check the forecast for today's Nix builds";
33

4-
inputs = {
5-
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
6-
nix-filter.url = "github:numtide/nix-filter";
7-
};
4+
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
85

96
outputs =
107
{
118
self,
129
nixpkgs,
13-
nix-filter,
1410
}:
1511
let
1612
inherit (nixpkgs) lib;
@@ -36,16 +32,24 @@
3632
let
3733
pkgs = nixpkgsFor.${system};
3834
packages = self.packages.${system};
35+
36+
mkCheck =
37+
name: deps: script:
38+
pkgs.runCommand name { nativeBuildInputs = deps; } ''
39+
${script}
40+
touch $out
41+
'';
3942
in
4043
lib.optionalAttrs (lib.elem system supportedSystems) {
41-
version-test = packages.nix-forecast.tests.version;
42-
43-
clippy = packages.nix-forecast.overrideAttrs (oldAttrs: {
44+
clippy = packages.nix-forecast.overrideAttrs {
4445
pname = "check-clippy";
4546

46-
nativeBuildInputs = oldAttrs.nativeBuildInputs ++ [
47+
nativeBuildInputs = [
48+
pkgs.cargo
4749
pkgs.clippy
4850
pkgs.clippy-sarif
51+
pkgs.rustPlatform.cargoSetupHook
52+
pkgs.rustc
4953
pkgs.sarif-fmt
5054
];
5155

@@ -57,36 +61,32 @@
5761
--tests \
5862
--message-format=json \
5963
| clippy-sarif | tee $out | sarif-fmt
64+
runHook postBuild
6065
'';
6166

6267
dontInstall = true;
6368
doCheck = false;
69+
doInstallCheck = false;
6470
dontFixup = true;
6571

6672
passthru = { };
6773
meta = { };
68-
});
69-
70-
formatting =
71-
pkgs.runCommand "check-formatting"
72-
{
73-
nativeBuildInputs = [
74-
pkgs.cargo
75-
pkgs.nixfmt-rfc-style
76-
pkgs.rustfmt
77-
];
78-
}
79-
''
80-
cd ${self}
81-
82-
echo "Running cargo fmt"
83-
cargo fmt -- --check
84-
85-
echo "Running nixfmt..."
86-
nixfmt --check .
87-
88-
touch $out
89-
'';
74+
};
75+
76+
rustfmt = mkCheck "check-cargo-fmt" [
77+
pkgs.cargo
78+
pkgs.rustfmt
79+
] "cd ${self} && cargo fmt -- --check";
80+
81+
actionlint = mkCheck "check-actionlint" [
82+
pkgs.actionlint
83+
] "actionlint ${self}/.github/workflows/*";
84+
85+
deadnix = mkCheck "check-deadnix" [ pkgs.deadnix ] "deadnix --fail ${self}";
86+
87+
nixfmt = mkCheck "check-nixfmt" [ pkgs.nixfmt-rfc-style ] "nixfmt --check ${self}";
88+
89+
statix = mkCheck "check-statix" [ pkgs.statix ] "statix check ${self}";
9090
}
9191
);
9292

@@ -120,96 +120,24 @@
120120

121121
formatter = forAllSystems (system: nixpkgsFor.${system}.nixfmt-rfc-style);
122122

123-
# for CI
124-
legacyPackages = forAllSystems (
125-
system:
126-
lib.optionalAttrs (lib.elem system supportedSystems) (
127-
lib.mapAttrs' (name: lib.nameValuePair "check-${name}") self.checks.${system}
128-
)
129-
);
123+
legacyPackages = forAllSystems (system: {
124+
nix-forecast-debug = self.packages.${system}.nix-forecast.overrideAttrs (
125+
finalAttrs: _: {
126+
cargoBuildType = "debug";
127+
cargoCheckType = finalAttrs.cargoBuildType;
128+
}
129+
);
130+
});
130131

131132
packages = forAllSystems (
132133
system:
133134
let
134135
pkgs = nixpkgsFor.${system};
135-
nixForecastPackages = lib.makeScope pkgs.newScope (final: self.overlays.default final pkgs);
136+
pkgs' = import ./default.nix { inherit pkgs; };
136137
in
137-
{
138-
inherit (nixForecastPackages) nix-forecast;
139-
default = self.packages.${system}.nix-forecast;
140-
}
138+
pkgs' // { default = pkgs'.nix-forecast; }
141139
);
142140

143-
overlays.default = final: _: {
144-
nix-forecast = final.callPackage (
145-
{
146-
lib,
147-
stdenv,
148-
rustPlatform,
149-
darwin,
150-
installShellFiles,
151-
makeBinaryWrapper,
152-
nix,
153-
nix-forecast,
154-
testers,
155-
}:
156-
157-
rustPlatform.buildRustPackage rec {
158-
pname = "nix-forecast";
159-
inherit (passthru.cargoTOML.package) version;
160-
161-
src = nix-filter {
162-
root = self;
163-
include = [
164-
./Cargo.toml
165-
./Cargo.lock
166-
./build.rs
167-
"src"
168-
];
169-
};
170-
171-
cargoLock.lockFile = ./Cargo.lock;
172-
173-
nativeBuildInputs = [
174-
installShellFiles
175-
makeBinaryWrapper
176-
];
177-
178-
buildInputs = lib.optionals stdenv.hostPlatform.isDarwin [
179-
darwin.apple_sdk.frameworks.CoreFoundation
180-
darwin.apple_sdk.frameworks.SystemConfiguration
181-
darwin.libiconv
182-
];
183-
184-
postInstall = ''
185-
wrapProgram $out/bin/nix-forecast --suffix PATH : "${lib.makeBinPath [ nix ]}"
186-
187-
installShellCompletion --cmd nix-forecast \
188-
--bash completions/nix-forecast.bash \
189-
--fish completions/nix-forecast.fish \
190-
--zsh completions/_nix-forecast
191-
'';
192-
193-
env = {
194-
COMPLETION_DIR = "completions";
195-
};
196-
197-
passthru = {
198-
cargoTOML = lib.importTOML ./Cargo.toml;
199-
200-
tests.version = testers.testVersion { package = nix-forecast; };
201-
};
202-
203-
meta = {
204-
description = "Check the forecast for today's Nix builds";
205-
homepage = "https://github.com/getchoo/nix-forecast";
206-
changelog = "https://github.com/getchoo/nix-forecast/releases/tag/${version}";
207-
license = lib.licenses.mpl20;
208-
maintainers = with lib.maintainers; [ getchoo ];
209-
mainProgram = "nix-forecast";
210-
};
211-
}
212-
) { };
213-
};
141+
overlays.default = final: prev: import ./overlay.nix final prev;
214142
};
215143
}

nix/package.nix

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
{
2+
lib,
3+
installShellFiles,
4+
makeBinaryWrapper,
5+
nix,
6+
rustPlatform,
7+
versionCheckHook,
8+
}:
9+
10+
let
11+
fs = lib.fileset;
12+
in
13+
rustPlatform.buildRustPackage rec {
14+
pname = "nix-forecast";
15+
inherit (passthru.cargoTOML.package) version;
16+
17+
src = fs.toSource {
18+
root = ../.;
19+
fileset = fs.intersection (fs.gitTracked ../.) (
20+
fs.unions [
21+
../Cargo.lock
22+
../Cargo.toml
23+
../build.rs
24+
../src
25+
]
26+
);
27+
};
28+
29+
cargoLock.lockFile = ../Cargo.lock;
30+
31+
nativeBuildInputs = [
32+
installShellFiles
33+
makeBinaryWrapper
34+
];
35+
36+
doInstallCheck = true;
37+
nativeInstallCheckInputs = [ versionCheckHook ];
38+
39+
postInstall = ''
40+
wrapProgram $out/bin/nix-forecast --suffix PATH : ${lib.makeBinPath [ nix ]}
41+
42+
installShellCompletion --cmd nix-forecast \
43+
--bash completions/nix-forecast.bash \
44+
--fish completions/nix-forecast.fish \
45+
--zsh completions/_nix-forecast
46+
'';
47+
48+
env = {
49+
COMPLETION_DIR = "completions";
50+
};
51+
52+
passthru = {
53+
cargoTOML = lib.importTOML ../Cargo.toml;
54+
};
55+
56+
meta = {
57+
description = "Check the forecast for today's Nix builds";
58+
homepage = "https://github.com/getchoo/nix-forecast";
59+
changelog = "https://github.com/getchoo/nix-forecast/releases/tag/${version}";
60+
license = lib.licenses.mpl20;
61+
maintainers = with lib.maintainers; [ getchoo ];
62+
mainProgram = "nix-forecast";
63+
};
64+
}

overlay.nix

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
final: _: {
2+
nix-forecast = final.callPackage ./nix/package.nix { };
3+
}

0 commit comments

Comments
 (0)