[NixOS] Add make-enable to control nixos modules with configuration

This commit is contained in:
Ivan Malison 2023-08-19 22:54:14 -06:00
parent d93b8da859
commit 4c6625ce50
8 changed files with 48 additions and 11 deletions

View File

@ -43,6 +43,7 @@
inherit system;
modules = baseModules ++ modules;
specialArgs = { inherit inputs; } // specialArgs;
makeEnable = (import ../make-enable.nix) nixpkgs.lib;
});
machinesPath = ../machines;
machineFilenames = builtins.attrNames (builtins.readDir machinesPath);

View File

@ -2,7 +2,6 @@
{
imports = [
./fonts.nix
inputs.home-manager.nixosModule
];
services.xserver = {

View File

@ -1,4 +1,6 @@
{ config, pkgs, options, lib, inputs, ... }:
let libDir = "${config.dotfiles-directory}/dotfiles/lib";
in
with lib;
{
options = {
@ -8,8 +10,7 @@ with lib;
};
};
config = let libDir = "${config.dotfiles-directory}/dotfiles/lib";
in {
config = {
# Shell configuration
programs.zsh = {
enable = true;

View File

@ -131,6 +131,7 @@
myPackages = {
taffybar = inputs.imalison-taffybar.defaultPackage."${system}";
};
makeEnable = (import ./make-enable.nix) nixpkgs.lib;
} // specialArgs;
});
machinesFilepath = ./machines;

View File

@ -1,4 +1,4 @@
inputs: { pkgs, config, ... }: {
{ pkgs, config, specialArgs, ... }: {
xsession = {
enable = true;
preferStatusNotifierItems = true;
@ -33,7 +33,7 @@ inputs: { pkgs, config, ... }: {
services.taffybar = {
enable = true;
package = inputs.imalison-taffybar.defaultPackage."${pkgs.system}";
package = specialArgs.nixos.specialArgs.inputs.imalison-taffybar.defaultPackage."${pkgs.system}";
};
services.notify-osd = {

26
nixos/make-enable.nix Normal file
View File

@ -0,0 +1,26 @@
lib: config: pathStr: default: configAttrs:
let
pathToAttrSet = str: value:
let
parts = lib.splitString "." str;
in
if lib.length parts == 1 then
{ ${lib.head parts} = value; }
else
{ ${lib.head parts} = pathToAttrSet (lib.concatStringsSep "." (lib.tail parts)) value; };
optionsSet = pathToAttrSet pathStr {
enable = lib.mkOption {
inherit default;
type = lib.types.bool;
};
};
cfg = lib.attrByPath (lib.splitString "." pathStr) { enable = false; defaulted = true; } config;
in
{
options = optionsSet;
config = lib.mkIf cfg.enable configAttrs;
}

View File

@ -1,5 +1,16 @@
{ inputs, ... }:
{ inputs, specialArgs, config, ... }:
{
imports = [
inputs.home-manager.nixosModule
];
home-manager.extraSpecialArgs = {
nixos = {
inherit specialArgs config;
};
};
home-manager.useGlobalPkgs = true;
home-manager.useUserPackages = true;
nix = {
extraOptions = ''
experimental-features = nix-command flakes

View File

@ -1,5 +1,5 @@
{ config, pkgs, options, inputs, ... }:
{
{ config, pkgs, options, inputs, specialArgs, ... }:
specialArgs.makeEnable config "modules.xmonad" true {
nixpkgs.overlays = with inputs; [
xmonad.overlay
xmonad-contrib.overlay
@ -31,7 +31,5 @@
haskellPackages.dbus-hslogger
];
home-manager.useGlobalPkgs = true;
home-manager.useUserPackages = true;
home-manager.users.imalison = (import ./home-manager.nix) inputs;
home-manager.users.imalison = (import ./home-manager.nix);
}