From 1eae89b8abb6de839e5235ee30d5016dfdbb5b6f Mon Sep 17 00:00:00 2001 From: Noah Masur <7386960+nmasur@users.noreply.github.com> Date: Mon, 10 Mar 2025 03:37:48 +0000 Subject: [PATCH] coalescing code for imports --- colorscheme/default.nix | 20 ++++++ flake.nix | 12 +--- hosts/aarch64-darwin/lookingglass/default.nix | 2 +- hosts/x86_64-linux/tempest/default.nix | 5 +- lib/default.nix | 64 +++++++++++++++++++ .../nmasur/presets/programs/git-work.nix | 2 + .../nmasur/presets/services/mbsync/mbsync.nix | 4 +- platforms/home-manager/theme.nix | 4 +- .../presets/services/audiobookshelf.nix | 6 +- platforms/nixos/modules/nmasur/settings.nix | 6 +- 10 files changed, 104 insertions(+), 21 deletions(-) create mode 100644 colorscheme/default.nix create mode 100644 lib/default.nix diff --git a/colorscheme/default.nix b/colorscheme/default.nix new file mode 100644 index 0000000..8adb6f8 --- /dev/null +++ b/colorscheme/default.nix @@ -0,0 +1,20 @@ +# Return an atrset of all colorschemes + +nixpkgs: + +let + inherit (nixpkgs) lib; +in + +lib.pipe (lib.filesystem.listFilesRecursive ./.) [ + # Get only files ending in default.nix + (builtins.filter (name: lib.hasSuffix "default.nix" name)) + # Import each colorscheme function + (map (file: { + name = builtins.baseNameOf (builtins.dirOf file); + value = import file; + })) + # Convert to an attrset of colorscheme -> colors + (builtins.listToAttrs) + +] diff --git a/flake.nix b/flake.nix index 8c5aab9..28f9d80 100644 --- a/flake.nix +++ b/flake.nix @@ -222,9 +222,6 @@ fullName = "Noah Masur"; gitName = fullName; gitEmail = "7386960+nmasur@users.noreply.github.com"; - mail.server = "noahmasur.com"; - mail.imapHost = "imap.purelymail.com"; - mail.smtpHost = "smtp.purelymail.com"; dotfilesRepo = "https://github.com/nmasur/dotfiles"; hostnames = { audiobooks = "read.${baseName}"; @@ -253,16 +250,12 @@ }; }; + colorscheme = import ./colorscheme; + # Common overlays to always use overlays = [ inputs.nur.overlays.default inputs.nix2vim.overlay - # inputs.jujutsu.overlays.default # Fix: https://github.com/martinvonz/jj/issues/4784 - # (import ./overlays/neovim-plugins.nix inputs) - # (import ./overlays/tree-sitter.nix inputs) - # (import ./overlays/mpv-scripts.nix inputs) - # (import ./overlays/nextcloud-apps.nix inputs) - # (import ./overlays/pkgs.nix) ] ++ (import ./overlays inputs); # System types to support. @@ -308,6 +301,7 @@ { home-manager.extraSpecialArgs = { hostnames = globals.hostnames; + inherit colorscheme; }; } ]; diff --git a/hosts/aarch64-darwin/lookingglass/default.nix b/hosts/aarch64-darwin/lookingglass/default.nix index b8b16f9..26160a0 100644 --- a/hosts/aarch64-darwin/lookingglass/default.nix +++ b/hosts/aarch64-darwin/lookingglass/default.nix @@ -29,7 +29,7 @@ rec { work.enable = true; experimental.enable = true; }; - nmasur.presets.programs.git = { + nmasur.presets.programs.git-work.work = { name = "Noah-Masur_1701"; email = "${nmasur.settings.username}@take2games.com"; }; diff --git a/hosts/x86_64-linux/tempest/default.nix b/hosts/x86_64-linux/tempest/default.nix index 2be123b..89cea15 100644 --- a/hosts/x86_64-linux/tempest/default.nix +++ b/hosts/x86_64-linux/tempest/default.nix @@ -31,14 +31,11 @@ rec { developer.enable = true; experimental.enable = true; }; - nmasur.presets.services.mbsync = { - user = nmasur.settings.username; - server = "noahmasur.com"; - }; home.stateVersion = "23.05"; }; system.stateVersion = "23.05"; + # Not sure what's necessary but too afraid to remove anything boot.initrd.availableKernelModules = [ "nvme" diff --git a/lib/default.nix b/lib/default.nix new file mode 100644 index 0000000..ad1f064 --- /dev/null +++ b/lib/default.nix @@ -0,0 +1,64 @@ +inputs: + +let + lib = inputs.nixpkgs.lib; +in + +lib +// rec { + + filesInDirectoryWithSuffix = + directory: suffix: + lib.pipe (lib.filesystem.listFilesRecursive directory) [ + # Get only files ending in .nix + (builtins.filter (name: lib.hasSuffix suffix name)) + ]; + + # Returns all files ending in .nix for a directory + nixFiles = directory: filesInDirectoryWithSuffix directory ".nix"; + + # Returns all files ending in default.nix for a directory + defaultFiles = directory: filesInDirectoryWithSuffix directory "default.nix"; + + # Imports all files in a directory and passes inputs + importOverlays = + directory: + lib.pipe (nixFiles directory) [ + # Import each overlay file + (map (file: (import file) inputs)) + ]; + + # Import default files as attrset with keys provided by parent directory + defaultFilesToAttrset = + directory: + lib.pipe (defaultFiles directory) [ + # Import each file + (map (file: { + name = builtins.baseNameOf (builtins.dirOf file); + value = import file; + })) + # Convert to an attrset of parent dir name -> file + (builtins.listToAttrs) + ]; + + # [ package1/package.nix package2/package.nix package2/hello.sh ] + buildPkgsFromDirectoryAndPkgs = + directory: pkgs: + lib.pipe (filesInDirectoryWithSuffix directory "package.nix") [ + + # Apply callPackage to create a derivation + # Must use final.callPackage to avoid infinite recursion + # [ package1.drv package2.drv ] + (builtins.map (name: pkgs.callPackage name { })) + + # Convert the list to an attrset with keys from pname or name attr + # { package1 = package1.drv, package2 = package2.drv } + (builtins.listToAttrs ( + map (v: { + name = v."pname" or v."name"; + value = v; + }) + )) + ]; + +} diff --git a/platforms/home-manager/modules/nmasur/presets/programs/git-work.nix b/platforms/home-manager/modules/nmasur/presets/programs/git-work.nix index 4232169..7bfbd0a 100644 --- a/platforms/home-manager/modules/nmasur/presets/programs/git-work.nix +++ b/platforms/home-manager/modules/nmasur/presets/programs/git-work.nix @@ -27,10 +27,12 @@ in name = lib.mkOption { type = lib.types.str; description = "Name to use for personal git commits"; + default = config.nmasur.presets.programs.git.name; }; email = lib.mkOption { type = lib.types.str; description = "Email to use for personal git commits"; + default = config.nmasur.presets.programs.git.email; }; }; }; diff --git a/platforms/home-manager/modules/nmasur/presets/services/mbsync/mbsync.nix b/platforms/home-manager/modules/nmasur/presets/services/mbsync/mbsync.nix index d00f11d..94052e9 100644 --- a/platforms/home-manager/modules/nmasur/presets/services/mbsync/mbsync.nix +++ b/platforms/home-manager/modules/nmasur/presets/services/mbsync/mbsync.nix @@ -6,7 +6,7 @@ }: let - inherit (config.nmasur.settings) fullName hostnames; + inherit (config.nmasur.settings) username fullName hostnames; cfg = config.nmasur.presets.services.mbsync; in @@ -17,10 +17,12 @@ in user = lib.mkOption { type = lib.types.str; description = "User name for the email address."; + default = username; }; server = lib.mkOption { type = lib.types.str; description = "Server name for the email address."; + default = hostnames.mail; }; imapHost = lib.mkOption { type = lib.types.str; diff --git a/platforms/home-manager/theme.nix b/platforms/home-manager/theme.nix index a2aa13a..f8114ee 100644 --- a/platforms/home-manager/theme.nix +++ b/platforms/home-manager/theme.nix @@ -1,4 +1,4 @@ -{ lib, ... }: +{ lib, colorscheme, ... }: { @@ -11,7 +11,7 @@ colors = lib.mkOption { type = lib.types.attrs; description = "Base16 color scheme."; - default = (import ../../colorscheme/gruvbox).dark; + default = colorscheme.gruvbox.dark; }; mode = lib.mkOption { type = lib.types.enum [ diff --git a/platforms/nixos/modules/nmasur/presets/services/audiobookshelf.nix b/platforms/nixos/modules/nmasur/presets/services/audiobookshelf.nix index e038de6..cc139ad 100644 --- a/platforms/nixos/modules/nmasur/presets/services/audiobookshelf.nix +++ b/platforms/nixos/modules/nmasur/presets/services/audiobookshelf.nix @@ -1,7 +1,7 @@ { config, lib, - globals, + hostnames, ... }: @@ -30,7 +30,7 @@ in # Allow web traffic to Caddy nmasur.presets.services.caddy.routes = [ { - match = [ { host = [ globals.hostnames.audiobooks ]; } ]; + match = [ { host = [ hostnames.audiobooks ]; } ]; handle = [ { handler = "reverse_proxy"; @@ -41,7 +41,7 @@ in ]; # Configure Cloudflare DNS to point to this machine - services.cloudflare-dyndns.domains = [ globals.hostnames.audiobooks ]; + services.cloudflare-dyndns.domains = [ hostnames.audiobooks ]; }; diff --git a/platforms/nixos/modules/nmasur/settings.nix b/platforms/nixos/modules/nmasur/settings.nix index cfe13da..55d6759 100644 --- a/platforms/nixos/modules/nmasur/settings.nix +++ b/platforms/nixos/modules/nmasur/settings.nix @@ -1,4 +1,8 @@ -{ lib, hostnames, ... }: +{ + lib, + hostnames, + ... +}: { options.nmasur.settings = {