From 1c1174edd39c5a23eaeb29c667f1a74a4b642789 Mon Sep 17 00:00:00 2001 From: Grey Jones Date: Fri, 28 Aug 2026 04:07:48 +0100 Subject: [PATCH] add function to mirror system config in home config --- modules/components/shells/noctalia.nix | 2 +- modules/components/window-managers/niri.nix | 2 +- modules/features/applications/gui/floorp.nix | 6 +-- modules/features/applications/gui/kitty.nix | 6 ++- .../features/applications/gui/nautilus.nix | 6 ++- modules/features/applications/gui/vscode.nix | 6 ++- modules/features/shells/zsh.nix | 4 +- modules/global/helpers.nix | 43 ++++++++++++++++++- modules/global/home.nix | 4 +- modules/hosts/kitagawa/kitagawa.nix | 10 ++--- 10 files changed, 69 insertions(+), 20 deletions(-) diff --git a/modules/components/shells/noctalia.nix b/modules/components/shells/noctalia.nix index c7c66f8..7bcb4de 100644 --- a/modules/components/shells/noctalia.nix +++ b/modules/components/shells/noctalia.nix @@ -10,7 +10,7 @@ }; flake.homeModules.graphics = { lib, pkgs, osConfig, config, ... }: { - config = lib.mkIf (builtins.hasAttr "osConfig" self) (lib.mkIf ((osConfig.components.shells == "noctalia")||(builtins.elem "noctalia" osConfig.components.shells)) { + config = lib.mkIf (builtins.tryEval osConfig).success (lib.mkIf ((osConfig.components.shells == "noctalia")||(builtins.elem "noctalia" osConfig.components.shells)) { home.activation = { symlinkNoctaliaState = lib.hm.dag.entryAfter ["writeBoundary"] (config.helpers.mkSymlinkActivationScript { target = ".local/state/noctalia/settings.toml"; diff --git a/modules/components/window-managers/niri.nix b/modules/components/window-managers/niri.nix index f835135..5aed825 100644 --- a/modules/components/window-managers/niri.nix +++ b/modules/components/window-managers/niri.nix @@ -40,7 +40,7 @@ }; flake.homeModules.graphics = { lib, osConfig, config, ... }: { - config = lib.mkIf (builtins.hasAttr "osConfig" self) (lib.mkIf ((osConfig.components.windowManagers == "niri")||(builtins.elem "niri" osConfig.components.windowManagers)) { + config = lib.mkIf (builtins.tryEval osConfig).success (lib.mkIf ((osConfig.components.windowManagers == "niri")||(builtins.elem "niri" osConfig.components.windowManagers)) { home.activation.symlinkNiriConfig = lib.hm.dag.entryAfter ["writeBoundary"] (config.helpers.mkSymlinkActivationScript { target = ".config/niri/config.kdl"; source = "dotfiles/${config.info.hostName}/niri.kdl"; diff --git a/modules/features/applications/gui/floorp.nix b/modules/features/applications/gui/floorp.nix index 68a1c40..b7f96f3 100644 --- a/modules/features/applications/gui/floorp.nix +++ b/modules/features/applications/gui/floorp.nix @@ -6,6 +6,8 @@ let firefox-addons = with pkgs; inputs.firefox-addons.packages.${system}; in { + stylix.targets.floorp.profileNames = [ "default" ]; + programs.floorp = { enable = true; nativeMessagingHosts = [ @@ -206,8 +208,6 @@ }; }; }; - }) // lib.optionalAttrs (builtins.hasAttr "osConfig" self) { - stylix.targets.floorp.profileNames = lib.mkIf (config.features.applications.gui.floorp.enable) [ "default" ]; - }; + }); }; } \ No newline at end of file diff --git a/modules/features/applications/gui/kitty.nix b/modules/features/applications/gui/kitty.nix index a4e5d1e..8fda5c1 100644 --- a/modules/features/applications/gui/kitty.nix +++ b/modules/features/applications/gui/kitty.nix @@ -1,6 +1,10 @@ { inputs, self, ... }: { - flake.homeModules.graphics = { pkgs, config, lib, ... }: { + flake.nixosModules.graphics = { pkgs, config, lib, ... }: { options.features.applications.gui.kitty.enable = lib.mkEnableOption "kitty"; + }; + + flake.homeModules.graphics = { pkgs, config, lib, ... }: { + options.features.applications.gui.kitty.enable = lib.mkOption (config.helpers.inheritOsConfigToHome "features.applications.gui.kitty.enable"); config = lib.mkIf (config.features.applications.gui.kitty.enable) { programs.kitty = { diff --git a/modules/features/applications/gui/nautilus.nix b/modules/features/applications/gui/nautilus.nix index 328e8f6..4941d89 100644 --- a/modules/features/applications/gui/nautilus.nix +++ b/modules/features/applications/gui/nautilus.nix @@ -20,7 +20,9 @@ }; flake.homeModules.graphics = { pkgs, osConfig, config, lib, ... }: { - config = lib.mkIf (builtins.hasAttr "osConfig" self) (lib.mkIf (osConfig.features.applications.gui.nautilus.enable) { + options.features.applications.gui.nautilus.enable = lib.mkOption (config.helpers.inheritOsConfigToHome "features.applications.gui.nautilus.enable"); + + config = lib.mkIf (config.features.applications.gui.nautilus.enable) { gtk.gtk3.bookmarks = [ "file://${config.info.rootPath} NixOS" "file:///home/grey/Downloads Downloads" @@ -30,6 +32,6 @@ "file:///home/grey/Videos Videos" "file:/// Root" ]; - }); + }; }; } \ No newline at end of file diff --git a/modules/features/applications/gui/vscode.nix b/modules/features/applications/gui/vscode.nix index 262fbda..7128b09 100644 --- a/modules/features/applications/gui/vscode.nix +++ b/modules/features/applications/gui/vscode.nix @@ -1,6 +1,10 @@ { inputs, self, ... }: { - flake.homeModules.graphics = { config, pkgs, lib, ... }: { + flake.nixosModules.graphics = { config, pkgs, lib, ... }: { options.features.applications.gui.vscode.enable = lib.mkEnableOption "vscode"; + }; + + flake.homeModules.graphics = { config, pkgs, lib, ... }: { + options.features.applications.gui.vscode.enable = lib.mkOption (config.helpers.inheritOsConfigToHome "features.applications.gui.vscode.enable"); config = lib.mkIf (config.features.applications.gui.vscode.enable) { home.packages = [ pkgs.vscode ]; diff --git a/modules/features/shells/zsh.nix b/modules/features/shells/zsh.nix index 379540b..ea40a61 100644 --- a/modules/features/shells/zsh.nix +++ b/modules/features/shells/zsh.nix @@ -18,7 +18,7 @@ antidote.enable = lib.mkEnableOption "antidote"; }; - config = (if builtins.hasAttr "osConfig" self then (lib.mkIf (osConfig.features.shells.zsh.enable || config.features.shells.zsh.enable)) else (lib.mkIf (config.features.shells.zsh.enable))) { + config = (if (builtins.tryEval osConfig).success then (lib.mkIf (osConfig.features.shells.zsh.enable || config.features.shells.zsh.enable)) else (lib.mkIf (config.features.shells.zsh.enable))) { home.shell.enableZshIntegration = true; programs.kitty.shellIntegration.enableZshIntegration = true; @@ -26,7 +26,7 @@ programs.zsh = { enable = true; completionInit = ""; - antidote = (if builtins.hasAttr "osConfig" self then (lib.mkIf (osConfig.features.shells.zsh.antidote.enable || config.features.shells.zsh.antidote.enable)) else (lib.mkIf (config.features.shells.zsh.antidote.enable))) { + antidote = (if (builtins.tryEval osConfig).success then (lib.mkIf (osConfig.features.shells.zsh.antidote.enable || config.features.shells.zsh.antidote.enable)) else (lib.mkIf (config.features.shells.zsh.antidote.enable))) { enable = true; plugins = [ "getantidote/use-omz" diff --git a/modules/global/helpers.nix b/modules/global/helpers.nix index 224fa3f..9b7de6a 100644 --- a/modules/global/helpers.nix +++ b/modules/global/helpers.nix @@ -1,11 +1,37 @@ { inputs, self, ... }: { flake.nixosModules.global = { pkgs, config, lib, ... }: { options.helpers = { - # nothing here yet + typeOf = lib.mkOption { + type = lib.types.functionTo lib.types.str; + default = value: ( + if builtins.isAttrs value then "attrs" else ( + if builtins.isBool value then "bool" else ( + if builtins.isFloat value then "float" else ( + if builtins.isFunction value then "function" else ( + if builtins.isInt value then "int" else ( + if builtins.isList value then "list" else ( + if builtins.isPath value then "path" else ( + if builtins.isString value then "str" else "" + ) + ) + ) + ) + ) + ) + ) + ); + readOnly = true; + }; + + attrByStrPath = lib.mkOption { + default = strPath: set: + lib.attrsets.attrByPath (lib.strings.splitString "." strPath) null set; + readOnly = true; + }; }; }; - flake.homeModules.global = { pkgs, config, lib, ... }: { + flake.homeModules.global = { pkgs, config, osConfig, lib, ... }: { options.helpers = { mkSymlinkActivationScript = lib.mkOption { type = lib.types.functionTo lib.types.str; @@ -15,6 +41,19 @@ fi ln -s ${config.info.rootPath}/${source} /home/grey/${target} ''; + readOnly = true; + }; + + inheritOsConfigToHome = lib.mkOption { + type = lib.types.functionTo lib.types.attrs; + default = let + safeOsConfig = builtins.tryEval osConfig; + in option: { + type = if safeOsConfig.success then safeOsConfig.value.helpers.attrByStrPath (safeOsConfig.value.helpers.typeOf (safeOsConfig.value.helpers.attrByStrPath option safeOsConfig.value)) lib.types else null; + default = (lib.mkIf (safeOsConfig.success) (safeOsConfig.value.helpers.attrByStrPath option safeOsConfig.value)).content; + readOnly = true; + }; + readOnly = true; }; }; }; diff --git a/modules/global/home.nix b/modules/global/home.nix index a04dced..05123e3 100644 --- a/modules/global/home.nix +++ b/modules/global/home.nix @@ -12,7 +12,7 @@ packages = with pkgs; [ speedtest-go ] ++ config.features.applications.extraPackages - ++ (if !(builtins.hasAttr "osConfig" self) then [ + ++ (if !(builtins.tryEval osConfig).success then [ pkgs.home-manager ] else []); @@ -24,7 +24,7 @@ xdg = { enable = true; - localBinInPath = !(builtins.hasAttr "osConfig" self); + localBinInPath = !(builtins.tryEval osConfig).success; }; programs = { diff --git a/modules/hosts/kitagawa/kitagawa.nix b/modules/hosts/kitagawa/kitagawa.nix index 077b16e..69afeeb 100644 --- a/modules/hosts/kitagawa/kitagawa.nix +++ b/modules/hosts/kitagawa/kitagawa.nix @@ -33,10 +33,7 @@ applications = { gui = { - spotify = { - enable = true; - spicetify.enable = true; - }; + kitty.enable = true; vscode.enable = true; }; @@ -102,8 +99,11 @@ gui = { equibop.enable = true; floorp.enable = true; - kitty.enable = true; remmina.enable = true; + spotify = { + enable = true; + spicetify.enable = true; + }; }; extraPackages = with pkgs; [