mirror of
https://github.com/gensokyo-zone/infrastructure.git
synced 2026-02-09 12:29:19 -08:00
Cursed refactor.
This commit is contained in:
parent
20b4bafa85
commit
5845debc95
83 changed files with 1000 additions and 804 deletions
|
|
@ -1,9 +1,9 @@
|
|||
{ pkgs, hosts, profiles }:
|
||||
{ pkgs, hosts, groups }:
|
||||
|
||||
with pkgs.lib;
|
||||
|
||||
(mapAttrs (name: hosts:
|
||||
pkgs.writeScript "deploy-profile-${name}" ''
|
||||
pkgs.writeScript "deploy-group-${name}" ''
|
||||
#!${pkgs.runtimeShell}
|
||||
export PATH=
|
||||
${concatMapStrings (host: ''
|
||||
|
|
@ -14,5 +14,5 @@ with pkgs.lib;
|
|||
# FIXME: remove jobs from PIDLIST once they finish
|
||||
trap "kill $PID_LIST" SIGINT
|
||||
wait $PID_LIST
|
||||
'') profiles)
|
||||
'') groups)
|
||||
// (mapAttrs (name: host: host.config.system.build.deployScript) hosts)
|
||||
|
|
|
|||
|
|
@ -1,12 +1,6 @@
|
|||
{
|
||||
pkgs,
|
||||
hostsDir ? ../config/hosts,
|
||||
privateHostsDir ? ../config/private/hosts,
|
||||
commonImports ? [ ../config/common ../modules/nixos ],
|
||||
pkgsPath ? ../pkgs,
|
||||
sources ? {},
|
||||
witch ? {}
|
||||
}:
|
||||
{ pkgs, hostsDir ? ../config/hosts, privateHostsDir ? ../config/private/hosts
|
||||
, commonImports ? [ ../config/nixos.nix ../modules/nixos ], pkgsPath ? ../pkgs
|
||||
, sources ? { }, witch ? { } }:
|
||||
|
||||
with pkgs.lib;
|
||||
|
||||
|
|
@ -14,41 +8,38 @@ rec {
|
|||
hostNames = attrNames
|
||||
(filterAttrs (name: type: type == "directory") (builtins.readDir hostsDir));
|
||||
|
||||
hostConfig = hostName: { config, ... }: {
|
||||
_module.args = {
|
||||
inherit hosts profiles;
|
||||
hostConfig = hostName:
|
||||
{ config, ... }: {
|
||||
_module.args = { inherit hosts groups; };
|
||||
imports = [
|
||||
(import (hostsDir + "/${hostName}/configuration.nix"))
|
||||
(import (privateHostsDir + "/${hostName}/configuration.nix"))
|
||||
../modules/nixos/deploy
|
||||
] ++ commonImports;
|
||||
networking = { inherit hostName; };
|
||||
nixpkgs.pkgs = import pkgsPath {
|
||||
inherit (config.nixpkgs) config;
|
||||
inherit sources;
|
||||
};
|
||||
};
|
||||
imports = [
|
||||
(import (hostsDir + "/${hostName}/configuration.nix"))
|
||||
(import (privateHostsDir + "/${hostName}/configuration.nix"))
|
||||
../modules/nixos/deploy
|
||||
] ++ commonImports;
|
||||
networking = {
|
||||
inherit hostName;
|
||||
};
|
||||
nixpkgs.pkgs = import pkgsPath { inherit (config.nixpkgs) config; inherit sources; };
|
||||
};
|
||||
|
||||
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);
|
||||
|
||||
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
|
||||
);
|
||||
groupNames = unique (concatLists
|
||||
(mapAttrsToList (name: host: host.config.deploy.groups) hosts));
|
||||
|
||||
profileNames = unique (concatLists
|
||||
(mapAttrsToList (name: host: host.config.deploy.profiles) hosts));
|
||||
|
||||
profiles = listToAttrs (map (profileName:
|
||||
nameValuePair profileName
|
||||
(filter (host: elem profileName host.config.deploy.profiles)
|
||||
(attrValues hosts))) profileNames);
|
||||
groups = listToAttrs (map (groupName:
|
||||
nameValuePair groupName
|
||||
(filter (host: elem groupName host.config.deploy.groups)
|
||||
(attrValues hosts))) groupNames);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,22 +1,23 @@
|
|||
{
|
||||
modulesDir,
|
||||
defaultFile ? "default.nix",
|
||||
importAll ? false
|
||||
}:
|
||||
{ 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)
|
||||
);
|
||||
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}:
|
||||
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;
|
||||
let m = import value;
|
||||
in {
|
||||
inherit name;
|
||||
value = if (isFunction m) && !importAll then value else m;
|
||||
}) files;
|
||||
in (listToAttrs modules)
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
{ lib }:
|
||||
{ lib }:
|
||||
|
||||
{
|
||||
style = import ./style.nix;
|
||||
colorhelpers = import ./colorhelpers.nix { inherit lib; };
|
||||
}
|
||||
style = import ./style.nix;
|
||||
colorhelpers = import ./colorhelpers.nix { inherit lib; };
|
||||
secrets = import ./secrets.nix;
|
||||
modList = import ./modules.nix;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue