summaryrefslogtreecommitdiff
path: root/parts/lib/configs.nix
blob: 9f7ac91d192daf49b4aad79553bda94d2dde4304 (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
{
  inputs,
  self,
  ...
}: let
  inherit (builtins) attrNames elemAt map;
  inherit (inputs.nixpkgs.lib) flatten genAttrs optional splitString;

  archs = ["x86_64" "aarch64"];
  os' = ["linux" "darwin"];
  mkSystems = systems: flatten (map (sys: map (arch: ["${arch}-${sys}" "${arch}-${sys}"]) archs) systems);
  systems = mkSystems os';

  mkSystemCfg = name: {
    profile,
    modules ? profile.modules,
    system ? profile.system,
    specialArgs ? profile.specialArgs,
  }:
    profile.builder {
      inherit specialArgs system;
      modules =
        [../../hosts/${name}]
        ++ (
          if modules == profile.modules
          then modules
          else modules ++ profile.modules
        );
    };
in {
  inherit mkSystemCfg;
  mapSystems = builtins.mapAttrs mkSystemCfg;

  genHMCfgs = users: let
    names = flatten (map (user: map (system: "${user}@${system}") systems) (attrNames users));
  in
    genAttrs names (name: let
      getPart = elemAt (splitString "@" name);
      username = getPart 0;
      system = getPart 1;
    in
      inputs.home-manager.lib.homeManagerConfiguration rec {
        pkgs = import (users.${username}.nixpkgs or inputs.nixpkgs) (
          {inherit system;} // users.${username}.nixpkgsArgs or {}
        );

        extraSpecialArgs = users.${username}.extraSpecialArgs or inputs;

        modules =
          [
            self.homeManagerModules.${username}
            {
              _module.args.osConfig = {};
              programs.home-manager.enable = true;
            }
            ../../users/${username}/home.nix
          ]
          ++ optional pkgs.stdenv.isDarwin ../../users/${username}/darwin.nix
          ++ users.${username}.modules or [];
      });

  genHMModules = users: let
    names = attrNames users;
  in
    genAttrs names (name: import ../../users/${name}/module.nix);
}