1let
2 pinned = (builtins.fromJSON (builtins.readFile ./pinned.json)).pins;
3in
4{
5 system ? builtins.currentSystem,
6
7 nixpkgs ? null,
8 nixPath ? "nixVersions.latest",
9}:
10let
11 nixpkgs' =
12 if nixpkgs == null then
13 fetchTarball {
14 inherit (pinned.nixpkgs) url;
15 sha256 = pinned.nixpkgs.hash;
16 }
17 else
18 nixpkgs;
19
20 pkgs = import nixpkgs' {
21 inherit system;
22 # Nixpkgs generally — and CI specifically — do not use aliases,
23 # because we want to ensure they are not load-bearing.
24 allowAliases = false;
25 };
26
27 fmt =
28 let
29 treefmtNixSrc = fetchTarball {
30 inherit (pinned.treefmt-nix) url;
31 sha256 = pinned.treefmt-nix.hash;
32 };
33 treefmtEval = (import treefmtNixSrc).evalModule pkgs {
34 # Important: The auto-rebase script uses `git filter-branch --tree-filter`,
35 # which creates trees within the Git repository under `.git-rewrite/t`,
36 # notably without having a `.git` themselves.
37 # So if this projectRootFile were the default `.git/config`,
38 # having the auto-rebase script use treefmt on such a tree would make it
39 # format all files in the _parent_ Git tree as well.
40 projectRootFile = ".git-blame-ignore-revs";
41
42 # Be a bit more verbose by default, so we can see progress happening
43 settings.verbose = 1;
44
45 # By default it's info, which is too noisy since we have many unmatched files
46 settings.on-unmatched = "debug";
47
48 programs.actionlint.enable = true;
49
50 programs.biome = {
51 enable = true;
52 settings.formatter = {
53 useEditorconfig = true;
54 };
55 settings.javascript.formatter = {
56 quoteStyle = "single";
57 semicolons = "asNeeded";
58 };
59 settings.json.formatter.enabled = false;
60 };
61 settings.formatter.biome.excludes = [
62 "*.min.js"
63 "pkgs/*"
64 ];
65
66 programs.keep-sorted.enable = true;
67
68 # This uses nixfmt underneath, the default formatter for Nix code.
69 # See https://github.com/NixOS/nixfmt
70 programs.nixfmt = {
71 enable = true;
72 package = pkgs.nixfmt;
73 };
74
75 programs.yamlfmt = {
76 enable = true;
77 settings.formatter = {
78 retain_line_breaks = true;
79 };
80 };
81 settings.formatter.yamlfmt.excludes = [
82 # Breaks helm templating
83 "nixos/tests/k3s/k3s-test-chart/templates/*"
84 # Aligns comments with whitespace
85 "pkgs/development/haskell-modules/configuration-hackage2nix/main.yaml"
86 # TODO: Fix formatting for auto-generated file
87 "pkgs/development/haskell-modules/configuration-hackage2nix/transitive-broken.yaml"
88 ];
89
90 settings.formatter.editorconfig-checker = {
91 command = "${pkgs.lib.getExe pkgs.editorconfig-checker}";
92 options = [ "-disable-indent-size" ];
93 includes = [ "*" ];
94 priority = 1;
95 };
96
97 # TODO: Upstream this into treefmt-nix eventually:
98 # https://github.com/numtide/treefmt-nix/issues/387
99 settings.formatter.markdown-code-runner = {
100 command = pkgs.lib.getExe pkgs.markdown-code-runner;
101 options =
102 let
103 config = pkgs.writers.writeTOML "markdown-code-runner-config" {
104 presets.nixfmt = {
105 language = "nix";
106 command = [ (pkgs.lib.getExe pkgs.nixfmt) ];
107 };
108 };
109 in
110 [ "--config=${config}" ];
111 includes = [ "*.md" ];
112 };
113 };
114 fs = pkgs.lib.fileset;
115 nixFilesSrc = fs.toSource {
116 root = ../.;
117 fileset = fs.difference ../. (fs.maybeMissing ../.git);
118 };
119 in
120 {
121 shell = treefmtEval.config.build.devShell;
122 pkg = treefmtEval.config.build.wrapper;
123 check = treefmtEval.config.build.check nixFilesSrc;
124 };
125
126in
127rec {
128 inherit pkgs fmt;
129 requestReviews = pkgs.callPackage ./request-reviews { };
130 codeownersValidator = pkgs.callPackage ./codeowners-validator { };
131
132 # FIXME(lf-): it might be useful to test other Nix implementations
133 # (nixVersions.stable and Lix) here somehow at some point to ensure we don't
134 # have eval divergence.
135 eval = pkgs.callPackage ./eval {
136 nix = pkgs.lib.getAttrFromPath (pkgs.lib.splitString "." nixPath) pkgs;
137 };
138
139 # CI jobs
140 lib-tests = import ../lib/tests/release.nix { inherit pkgs; };
141 manual-nixos = (import ../nixos/release.nix { }).manual.${system} or null;
142 manual-nixpkgs = (import ../doc { inherit pkgs; });
143 manual-nixpkgs-tests = (import ../doc { inherit pkgs; }).tests;
144 nixpkgs-vet = pkgs.callPackage ./nixpkgs-vet.nix {
145 nix = pkgs.nixVersions.latest;
146 };
147 parse = pkgs.lib.recurseIntoAttrs {
148 latest = pkgs.callPackage ./parse.nix { nix = pkgs.nixVersions.latest; };
149 lix = pkgs.callPackage ./parse.nix { nix = pkgs.lix; };
150 nix_2_28 = pkgs.callPackage ./parse.nix { nix = pkgs.nixVersions.nix_2_28; };
151 };
152 shell = import ../shell.nix { inherit nixpkgs system; };
153 tarball = import ../pkgs/top-level/make-tarball.nix {
154 # Mirrored from top-level release.nix:
155 nixpkgs = {
156 outPath = pkgs.lib.cleanSource ../.;
157 revCount = 1234;
158 shortRev = "abcdef";
159 revision = "0000000000000000000000000000000000000000";
160 };
161 officialRelease = false;
162 inherit pkgs lib-tests;
163 nix = pkgs.nixVersions.latest;
164 };
165}