about summary refs log tree commit diff
path: root/lib/mk_system.nix
blob: c9d2705c22e235ef1f32b9362c38daa3fde8eb51 (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
{ self, unstable, colmena, ... } @ args:
{
  mkSystem = { name, nixpkgs ? unstable, system ? "x86_64-linux", overlays ? null, extraModules ? null }:
    nixpkgs.lib.nixosSystem (
      let
        configFolder = "${self}/nixos";
        entryPoint = "${configFolder}/${name}/configuration.nix";
        hardware = "${configFolder}/${name}/hardware-configuration.nix";
      in
      {
        system = system;

        specialArgs = args;

        modules = [
          {
            networking.hostName = name;
            nix.flakes.enable = true;
            system.configurationRevision = self.rev or "dirty";
            documentation.man = { enable = true; generateCaches = true; };
          }
          entryPoint
          hardware
        ] ++ self.lib.mapModulesRec' ../modules import
        ++ nixpkgs.lib.optional (overlays != null) { nixpkgs.overlays = overlays; }
        ++ nixpkgs.lib.optionals (extraModules != null) extraModules;

        # let deployment options to be set without breaking eval on nixosConfigurations
        extraModules = [ colmena.nixosModules.deploymentOptions ];
      }
    );

  mkColmenaFromNixOSConfigurations = conf:
    {
      meta = {
        # Colmena requirement. Will be overridden in nodeNixpkgs.
        nixpkgs = import unstable { system = "x86_64-linux"; };
        nodeNixpkgs = builtins.mapAttrs (_: value: value.pkgs) conf;
        nodeSpecialArgs = builtins.mapAttrs (_: value: value._module.specialArgs) conf;
      };
    } // builtins.mapAttrs (_: value: { imports = value._module.args.modules; }) conf;

  mkHydraFromNixOSConfigurations = conf:
    unstable.lib.mapAttrs' (name: value: { name = "nixos-${name}"; value = value.config.system.build.toplevel; }) conf;
}