From d250dc13ef86ad9e664ab7ad43c796088384e533 Mon Sep 17 00:00:00 2001 From: LordGrimmauld Date: Tue, 16 Apr 2024 12:09:17 +0200 Subject: [PATCH] refactor: move option definitions to modules --- common/cloudsync.nix | 46 +++++++++ common/firefox.nix | 16 +++ common/gaming.nix | 6 ++ common/localisation.nix | 6 ++ common/networking.nix | 6 ++ common/opengl.nix | 42 ++++++++ common/portals.nix | 6 ++ common/printing.nix | 6 ++ common/sound.nix | 6 ++ common/sway.nix | 58 +++++++++++ common/toolchains.nix | 22 ++++ configuration.nix | 2 +- load_common.nix | 221 ---------------------------------------- 13 files changed, 221 insertions(+), 222 deletions(-) diff --git a/common/cloudsync.nix b/common/cloudsync.nix index 08558dc..0d67246 100644 --- a/common/cloudsync.nix +++ b/common/cloudsync.nix @@ -1,6 +1,20 @@ { pkgs, config, lib, ... }: let cfg = config.grimmShared; + sync_mod = with lib; types.submodule ({ config, ... }: { + options = { + remote = mkOption { + type = types.nonEmptyStr; + description = "path on the cloud server"; + }; + + local = mkOption { + type = types.nonEmptyStr; + default = "$HOME/" + (lib.strings.concatStrings (builtins.match "/*(.+)" config.remote)); + description = "local path to sync"; + }; + }; + }); in { config = with cfg; lib.mkIf (enable && cloudSync.enable) ( @@ -63,4 +77,36 @@ in config.users.users); } ); + + options.users.users = with lib; mkOption { + type = types.attrsOf (types.submodule { + options = { + syncPaths = mkOption { + type = types.listOf sync_mod; + default = [ ]; + description = "paths to sync via nextcloud"; + }; + }; + }); + }; + + + options.grimmShared.cloudSync = with lib; { + enable = mkEnableOption "cloud_sync"; + + username = mkOption { + type = types.nonEmptyStr; + description = "username to use for cloud login"; + }; + + server = mkOption { + type = types.nonEmptyStr; + description = "server url to use for cloud sync"; + }; + + passwordFile = mkOption { + type = types.nonEmptyStr; + description = "password file to use for login"; + }; + }; } diff --git a/common/firefox.nix b/common/firefox.nix index 26329ae..0f68bf0 100644 --- a/common/firefox.nix +++ b/common/firefox.nix @@ -56,4 +56,20 @@ in }; }; }; + + options.grimmShared.firefox = with lib; { + enable = mkEnableOption "grimm-firefox"; + + plugins = mkOption { + type = types.attrsOf types.str; + default = { }; + description = "set of plugins to install. Format: guid = short-id"; + }; + + disableUserPlugins = mkOption { + type = types.bool; + default = false; + description = "disables user controlled plugins"; + }; + }; } diff --git a/common/gaming.nix b/common/gaming.nix index 4e6d841..96429e2 100644 --- a/common/gaming.nix +++ b/common/gaming.nix @@ -46,4 +46,10 @@ in }) ]; }; + + options.grimmShared.gaming = with lib; mkOption { + type = types.bool; + default = false; + description = "enables steam, heroic, prism and gamemoded"; + }; } diff --git a/common/localisation.nix b/common/localisation.nix index f725e7e..9c9dc2e 100644 --- a/common/localisation.nix +++ b/common/localisation.nix @@ -28,4 +28,10 @@ in variant = ""; }; }; + + options.grimmShared.locale = with lib; mkOption { + type = types.bool; + default = true; + description = "Sets german units but english language"; + }; } diff --git a/common/networking.nix b/common/networking.nix index ef54f45..db16dc3 100644 --- a/common/networking.nix +++ b/common/networking.nix @@ -23,4 +23,10 @@ in serviceConfig.ExecStart = "${pkgs.bluez}/bin/mpris-proxy"; }; }; + + options.grimmShared.network = with lib; mkOption { + type = types.bool; + default = false; + description = "Enables network manager, wifi and bluetooth"; + }; } diff --git a/common/opengl.nix b/common/opengl.nix index 36229c2..8733efd 100644 --- a/common/opengl.nix +++ b/common/opengl.nix @@ -1,6 +1,33 @@ { pkgs, config, lib, ... }: let cfg = config.grimmShared; + screen = with lib; types.submodule { + options = { + fps = mkOption { + type = types.int; + default = 60; + description = "max framerate of screen"; + }; + + mode = mkOption { + type = types.nonEmptyStr; + default = "1920x1080"; + description = "pixel format of the screen"; + }; + + id = mkOption { + type = types.nonEmptyStr; + description = "ID of the screen"; + }; + + pos = mkOption { + type = types.nullOr types.nonEmptyStr; + default = null; + example = "0,0"; + description = "position where to place the screen"; + }; + }; + }; in { config = with cfg; lib.mkIf (enable && graphical) { @@ -28,4 +55,19 @@ in glfw ]; }; + + + options.grimmShared = with lib; { + graphical = mkOption { + type = types.bool; + default = cfg.screens != { }; + description = "whether to force enable graphical components"; + }; + + screens = mkOption { + type = types.attrsOf screen; + default = { }; + description = "Screens to initialize, will activate graphical components"; + }; + }; } diff --git a/common/portals.nix b/common/portals.nix index 25d38b3..1838ab0 100644 --- a/common/portals.nix +++ b/common/portals.nix @@ -34,4 +34,10 @@ in fonts.fontDir.enable = true; }; + + options.grimmShared.portals = with lib; mkOption { + type = types.bool; + default = false; + description = "Enables portals for wlr, gtk and kde as well as fixes fonts"; + }; } diff --git a/common/printing.nix b/common/printing.nix index d9f6139..b95e5b5 100644 --- a/common/printing.nix +++ b/common/printing.nix @@ -19,4 +19,10 @@ in skanpage ]; }; + + options.grimmShared.printing = with lib; mkOption { + type = types.bool; + default = false; + description = "Enables print and scan related options"; + }; } diff --git a/common/sound.nix b/common/sound.nix index 14800a8..5e10670 100644 --- a/common/sound.nix +++ b/common/sound.nix @@ -25,4 +25,10 @@ in pulseaudio ]; }; + + options.grimmShared.sound = with lib; mkOption { + type = types.bool; + default = false; + description = "whether to enable sound"; + }; } diff --git a/common/sway.nix b/common/sway.nix index b7fa065..a4bde00 100644 --- a/common/sway.nix +++ b/common/sway.nix @@ -1,6 +1,39 @@ { pkgs, config, lib, ... }: let cfg = config.grimmShared; + sway_conf = with lib; types.submodule ({ config, ... }: rec { + options = { + keybinds = mkOption { + type = types.attrsOf types.str; + default = { }; + description = "set of keybinds assigning key combo to action"; + }; + + autolaunch = mkOption { + type = types.listOf (types.either types.str types.package); + default = [ ]; + description = "set of commands to be run at sway startup"; + }; + + extraConfig = mkOption { + type = types.str; + default = ""; + description = "additional sway config to be included"; + }; + + definitions = mkOption { + type = types.attrsOf types.str; + default = { }; + description = "set of definitions assigning variable to value"; + }; + + modes = mkOption { + type = types.attrsOf sway_conf; + default = { }; + description = "possible modes to switch to, e.g. resize"; + }; + }; + }); in { config = @@ -115,4 +148,29 @@ in ''; }; }; + + options.grimmShared.sway = with lib; { + enable = mkEnableOption "grimm-sway"; + + bar = { + enable = mkEnableOption "grimm-sway-bar"; + + style = mkOption { + type = types.nullOr types.path; + default = null; + description = "waybar style sheet to use"; + }; + + config = mkOption { + type = types.nullOr types.path; + default = null; + description = "waybar config to use"; + }; + }; + + config = mkOption { + type = sway_conf; + description = "sway config to use"; + }; + }; } diff --git a/common/toolchains.nix b/common/toolchains.nix index 4ca5b90..d2253a0 100644 --- a/common/toolchains.nix +++ b/common/toolchains.nix @@ -117,4 +117,26 @@ in programs.ssh.startAgent = true; programs.thefuck.enable = true; }; + + options.grimmShared.tooling = with lib; { + enable = mkEnableOption "grimm-tooling"; + + pass = mkOption { + type = types.bool; + default = true; + description = "Enables password-store, gnupg and such secret handling"; + }; + + git_user = mkOption { + type = types.str; + default = "Grimmauld"; + description = "Username for git to use"; + }; + + git_email = mkOption { + type = types.str; + default = "${config.grimmShared.tooling.git_user}@grimmauld.de"; + description = "Email for git to use"; + }; + }; } diff --git a/configuration.nix b/configuration.nix index 03406f4..46dca3c 100644 --- a/configuration.nix +++ b/configuration.nix @@ -80,7 +80,7 @@ qt6ct ]; - # environment.etc."kvantum".source = "${pkgs.catppuccin-kvantum}/share/Kvantum"; + # environment.etc."kvantum".source = "${pkgs.catppuccin-kvantum}/share/Kvantum"; environment.sessionVariables = { NIXPKGS_ALLOW_UNFREE = "1"; diff --git a/load_common.nix b/load_common.nix index 2ec12b6..34229e7 100644 --- a/load_common.nix +++ b/load_common.nix @@ -1,229 +1,8 @@ { config, lib, pkgs, ... }: with lib; -let - cfg = config.grimmShared; - sync_mod = types.submodule ({ config, ... }: { - options = { - remote = mkOption { - type = types.nonEmptyStr; - description = "path on the cloud server"; - }; - - local = mkOption { - type = types.nonEmptyStr; - default = "$HOME/" + (lib.strings.concatStrings (builtins.match "/*(.+)" config.remote)); - description = "local path to sync"; - }; - }; - }); - - screen = types.submodule { - options = { - fps = mkOption { - type = types.int; - default = 60; - description = "max framerate of screen"; - }; - - mode = mkOption { - type = types.nonEmptyStr; - default = "1920x1080"; - description = "pixel format of the screen"; - }; - - id = mkOption { - type = types.nonEmptyStr; - description = "ID of the screen"; - }; - - pos = mkOption { - type = types.nullOr types.nonEmptyStr; - default = null; - example = "0,0"; - description = "position where to place the screen"; - }; - }; - }; - - sway_conf = types.submodule ({ config, ... }: rec { - options = { - keybinds = mkOption { - type = types.attrsOf types.str; - default = { }; - description = "set of keybinds assigning key combo to action"; - }; - - autolaunch = mkOption { - type = types.listOf (types.either types.str types.package); - default = [ ]; - description = "set of commands to be run at sway startup"; - }; - - extraConfig = mkOption { - type = types.str; - default = ""; - description = "additional sway config to be included"; - }; - - definitions = mkOption { - type = types.attrsOf types.str; - default = { }; - description = "set of definitions assigning variable to value"; - }; - - modes = mkOption { - type = types.attrsOf sway_conf; - default = { }; - description = "possible modes to switch to, e.g. resize"; - }; - }; - }); -in { options.grimmShared = { enable = mkEnableOption "grimm-shared-common"; - - locale = mkOption { - type = types.bool; - default = true; - description = "Sets german units but english language"; - }; - - printing = mkOption { - type = types.bool; - default = false; - description = "Enables print and scan related options"; - }; - - portals = mkOption { - type = types.bool; - default = false; - description = "Enables portals for wlr, gtk and kde as well as fixes fonts"; - }; - - network = mkOption { - type = types.bool; - default = false; - description = "Enables network manager, wifi and bluetooth"; - }; - - tooling = { - enable = mkEnableOption "grimm-tooling"; - - pass = mkOption { - type = types.bool; - default = true; - description = "Enables password-store, gnupg and such secret handling"; - }; - - git_user = mkOption { - type = types.str; - default = "Grimmauld"; - description = "Username for git to use"; - }; - - git_email = mkOption { - type = types.str; - default = "${config.grimmShared.tooling.git_user}@grimmauld.de"; - description = "Email for git to use"; - }; - }; - - sound = mkOption { - type = types.bool; - default = false; - description = "whether to enable sound"; - }; - - graphical = mkOption { - type = types.bool; - default = false; - description = "whether to enable graphical components"; - }; - - gaming = mkOption { - type = types.bool; - default = false; - description = "enables steam, heroic, prism and gamemoded"; - }; - - firefox = { - enable = mkEnableOption "grimm-firefox"; - - plugins = mkOption { - type = types.attrsOf types.str; - default = { }; - description = "set of plugins to install. Format: guid = short-id"; - }; - - disableUserPlugins = mkOption { - type = types.bool; - default = false; - description = "disables user controlled plugins"; - }; - }; - - screens = mkOption { - type = types.attrsOf screen; - default = { }; - description = "Screens to initialize"; - }; - - sway = { - enable = mkEnableOption "grimm-sway"; - - bar = { - enable = mkEnableOption "grimm-sway-bar"; - - style = mkOption { - type = types.nullOr types.path; - default = null; - description = "waybar style sheet to use"; - }; - - config = mkOption { - type = types.nullOr types.path; - default = null; - description = "waybar config to use"; - }; - }; - - config = mkOption { - type = sway_conf; - description = "sway config to use"; - }; - }; - - cloudSync = { - enable = mkEnableOption "cloud_sync"; - - username = mkOption { - type = types.nonEmptyStr; - description = "username to use for cloud login"; - }; - - server = mkOption { - type = types.nonEmptyStr; - description = "server url to use for cloud sync"; - }; - - passwordFile = mkOption { - type = types.nonEmptyStr; - description = "password file to use for login"; - }; - }; - }; - - options.users.users = mkOption { - type = types.attrsOf (types.submodule { - options = { - syncPaths = mkOption { - type = types.listOf sync_mod; - default = [ ]; - description = "paths to sync via nextcloud"; - }; - }; - }); }; imports = [