Skip to content

Commit 3941a00

Browse files
authored
Merge pull request #429 from nix-community/flake-restructure
Restructure flake into flake-modules named by the flake output
2 parents 1d1b5bc + 1d86794 commit 3941a00

21 files changed

+141
-131
lines changed

nix/checks/effects.nix renamed to checks/effects.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
{ pkgs, ... }:
77
{
88
environment.systemPackages = [
9-
(pkgs.python3.pkgs.callPackage ../../nix/buildbot-effects.nix { })
9+
(pkgs.python3.pkgs.callPackage ../packages/buildbot-effects.nix { })
1010
];
1111
};
1212
};

checks/flake-module.nix

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{ self, ... }:
2+
{
3+
perSystem =
4+
{
5+
self',
6+
system,
7+
pkgs,
8+
lib,
9+
...
10+
}:
11+
{
12+
checks =
13+
let
14+
# this gives us a reference to our flake but also all flake inputs
15+
checkArgs = {
16+
inherit self pkgs;
17+
};
18+
nixosMachines = lib.mapAttrs' (
19+
name: config: lib.nameValuePair "nixos-${name}" config.config.system.build.toplevel
20+
) ((lib.filterAttrs (name: _: lib.hasSuffix system name)) self.nixosConfigurations);
21+
packages = lib.mapAttrs' (n: lib.nameValuePair "package-${n}") self'.packages;
22+
devShells = lib.mapAttrs' (n: lib.nameValuePair "devShell-${n}") self'.devShells;
23+
in
24+
nixosMachines
25+
// packages
26+
// devShells
27+
// lib.mkIf (pkgs.stdenv.hostPlatform.isLinux) {
28+
master = import ./master.nix checkArgs;
29+
worker = import ./worker.nix checkArgs;
30+
effects = import ./effects.nix checkArgs;
31+
};
32+
};
33+
}
File renamed without changes.
File renamed without changes.
File renamed without changes.

devShells/flake-module.nix

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
perSystem =
3+
{ pkgs, ... }:
4+
{
5+
devShells.default = pkgs.mkShell {
6+
packages = [
7+
pkgs.bashInteractive
8+
pkgs.mypy
9+
pkgs.ruff
10+
];
11+
};
12+
};
13+
}

examples/flake-module.nix

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{ self, inputs, ... }:
2+
{
3+
flake = {
4+
nixosConfigurations =
5+
let
6+
examplesFor =
7+
system:
8+
import ../examples {
9+
inherit system;
10+
inherit (inputs) nixpkgs;
11+
buildbot-nix = self;
12+
};
13+
in
14+
examplesFor "x86_64-linux" // examplesFor "aarch64-linux";
15+
};
16+
}

flake.nix

Lines changed: 20 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -17,104 +17,27 @@
1717
};
1818

