Work in progress refactor.

This commit is contained in:
kat witch 2021-03-03 03:00:51 +00:00
parent ad1faf2f24
commit 9ece41ee80
No known key found for this signature in database
GPG key ID: 1B477797DCA5EC72
14 changed files with 130 additions and 76 deletions

View file

@ -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));

22
lib/modules.nix Normal file
View file

@ -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)

34
lib/style.nix Normal file
View file

@ -0,0 +1,34 @@
rec {
base16 = {
color0 = "#2e3440";
color1 = "#bf616a";
color2 = "#a3be8c";
color3 = "#ebcb8b";
color4 = "#81a1c1";
color5 = "#b48ead";
color6 = "#88c0d0";
color7 = "#e5e9f0";
color8 = "#4c566a";
color9 = "#d08770";
color10 = "#3b4252";
color11 = "#434c5e";
color12 = "#d8dee9";
color13 = "#eceff4";
color14 = "#5e81ac";
color15 = "#8fbcbb";
color16 = "#fd971f";
color17 = "#cc6633";
color18 = "#383830";
color19 = "#49483e";
color20 = "#a59f85";
color21 = "#f5f4f1";
};
font = {
name = "Hack Nerd Font";
size = "9";
size_css = "12px";
};
}

6
lib/witch.nix Normal file
View file

@ -0,0 +1,6 @@
{ lib }:
{
style = import ./style.nix;
colorhelpers = import ./colorhelpers.nix { inherit lib; };
}