Skip to content

Commit

Permalink
Refactor a bit module propagation
Browse files Browse the repository at this point in the history
  • Loading branch information
dwarfmaster committed Nov 22, 2022
1 parent c7255a4 commit 5002186
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 46 deletions.
68 changes: 34 additions & 34 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
arkenfox }:
let
# All overlays to apply
finalOverlays = self.overlays // {
overlays = self.overlays // {
nur = nur.overlay;
arkenfox = arkenfox.overlay;
packages = self: super: {
Expand All @@ -74,25 +74,28 @@
} // packages self super;
variants = self: super: pkgs-variants super.system;
};
# Modules to be made available to hosts config
finalModules = self.nixosModules // {
inherit libModule;
profiles = { ... }: { imports = nixosProfiles; };
mailserver = simple-mailserver.nixosModules.mailserver;
home-manager = home.nixosModules.home-manager;
imacs = imacs.nixosModules.imacs;
impermanence = impermanence.nixosModule;
};
# HM Modules to be made available to profiles
finalHMModules = system: self.hmModules // {
inherit libModule;
profiles = { ... }: { imports = hmProfiles; };
rycee-base16 = (nur-no-pkgs system).repos.rycee.hmModules.theme-base16;
nix-doom-emacs = nix-doom-emacs.hmModule;
arkenfox = arkenfox.hmModules.default;
nixvim = nixvim.homeManagerModules.nixvim;
colors = colors.homeManagerModules.colorScheme;
impermanence = impermanence.nixosModules.home-manager.impermanence;
# Modules to be made available to configs
modules = {
nixos = self.nixosModules // {
inherit libModule;
profiles = { ... }: { imports = profiles.nixos; };
nur = nur.nixosModules.nur;
mailserver = simple-mailserver.nixosModules.mailserver;
home-manager = home.nixosModules.home-manager;
imacs = imacs.nixosModules.imacs;
impermanence = impermanence.nixosModule;
};
hm = self.hmModules // {
inherit libModule;
profiles = { ... }: { imports = profiles.hm; };
nur = nur.hmModules.nur;
rycee-base16 = nur-modules.repos.rycee.hmModules.theme-base16;
nix-doom-emacs = nix-doom-emacs.hmModule;
arkenfox = arkenfox.hmModules.default;
nixvim = nixvim.homeManagerModules.nixvim;
colors = colors.homeManagerModules.colorScheme;
impermanence = impermanence.nixosModules.home-manager.impermanence;
};
};
# All attributes to add to lib in modules
extraLib = {
Expand All @@ -116,13 +119,15 @@
eachSupportedSystem = f: builtins.listToAttrs
(map (system: lib.nameValuePair system (f system)) supportedSystems);

nixosProfiles = importProfiles ./profiles/nixos;
hmProfiles = importProfiles ./profiles/hm;
profiles = {
nixos = importProfiles ./profiles/nixos;
hm = importProfiles ./profiles/hm;
};

pkgImport = system: unfree: pkgs:
import pkgs {
inherit system;
overlays = attrValues finalOverlays;
overlays = attrValues overlays;
config = { allowUnfree = unfree; };
};

Expand All @@ -136,26 +141,21 @@

packages = import ./packages;

pkgs = system: import nixos {
inherit system;
config = { allowUnfree = false; };
overlays = attrValues finalOverlays;
};

nur-no-pkgs = system: import nur {
nurpkgs = pkgImport system false nixos;
nur-modules = import nur {
# Architecture is hardcoded since it won't be used by modules
nurpkgs = import nixos { system = "x86_64-linux"; };
};

libModule = { pkgs, lib, ... }@args: {
lib = utils.recImport { dir = ./lib; _import = base: import "${./lib}/${base}.nix" args; } // {
utils = import ./utils.nix args;
};
} // extraLib;
};

hosts =
import ./hosts ({
inherit self pkgs lib;
inherit finalOverlays finalModules finalHMModules;
inherit self lib;
inherit overlays modules;
});

in {
Expand Down
20 changes: 8 additions & 12 deletions hosts/default.nix
Original file line number Diff line number Diff line change
@@ -1,23 +1,20 @@
{ lib
, pkgs
, self
, finalOverlays
, finalModules
, finalHMModules
, overlays
, modules
}:
let
inherit (lib) types utils;
inherit (utils) recImport;
inherit (lib) types;
inherit (builtins) attrValues removeAttrs;

modules = hostName: system:
host-modules = hostName: system:
let
global = {
profiles.core.enable = lib.mkDefault true;

home-manager.useGlobalPkgs = true;
home-manager.useUserPackages = true;
home-manager.sharedModules = builtins.attrValues (finalHMModules system);
home-manager.sharedModules = builtins.attrValues modules.hm;

networking.hostName = hostName;
nix.nixPath = let path = toString ../.; in
Expand All @@ -31,7 +28,7 @@ let

# Will use the nixpkgs from which nixosSystem is called
nixpkgs = {
overlays = builtins.attrValues finalOverlays;
overlays = builtins.attrValues overlays;
config = {
allowUnfree = false;
};
Expand All @@ -48,12 +45,11 @@ let

local = import "${toString ./.}/${hostName}.nix";
in
(attrValues finalModules) ++ [ global local ];
(attrValues modules.nixos) ++ [ global local ];

mkHost = hostname: system: {
modules = modules hostname system;
modules = host-modules hostname system;
inherit system;
pkgs = pkgs system;
};

in {
Expand Down

0 comments on commit 5002186

Please sign in to comment.