1919
outputs =
20-
inputs@{ self, flake-parts, ... }:
21-
flake-parts.lib.mkFlake { inherit inputs; } (
22-
{
23-
lib,
24-
config,
25-
withSystem,
26-
...
27-
}:
28-
{
29-
imports =
30-
[
31-
./nix/checks/flake-module.nix
32-
]
33-
++ inputs.nixpkgs.lib.optional (inputs.treefmt-nix ? flakeModule) ./nix/treefmt/flake-module.nix
34-
++ inputs.nixpkgs.lib.optionals (inputs.hercules-ci-effects ? flakeModule) [
35-
inputs.hercules-ci-effects.flakeModule
36-
{
37-
herculesCI = herculesCI: {
38-
onPush.default.outputs.effects.deploy = withSystem config.defaultEffectSystem (
39-
{ pkgs, hci-effects, ... }:
40-
hci-effects.runIf (herculesCI.config.repo.branch == "main") (
41-
hci-effects.mkEffect {
42-
effectScript = ''
43-
echo "${builtins.toJSON { inherit (herculesCI.config.repo) branch tag rev; }}"
44-
${pkgs.hello}/bin/hello
45-
'';
46-
}
47-
)
48-
);
49-
};
50-
}
51-
];
52-
systems = [
53-
"x86_64-linux"
54-
"aarch64-linux"
55-
"aarch64-darwin"
20+
inputs@{ flake-parts, ... }:
21+
flake-parts.lib.mkFlake { inherit inputs; } {
22+
imports =
23+
[
24+
./examples/flake-module.nix
25+
./devShells/flake-module.nix
26+
./nixosModules/flake-module.nix
27+
./checks/flake-module.nix
28+
./packages/flake-module.nix
29+
]
30+
++ inputs.nixpkgs.lib.optional (inputs.treefmt-nix ? flakeModule) ./formatter/flake-module.nix
31+
++ inputs.nixpkgs.lib.optionals (inputs.hercules-ci-effects ? flakeModule) [
32+
inputs.hercules-ci-effects.flakeModule
33+
./herculesCI/flake-module.nix
5634
];
5735

58-
flake = {
59-
nixosModules.buildbot-master.imports = [
60-
./nix/master.nix
61-
];
36+
systems = [
37+
"x86_64-linux"
38+
"aarch64-linux"
39+
"aarch64-darwin"
40+
];
6241

63-
nixosModules.buildbot-worker.imports = [
64-
./nix/worker.nix
65-
];
66-
67-
nixosConfigurations =
68-
let
69-
examplesFor =
70-
system:
71-
import ./examples {
72-
inherit system;
73-
inherit (inputs) nixpkgs;
74-
buildbot-nix = self;
75-
};
76-
in
77-
examplesFor "x86_64-linux" // examplesFor "aarch64-linux";
78-
79-
lib = import ./nix/lib.nix;
80-
};
81-
perSystem =
82-
{
83-
self',
84-
pkgs,
85-
system,
86-
...
87-
}:
88-
{
89-
packages =
90-
{
91-
default = pkgs.mkShell {
92-
packages = [
93-
pkgs.bashInteractive
94-
pkgs.mypy
95-
pkgs.ruff
96-
];
97-
};
98-
# useful for checking what buildbot version is used.
99-
buildbot = pkgs.buildbot;
100-
buildbot-nix = pkgs.python3.pkgs.callPackage ./nix/buildbot-nix.nix { };
101-
buildbot-gitea = pkgs.python3.pkgs.callPackage ./nix/buildbot-gitea.nix {
102-
buildbot = pkgs.buildbot;
103-
};
104-
}
105-
// lib.optionalAttrs pkgs.stdenv.isLinux {
106-
buildbot-effects = pkgs.python3.pkgs.callPackage ./nix/buildbot-effects.nix { };
107-
};
108-
checks =
109-
let
110-
nixosMachines = lib.mapAttrs' (
111-
name: config: lib.nameValuePair "nixos-${name}" config.config.system.build.toplevel
112-
) ((lib.filterAttrs (name: _: lib.hasSuffix system name)) self.nixosConfigurations);
113-
packages = lib.mapAttrs' (n: lib.nameValuePair "package-${n}") self'.packages;
114-
devShells = lib.mapAttrs' (n: lib.nameValuePair "devShell-${n}") self'.devShells;
115-
in
116-
nixosMachines // packages // devShells;
117-
};
118-
}
119-
);
42+
};
12043
}
File renamed without changes.

herculesCI/flake-module.nix

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
config,
3+
withSystem,
4+
...
5+
}:
6+
{
7+
herculesCI = herculesCI: {
8+
onPush.default.outputs.effects.deploy = withSystem config.defaultEffectSystem (
9+
{ pkgs, hci-effects, ... }:
10+
hci-effects.runIf (herculesCI.config.repo.branch == "main") (
11+
hci-effects.mkEffect {
12+
effectScript = ''
13+
echo "${builtins.toJSON { inherit (herculesCI.config.repo) branch tag rev; }}"
14+
${pkgs.hello}/bin/hello
15+
'';
16+
}
17+
)
18+
);
19+
};
20+
}

0 commit comments

Comments
 (0)