diff --git a/config/common/default.nix b/config/common/default.nix index 25c05042..8cdfa756 100644 --- a/config/common/default.nix +++ b/config/common/default.nix @@ -1,8 +1,7 @@ -{ config, lib, pkgs, ... }: +{ config, lib, pkgs, sources, ... }: -let sources = import ../../nix/sources.nix; -in { - imports = [ ../../modules ../users (sources.home-manager + "/nixos") ]; +{ + imports = [../users (sources.home-manager + "/nixos") ]; boot.kernelPackages = lib.mkDefault pkgs.linuxPackages_latest; boot.loader.grub.configurationLimit = 8; diff --git a/config/hosts/samhain/configuration.nix b/config/hosts/samhain/configuration.nix index 79420224..94e43965 100644 --- a/config/hosts/samhain/configuration.nix +++ b/config/hosts/samhain/configuration.nix @@ -1,7 +1,6 @@ -{ config, pkgs, lib, ... }: +{ config, pkgs, lib, sources, witch, ... }: -let sources = (import ../../../nix/sources.nix); -in { +{ imports = [ ../../services/zfs.nix ./hardware.nix diff --git a/config/users/kat/kitty.nix b/config/users/kat/kitty.nix index dd62c77d..5ee8b098 100644 --- a/config/users/kat/kitty.nix +++ b/config/users/kat/kitty.nix @@ -1,28 +1,27 @@ -{ config, lib, pkgs, ... }: +{ config, lib, pkgs, witch, ... }: -let style = import ./style.nix; -in { +{ config = lib.mkIf (lib.elem "desktop" config.meta.deploy.profiles) { home-manager.users.kat = { programs.kitty = { enable = true; - font.name = style.font.name; + font.name = witch.style.font.name; settings = { - font_size = style.font.size; - background = style.base16.color0; + font_size = witch.style.font.size; + background = witch.style.base16.color0; background_opacity = "0.7"; - foreground = style.base16.color7; - selection_background = style.base16.color7; - selection_foreground = style.base16.color0; - url_color = style.base16.color3; - cursor = style.base16.color7; + foreground = witch.style.base16.color7; + selection_background = witch.style.base16.color7; + selection_foreground = witch.style.base16.color0; + url_color = witch.style.base16.color3; + cursor = witch.style.base16.color7; active_border_color = "#75715e"; active_tab_background = "#9900ff"; - active_tab_foreground = style.base16.color7; + active_tab_foreground = witch.style.base16.color7; inactive_tab_background = "#3a3a3a"; inactive_tab_foreground = "#665577"; - } // style.base16; + } // witch.style.base16; }; }; }; diff --git a/config/users/kat/sway.nix b/config/users/kat/sway.nix index 1d02ca68..7fcc4026 100644 --- a/config/users/kat/sway.nix +++ b/config/users/kat/sway.nix @@ -1,7 +1,6 @@ -{ config, pkgs, lib, ... }: +{ config, pkgs, lib, witch, ... }: let - style = import ./style.nix; secrets = import ../../../secrets.nix; in { config = lib.mkIf (lib.elem "sway" config.meta.deploy.profiles) { @@ -26,16 +25,16 @@ in { programs.mako = { enable = true; defaultTimeout = 3000; - borderColor = style.base16.color7; - backgroundColor = "${style.base16.color0}70"; - textColor = style.base16.color7; + borderColor = witch.style.base16.color7; + backgroundColor = "${witch.style.base16.color0}70"; + textColor = witch.style.base16.color7; }; wayland.windowManager.sway = { enable = true; config = let dmenu = - "${pkgs.bemenu}/bin/bemenu --fn '${style.font.name} ${style.font.size}' --nb '${style.base16.color0}' --nf '${style.base16.color7}' --sb '${style.base16.color1}' --sf '${style.base16.color7}' -l 5 -m -1 -i"; + "${pkgs.bemenu}/bin/bemenu --fn '${witch.style.font.name} ${witch.style.font.size}' --nb '${witch.style.base16.color0}' --nf '${witch.style.base16.color7}' --sb '${witch.style.base16.color1}' --sf '${witch.style.base16.color7}' -l 5 -m -1 -i"; lockCommand = "swaylock -i ${./wallpapers/main.png} -s fill"; cfg = config.home-manager.users.kat.wayland.windowManager.sway.config; in { @@ -84,7 +83,7 @@ in { }; }; - fonts = [ "${style.font.name} ${style.font.size}" ]; + fonts = [ "${witch.style.font.name} ${witch.style.font.size}" ]; terminal = "${pkgs.kitty}/bin/kitty"; # TODO: replace with wofi menu = @@ -192,32 +191,32 @@ in { colors = { focused = { - border = style.base16.color8; - background = style.base16.color4; - text = style.base16.color0; - indicator = style.base16.color2; - childBorder = style.base16.color8; + border = witch.style.base16.color8; + background = witch.style.base16.color4; + text = witch.style.base16.color0; + indicator = witch.style.base16.color2; + childBorder = witch.style.base16.color8; }; focusedInactive = { - border = style.base16.color0; - background = style.base16.color11; - text = style.base16.color12; - indicator = style.base16.color2; - childBorder = style.base16.color8; + border = witch.style.base16.color0; + background = witch.style.base16.color11; + text = witch.style.base16.color12; + indicator = witch.style.base16.color2; + childBorder = witch.style.base16.color8; }; unfocused = { - border = style.base16.color0; - background = style.base16.color8; - text = style.base16.color12; - indicator = style.base16.color8; - childBorder = style.base16.color8; + border = witch.style.base16.color0; + background = witch.style.base16.color8; + text = witch.style.base16.color12; + indicator = witch.style.base16.color8; + childBorder = witch.style.base16.color8; }; urgent = { - border = style.base16.color8; - background = style.base16.color9; - text = style.base16.color0; - indicator = style.base16.color1; - childBorder = style.base16.color8; + border = witch.style.base16.color8; + background = witch.style.base16.color9; + text = witch.style.base16.color0; + indicator = witch.style.base16.color1; + childBorder = witch.style.base16.color8; }; }; }; diff --git a/config/users/kat/waybar/default.nix b/config/users/kat/waybar/default.nix index ac96e62d..e7d7ac56 100644 --- a/config/users/kat/waybar/default.nix +++ b/config/users/kat/waybar/default.nix @@ -1,7 +1,6 @@ -{ config, lib, pkgs, ... }: +{ config, lib, pkgs, witch, ... }: let - style = import ../style.nix; secrets = import ../../../../secrets.nix; in { config = lib.mkIf (lib.elem "sway" config.meta.deploy.profiles) { @@ -9,8 +8,8 @@ in { programs.waybar = { enable = true; style = import ./waybar.css.nix { - inherit style; - hextorgba = pkgs.colorhelpers.hextorgba; + style = witch.style; + hextorgba = witch.colorhelpers.hextorgba; }; settings = [{ modules-left = [ "sway/workspaces" "sway/mode" "sway/window" ]; diff --git a/default.nix b/default.nix index 03f9ef9c..3b25f31e 100644 --- a/default.nix +++ b/default.nix @@ -1,13 +1,14 @@ -let +rec { + sources = import ./nix/sources.nix; pkgs = import ./pkgs { }; - hosts = import ./lib/hosts.nix { inherit pkgs; }; -in { - inherit pkgs; + witch = import ./lib/witch.nix { lib = pkgs.lib; }; + + hosts = import ./lib/hosts.nix { inherit pkgs sources witch; }; + inherit (pkgs) lib; - inherit (hosts) hosts profiles; + deploy = import ./lib/deploy.nix { inherit pkgs; inherit (hosts) hosts profiles; }; - sources = import ./nix/sources.nix; } diff --git a/lib/hosts.nix b/lib/hosts.nix index 8d87fff0..44b1083e 100644 --- a/lib/hosts.nix +++ b/lib/hosts.nix @@ -1,5 +1,12 @@ -{ pkgs, hostsDir ? ../config/hosts, privateHostsDir ? ../config/private/hosts -, commonImports ? [ ../config/common ../modules ], pkgsPath ? ../pkgs }: +{ + pkgs, + hostsDir ? ../config/hosts, + privateHostsDir ? ../config/private/hosts, + commonImports ? [ ../config/common ../modules/nixos ], + pkgsPath ? ../pkgs, + sources ? {}, + witch ? {} +}: with pkgs.lib; @@ -7,22 +14,37 @@ rec { hostNames = attrNames (filterAttrs (name: type: type == "directory") (builtins.readDir hostsDir)); - hostConfig = hostName: - { config, ... }: { - _module.args = { inherit hosts profiles; }; - imports = [ - (import (hostsDir + "/${hostName}/configuration.nix")) - (import (privateHostsDir + "/${hostName}/configuration.nix")) - ../modules/deploy - ] ++ commonImports; - networking = { inherit hostName; }; - nixpkgs.pkgs = import pkgsPath { inherit (config.nixpkgs) config; }; + hostConfig = hostName: { config, ... }: { + _module.args = { + inherit hosts profiles; }; + imports = [ + (import (hostsDir + "/${hostName}/configuration.nix")) + (import (privateHostsDir + "/${hostName}/configuration.nix")) + # urgh, yes, we still need to manually import the deploy module for now + # at least if i want to keep my thing reusable. + ../modules/nixos/deploy + ] ++ commonImports; + networking = { + inherit hostName; + }; + nixpkgs.pkgs = import pkgsPath { inherit (config.nixpkgs) config; }; + }; - hosts = listToAttrs (map (hostName: - nameValuePair hostName - (import (pkgs.path + "/nixos") { configuration = hostConfig hostName; })) - hostNames); + + hosts = listToAttrs ( + map ( + hostName: nameValuePair hostName ( + import (pkgs.path + "/nixos/lib/eval-config.nix") { + modules = [ + (hostConfig hostName) + (if sources ? home-manager then sources.home-manager + "/nixos" else {}) + ]; + specialArgs = { inherit sources witch; }; + } + ) + ) hostNames + ); profileNames = unique (concatLists (mapAttrsToList (name: host: host.config.meta.deploy.profiles) hosts)); diff --git a/lib/modules.nix b/lib/modules.nix new file mode 100644 index 00000000..ae52bdcb --- /dev/null +++ b/lib/modules.nix @@ -0,0 +1,22 @@ +{ + modulesDir, + defaultFile ? "default.nix", + importAll ? false +}: + +with builtins; + +let + filterAttrNamesToList = filter: set: foldl' (a: b: a ++ b) [] ( + map (e: if (filter e set.${e}) then [ e ] else []) (attrNames set) + ); + nameValuePair = name: value: { inherit name value; }; + listToAttrs = foldl' (acc: val: acc // { ${val.name} = val.value; }) {}; + directories = filterAttrNamesToList (_: type: type == "directory") (readDir modulesDir); + files = map (dir: nameValuePair dir (modulesDir + "/${dir}/${defaultFile}")) directories; + modules = map ({name, value}: + # if the file contains a function, assume it to be a module and pass the path + # (for dedup and such). if it contains anything else, pass that. + let m = import value; in { inherit name; value = if (isFunction m) && !importAll then value else m; } + ) files; +in (listToAttrs modules) diff --git a/config/users/kat/style.nix b/lib/style.nix similarity index 100% rename from config/users/kat/style.nix rename to lib/style.nix diff --git a/lib/witch.nix b/lib/witch.nix new file mode 100644 index 00000000..0a31c88d --- /dev/null +++ b/lib/witch.nix @@ -0,0 +1,6 @@ +{ lib }: + +{ + style = import ./style.nix; + colorhelpers = import ./colorhelpers.nix { inherit lib; }; +} \ No newline at end of file diff --git a/modules/home/default.nix b/modules/home/default.nix new file mode 100644 index 00000000..582cb772 --- /dev/null +++ b/modules/home/default.nix @@ -0,0 +1,10 @@ +{ ... }: + +let sources = import ../../nix/sources.nix; +in { + home-manager.users = { + imports = [ + (sources.tf-nix + "/modules/home/secrets.nix") + ]; + }; +} diff --git a/modules/default.nix b/modules/nixos/default.nix similarity index 78% rename from modules/default.nix rename to modules/nixos/default.nix index c1477b72..f17cb06f 100644 --- a/modules/default.nix +++ b/modules/nixos/default.nix @@ -1,6 +1,6 @@ { ... }: -let sources = import ../nix/sources.nix; +let sources = import ../../nix/sources.nix; in { imports = [ ./deploy diff --git a/modules/deploy/default.nix b/modules/nixos/deploy/default.nix similarity index 100% rename from modules/deploy/default.nix rename to modules/nixos/deploy/default.nix diff --git a/pkgs/default.nix b/pkgs/default.nix index aa2ef917..b915f2d6 100644 --- a/pkgs/default.nix +++ b/pkgs/default.nix @@ -25,8 +25,6 @@ let vendor-reset = (super.callPackage ./vendor-reset { kernel = ksuper.kernel; }).out; }); - - colorhelpers = import ../lib/colorhelpers.nix { inherit (self) lib; }; }; in pkgs.extend (overlay)