summaryrefslogtreecommitdiff
path: root/flake.nix
blob: ecb7b72f1d23dd1f19312a95c97c55b1e3259020 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
{
  description = "Personal monorepo";

  inputs = {
    nixpkgs.url = "github:nixos/nixpkgs/nixos-24.11";

    disko.url = "github:nix-community/disko/v1.6.1";
    disko.inputs.nixpkgs.follows = "nixpkgs";

    sops-nix.url = "github:Mic92/sops-nix";
    sops-nix.inputs.nixpkgs.follows = "nixpkgs";

    nixos-hardware.url = "github:nixos/nixos-hardware/master";
  };

  outputs = { self, nixpkgs, ... } @ inputs:
    let
      inherit (builtins)
        attrNames
        filter
        listToAttrs
        map
        readDir
        ;

      inherit (nixpkgs.lib)
        nixosSystem
        ;

      readTree = import ./mod/nix/readTree { };

      # Recursively converts subdirectories under ./mod into an attrset
      # that can be passed to other parts of the depot.
      readDepot = depotArgs: readTree {
        args = depotArgs;
        path = ./mod;
      };

      # Named arguments to be made available to any nix expression in
      # the depot module.
      depot = readTree.fix (self: readDepot {
        depot = self;

        # x86_64-linux is hardcoded as the package arch only for the
        # mod directory. This workaround keeps the flake pure,
        # at the expense of only supporting one system. This can
        # be circumvented by retrieving the system during evaluation,
        # but flakes disallow this by design.
        #
        # This monorepo currently depends on functionality from flakes,
        # but this may change in the future, perhaps shifting to an
        # impure base with certain packages exposed from the flake in a
        # pure way.
        #
        # In practice, this means that any configuration or package
        # exposed from the depot flake that makes use of internal
        # derivations is limited to x86_64-linux. For now this is fine,
        # but ideally any architecture supported by nix should be
        # allowed to evaluate projects hosted here.
        pkgs = nixpkgs.legacyPackages."x86_64-linux";

        # Expose lib attribute to modules.
        lib = nixpkgs.lib;
      });

      machines = filter (m: m != "iso" && m != "xnet")
        (attrNames (readDir ./machines));
    in
    {
      inherit depot;

      nixosModules.xnet.imports =
        [ ./machines/xnet inputs.disko.nixosModules.disko ];

      nixosConfigurations = listToAttrs (
        map
          (name: {
            inherit name;
            value = nixosSystem {
              system = "x86_64-linux";
              specialArgs = { inherit inputs depot; };
              modules = [
                # Machine's specific configuration
                ./machines/${name}

                # Implicitly import xnet
                self.nixosModules.xnet

                # Global module
                ({ inputs, ... }: {

                  # Set system nixpkgs to flake input
                  nix.registry.nixpkgs.flake = inputs.nixpkgs;
                })
              ];
            };
          })
          machines);
    };
}