a flake module to ease creating and managing multiple hosts in your nix flake.
1{
2 inputs = {
3 nixpkgs.url = "https://channels.nixos.org/nixpkgs-unstable/nixexprs.tar.xz";
4
5 # you need nixos/nix >= 2.28 to eval this flake
6 easy-hosts.url = "path:../.";
7
8 flake-parts = {
9 url = "github:hercules-ci/flake-parts";
10 inputs.nixpkgs-lib.follows = "nixpkgs";
11 };
12
13 };
14
15 outputs =
16 inputs:
17 inputs.flake-parts.lib.mkFlake { inherit inputs; } {
18 # required for eval
19 systems = [ "x86_64-linux" ];
20
21 # do the thing
22 imports = [ inputs.easy-hosts.flakeModule ];
23
24 easy-hosts = {
25 # add our system tags
26 perTag = tag: {
27 modules = [
28 { system.nixos.tags = [ tag ]; }
29 ];
30 };
31
32 # setup grub as the bootloader if the class is nixos
33 # if this doesn't run then well classes are broken
34 perClass = class: {
35 modules =
36 if class == "nixos" then
37 [
38 {
39 boot.loader.grub = {
40 enable = true;
41 device = "/dev/sda";
42 };
43 }
44 ]
45 else
46 [ ];
47 };
48
49 # finally do the thing we all came for
50 hosts = {
51 test1 = {
52 class = "nixos";
53 arch = "x86_64";
54
55 # test some tags
56 tags = [
57 "laptop"
58 "headless"
59 ];
60
61 modules = [
62 {
63 # remove fs assertion
64 fileSystems."/".label = "root";
65 }
66 ];
67 };
68 };
69 };
70 };
71}