[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; inherit system;
modules = baseModules ++ modules; modules = baseModules ++ modules;
specialArgs = { inherit inputs; } // specialArgs; specialArgs = { inherit inputs; } // specialArgs;
makeEnable = (import ../make-enable.nix) nixpkgs.lib;
}); });
machinesPath = ../machines; machinesPath = ../machines;
machineFilenames = builtins.attrNames (builtins.readDir machinesPath); machineFilenames = builtins.attrNames (builtins.readDir machinesPath);

View File

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

View File

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

View File

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

View File

@ -1,4 +1,4 @@
inputs: { pkgs, config, ... }: { { pkgs, config, specialArgs, ... }: {
xsession = { xsession = {
enable = true; enable = true;
preferStatusNotifierItems = true; preferStatusNotifierItems = true;
@ -33,7 +33,7 @@ inputs: { pkgs, config, ... }: {
services.taffybar = { services.taffybar = {
enable = true; enable = true;
package = inputs.imalison-taffybar.defaultPackage."${pkgs.system}"; package = specialArgs.nixos.specialArgs.inputs.imalison-taffybar.defaultPackage."${pkgs.system}";
}; };
services.notify-osd = { 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 = { nix = {
extraOptions = '' extraOptions = ''
experimental-features = nix-command flakes 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; [ nixpkgs.overlays = with inputs; [
xmonad.overlay xmonad.overlay
xmonad-contrib.overlay xmonad-contrib.overlay
@ -31,7 +31,5 @@
haskellPackages.dbus-hslogger haskellPackages.dbus-hslogger
]; ];
home-manager.useGlobalPkgs = true; home-manager.users.imalison = (import ./home-manager.nix);
home-manager.useUserPackages = true;
home-manager.users.imalison = (import ./home-manager.nix) inputs;
} }