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" "utils": "utils_2"
}, },
"locked": { "locked": {
"narHash": "sha256-7Y6SqdLWr/g8tqNjqakRbS0KVIA/yzRm3D/RnoTAuzE=", "narHash": "sha256-9mdO1eRrHz/3EAr3M8Ugdc8T6qWu4UbogafqO4mruKo=",
"path": "./lib", "path": "./lib",
"type": "path" "type": "path"
}, },

View File

@ -4,70 +4,18 @@
let let
defaultSystem = "x86_64-linux"; defaultSystem = "x86_64-linux";
experimentalFeatures = [ modules = with lib.modules; {
"flakes" modOverrides = modOverrides { inherit overrides; };
"nix-command" hmDefaults = hmDefaults {
"ca-references" inherit extern;
"ca-derivations" inherit (self) homeModules;
]; userSuites = suites.user;
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;
}; };
globalDefaults = globalDefaults {
# Everything in `./modules/list.nix`. inherit self nixos inputs multiPkgs;
flakeModules = { imports = builtins.attrValues self.nixosModules ++ extern.modules; }; };
cachix = cachix { inherit self; };
cachix = let rootCachix = "${self}/cachix.nix"; in flakeModules = flakeModules { inherit self extern; };
if builtins.pathExists rootCachix
then rootCachix
else { }
;
}; };
specialArgs = extern.specialArgs // { suites = suites.system; }; specialArgs = extern.specialArgs // { suites = suites.system; };

View File

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