about summary refs log tree commit diff
path: root/hosts/default.nix
blob: 100cdcc0fc37ebaf676dda92552cdd2eac75df1b (plain) (blame)
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
{
  lib,
  inputs,
  secrets,
  dotfiles,
  hosts,
  hardwares,
  systems,
  isNixOS,
  isMacOS,
  isIso,
  isHardware,
  user,
  nixpkgs,
  home-manager,
  nix-darwin,
  ...
}: let
  mkHost = {
    host,
    hardware,
    stateVersion,
    system,
    timezone,
    location,
    extraOverlays,
    extraModules,
  }: isNixOS: isMacOS: isIso: isHardware: let
    pkgs = import nixpkgs {
      inherit system;
      config = {
        allowUnfree = true;
        allowBroken = true;
        allowUnsupportedSystem = true;
        cudaSupport = false;
      };
      overlays =
        [
          inputs.nur.overlays.default
          inputs.neovim-nightly-overlay.overlays.default
          (import ../packages)
          (import ../overlays)
        ]
        ++ extraOverlays;
    };

    extraArgs = {
      inherit pkgs inputs isIso isHardware user secrets dotfiles timezone location hardware system stateVersion;
      hostname = host + "-" + hardware;
    };

    extraSpecialModules = extraModules ++ lib.optional isHardware ../hardware/${hardware} ++ lib.optional isIso "${nixpkgs}/nixos/modules/installer/cd-dvd/installation-cd-minimal.nix";
  in
    if isNixOS
    then
      nixpkgs.lib.nixosSystem
      {
        inherit system;
        specialArgs = extraArgs;
        modules =
          [
            ./configuration.nix
            ./${host}
            home-manager.nixosModules.home-manager
            {
              home-manager.useGlobalPkgs = true;
              home-manager.useUserPackages = true;
              home-manager.extraSpecialArgs = extraArgs;
              home-manager.users.${user} = {
                imports = [
                  ./home.nix
                  ./${host}/home.nix
                ];
              };
            }
            inputs.nix-index.nixosModules.nix-index
          ]
          ++ extraSpecialModules;
      }
    else if isMacOS
    then
      nix-darwin.lib.darwinSystem
      {
        inherit system;
        specialArgs = extraArgs;
        modules = [
          ./darwin.nix
          home-manager.darwinModules.home-manager
          {
            home-manager.useGlobalPkgs = true;
            home-manager.useUserPackages = true;
            home-manager.extraSpecialArgs = extraArgs;
            home-manager.users."manuel.palenzuela" = {
              imports = [
                ./home-darwin.nix
              ];
            };
          }
        ];
      }
    else
      home-manager.lib.homeManagerConfiguration
      {
        inherit pkgs;
        extraSpecialArgs = extraArgs;
        modules = [
          ./home.nix
          ./${host}/home.nix
        ];
      };

  hardwarePermutatedHosts = lib.concatMap (hardware: map (host: host // hardware) hosts) hardwares;
  systemsPermutatedHosts = lib.concatMap (system: map (host: host // system) hardwarePermutatedHosts) systems;
  permutatedHosts = systemsPermutatedHosts;
in
  /*
  We have a list of sets.
  Map each element of the list applying the mkHost function to its elements and returning a set in the listToAttrs format
  builtins.listToAttrs on the result
  */
  builtins.listToAttrs (map (mInput @ {
      host,
      hardware,
      system,
      ...
    }: {
      name = host + "-" + hardware + "-" + system;
      value = mkHost mInput isNixOS isMacOS isIso isHardware;
    })
    permutatedHosts)