aboutsummaryrefslogblamecommitdiff
path: root/nix/lib/mkSystem.nix
blob: c069a3fb7f7ce106a6290b8d5f99d6621ee687fc (plain) (tree)
1
2
3
4
5
6
7
8
9

                                                                  
 
       



           
 
           




                 


                                     
                                            


                                                                              
                                 




                                                                                           





                                          


                                    
                                   
                                      
 





                                          


                                                
                                                        








                                       
                                                     
        






                                                                         
                                       





                                 
# This function creates a NixOS system based on our VM setup for a
# particular architecture.
{
  self,
  nixpkgs,
  inputs,
  overlays,
}:

systemName:
{
  system,
  user,
  darwin ? false,
}:

let
  # The config files for this system.
  machineConfig = ../machines/${systemName};
  userOSConfig = ../users/${user}/${if darwin then "darwin" else "nixos"}.nix;
  userHMConfig = ../users/${user}/home-manager.nix;

  # NixOS vs nix-darwin functions
  systemFunc = if darwin then inputs.darwin.lib.darwinSystem else nixpkgs.lib.nixosSystem;
  home-manager =
    if darwin then inputs.home-manager.darwinModules else inputs.home-manager.nixosModules;
in
systemFunc rec {
  inherit system;

  modules = [
    # Allow unfree packages.
    { nixpkgs.config.allowUnfree = true; }

    # Add overlays
    { nixpkgs.overlays = overlays; }

    inputs.disko.nixosModules.disko
    inputs.agenix.nixosModules.default

    machineConfig
    userOSConfig
    home-manager.home-manager
    {
      home-manager.useGlobalPkgs = true;
      home-manager.useUserPackages = true;
      home-manager.sharedModules = [
        inputs.agenix.homeManagerModules.default
      ];
      home-manager.users.${user} = import userHMConfig {
        inherit
          self
          inputs
          darwin
          systemName
          ;
      };
      home-manager.extraSpecialArgs = {
        inherit self inputs;
        configPath = "${self}/configs/users/${user}";
      };
    }

    # We expose some extra arguments so that our modules can parameterize
    # better based on these values.
    {
      config._module.args = {
        currentSystem = system;
        currentSystemName = systemName;
        currentSystemUser = user;
        inputs = inputs;
      };
    }
  ];
}