aboutsummaryrefslogtreecommitdiff
path: root/lib/default.nix
blob: 6ad0a1ff7cdb0fa104603948b132b267335ccdc9 (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
{ inputs, ... }:

let
  lib = inputs.nixpkgs.lib;
  isDarwin = s: lib.strings.hasSuffix "-darwin" s;
in
{
  mkSystem =
    {
      host,
      username,
      system,
      overlays ? [ ],
      sharedModules ? [ ],
      extraModules ? [ ],
      extraSpecialArgs ? { },
    }:
    let
      darwinHost = isDarwin system;
      builder = if darwinHost then inputs.nix-darwin.lib.darwinSystem else inputs.nixpkgs.lib.nixosSystem;
      hmModule =
        if darwinHost then
          inputs.home-manager.darwinModules.home-manager
        else
          inputs.home-manager.nixosModules.home-manager;
      hostDir = ../hosts/${host};
      hostCfg = hostDir + /configuration.nix;
      hostHome = hostDir + /home.nix;

      hmEnabled = builtins.pathExists hostHome;

      nixpkgsModule = {
        nix.settings.experimental-features = [
          "nix-command"
          "flakes"
        ];
        nixpkgs.overlays = overlays;
        nixpkgs.config.allowUnfree = true;
      };

      modules = [
        hostCfg
        nixpkgsModule
      ]
      ++ lib.optionals darwinHost [ inputs.mac-app-util.darwinModules.default ]
      ++ lib.optionals hmEnabled [
        hmModule
        {
          home-manager.useGlobalPkgs = true;
          home-manager.useUserPackages = true;
          home-manager.backupFileExtension = "backup";
          home-manager.extraSpecialArgs = {
            inherit
              inputs
              system
              host
              username
              ;
          }
          // extraSpecialArgs;
          home-manager.users.${username} = import hostHome;
          home-manager.sharedModules =
            sharedModules ++ lib.optional darwinHost inputs.mac-app-util.homeManagerModules.default;
        }
      ]
      ++ extraModules;
    in
    builder {
      system = system;
      specialArgs = (
        {
          inherit
            inputs
            system
            host
            username
            ;
        }
        // extraSpecialArgs
      );
      modules = modules;
    };
}