lib: init modules and move mkHosts modules there

This helps to split up the code in mkHosts and creates a place where we
can store modules relevent to devos. It will also be easier to remove
unecessary parts of each module in the future when they are all
compartmentalized.
This commit is contained in:
Pacman99 2021-04-24 08:56:51 -07:00
parent e6f548e723
commit 2d9ea0d27e
4 changed files with 88 additions and 64 deletions

View file

@ -81,7 +81,7 @@
"utils": "utils_2"
},
"locked": {
"narHash": "sha256-7Y6SqdLWr/g8tqNjqakRbS0KVIA/yzRm3D/RnoTAuzE=",
"narHash": "sha256-9mdO1eRrHz/3EAr3M8Ugdc8T6qWu4UbogafqO4mruKo=",
"path": "./lib",
"type": "path"
},

View file

@ -4,70 +4,18 @@
let
defaultSystem = "x86_64-linux";
experimentalFeatures = [
"flakes"
"nix-command"
"ca-references"
"ca-derivations"
];
modules = {
modOverrides = { config, overrideModulesPath, ... }:
let
inherit (overrides) modules disabledModules;
in
{
disabledModules = modules ++ disabledModules;
imports = map
(path: "${overrideModulesPath}/${path}")
modules;
};
global = { config, pkgs, ... }: {
home-manager = {
useGlobalPkgs = true;
useUserPackages = true;
extraSpecialArgs = extern.userSpecialArgs // { suites = suites.user; };
sharedModules = extern.userModules ++ (builtins.attrValues self.homeModules);
};
users.mutableUsers = lib.mkDefault false;
hardware.enableRedistributableFirmware = lib.mkDefault true;
nix.nixPath = [
"nixpkgs=${nixos}"
"nixos-config=${self}/lib/compat/nixos"
"home-manager=${inputs.home}"
];
nixpkgs.pkgs = lib.mkDefault multiPkgs.${config.nixpkgs.system};
nix.registry = {
devos.flake = self;
nixos.flake = nixos;
override.flake = inputs.override;
};
nix.package = pkgs.nixFlakes;
nix.extraOptions = ''
experimental-features = ${lib.concatStringsSep " "
experimentalFeatures
}
'';
system.configurationRevision = lib.mkIf (self ? rev) self.rev;
modules = with lib.modules; {
modOverrides = modOverrides { inherit overrides; };
hmDefaults = hmDefaults {
inherit extern;
inherit (self) homeModules;
userSuites = suites.user;
};
# Everything in `./modules/list.nix`.
flakeModules = { imports = builtins.attrValues self.nixosModules ++ extern.modules; };
cachix = let rootCachix = "${self}/cachix.nix"; in
if builtins.pathExists rootCachix
then rootCachix
else { }
;
globalDefaults = globalDefaults {
inherit self nixos inputs multiPkgs;
};
cachix = cachix { inherit self; };
flakeModules = flakeModules { inherit self extern; };
};
specialArgs = extern.specialArgs // { suites = suites.system; };

View file

@ -16,6 +16,7 @@
attrs = import ./attrs.nix { lib = nixpkgs.lib // self; };
lists = import ./lists.nix { lib = nixpkgs.lib // self; };
strings = import ./strings.nix { lib = nixpkgs.lib // self; };
modules = import ./modules.nix { lib = nixpkgs.lib // self; };
in
utils.lib
@ -51,6 +52,7 @@
filterPackages;
inherit (lists) pathsIn;
inherit (strings) rgxToString;
inherit modules;
}
);

74
lib/modules.nix Normal file
View file

@ -0,0 +1,74 @@
{ lib }:
{
modOverrides = { overrides }:
{ config, overrideModulesPath, ... }:
let
inherit (overrides) modules disabledModules;
in
{
disabledModules = modules ++ disabledModules;
imports = map
(path: "${overrideModulesPath}/${path}")
modules;
};
hmDefaults = { userSuites, extern, homeModules }: {
home-manager = {
useGlobalPkgs = true;
useUserPackages = true;
extraSpecialArgs = extern.userSpecialArgs // { suites = userSuites; };
sharedModules = extern.userModules ++ (builtins.attrValues homeModules);
};
};
globalDefaults = { self, nixos, inputs, multiPkgs }:
let
experimentalFeatures = [
"flakes"
"nix-command"
"ca-references"
"ca-derivations"
];
in
{ config, pkgs, ... }: {
users.mutableUsers = lib.mkDefault false;
hardware.enableRedistributableFirmware = lib.mkDefault true;
nix.nixPath = [
"nixpkgs=${nixos}"
"nixos-config=${self}/lib/compat/nixos"
"home-manager=${inputs.home}"
];
nixpkgs.pkgs = lib.mkDefault multiPkgs.${config.nixpkgs.system};
nix.registry = {
devos.flake = self;
nixos.flake = nixos;
override.flake = inputs.override;
};
nix.package = pkgs.nixFlakes;
nix.extraOptions = ''
experimental-features = ${lib.concatStringsSep " "
experimentalFeatures
}
'';
system.configurationRevision = lib.mkIf (self ? rev) self.rev;
};
cachix = { self }:
let rootCachix = "${self}/cachix.nix"; in
if builtins.pathExists rootCachix
then rootCachix
else { };
flakeModules = { self, extern }: { imports = builtins.attrValues self.nixosModules ++ extern.modules; };
}