before pattern-copy
parent
85dda3dbd3
commit
4df865676b
23
flake.nix
23
flake.nix
|
@ -53,7 +53,7 @@
|
|||
users.path = "${path}/users";
|
||||
};
|
||||
} _inputs);
|
||||
inputs_w_pkgs = (_lib.recursiveUpdate {inherit pkgs;} inputs);
|
||||
inputs_w_pkgs = (_lib.recursiveUpdate {inherit pkgs; lib = pkgs.lib;} inputs);
|
||||
lib = _lib.recursiveUpdate (import ./lib inputs_w_pkgs) _lib;
|
||||
|
||||
# update inputs with our library and past onto our end configurations
|
||||
|
@ -65,6 +65,20 @@
|
|||
# {nixpkgs, agenix, home-manager, flake-utils, nixgl, rust-overlay, flake-compat
|
||||
# ,pkgs, lib (extended), proj_root}
|
||||
final_inputs = inputs_w_lib;
|
||||
|
||||
# Tests: unit + integration
|
||||
unit_tests = (import ./lib/test.nix final_inputs) //
|
||||
{
|
||||
test_example = {
|
||||
expr = "names must start with 'test'";
|
||||
expected = "or won't show up";
|
||||
};
|
||||
not_show = {
|
||||
expr = "this will be ignored by lib.runTests";
|
||||
expected = "for sure";
|
||||
};
|
||||
};
|
||||
|
||||
in {
|
||||
inherit (hosts) nixosConfigurations;
|
||||
# inherit (users) homeConfigurations;
|
||||
|
@ -72,9 +86,10 @@
|
|||
devShell."${system}" = import ./dev-shell.nix final_inputs;
|
||||
templates = import ./templates final_inputs;
|
||||
|
||||
unit_tests = (lib.runTests
|
||||
(import ./lib/test.nix final_inputs) //
|
||||
{});
|
||||
unit_tests = lib.runTests unit_tests;
|
||||
secrets = import ./secrets final_inputs;
|
||||
debug = {
|
||||
inherit final_inputs hosts users modules lib inputs_w_pkgs unit_tests;
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
|
@ -1,16 +1,64 @@
|
|||
{nixpkgs, agenix, home-manager, flake-utils, nixgl, rust-overlay, flake-compat
|
||||
,pkgs, lib, proj_root,...}@inputs:{
|
||||
nixosConfigurations = {
|
||||
bao = lib.mkHost {
|
||||
,pkgs, lib, proj_root, nixosDefaultVersion? "22.05", defaultSystem? "x86_64-linux",...}@finalInputs: let
|
||||
config = {
|
||||
bao.metadata = {
|
||||
# req
|
||||
hostName = "bao";
|
||||
nixosBareConfiguration = {
|
||||
# opts
|
||||
ssh_pubkey = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIIBuAaAE7TiQmMH300VRj/pYCri1qPmHjd+y9aX2J0Fs";
|
||||
nixosVersion = "22.11";
|
||||
system = "x86_64-linux";
|
||||
preset = "base";
|
||||
};
|
||||
bao.nixosConfig = {
|
||||
modules = [
|
||||
|
||||
import ../modules/kde.sys.nix
|
||||
import ../modules/pulseaudio.sys.nix
|
||||
import ../modules/storage.perso.sys.nix
|
||||
];
|
||||
};
|
||||
};
|
||||
propagate = hostConfig@{metadata, nixosConfig}: let
|
||||
# req
|
||||
inherit (metadata) hostName;
|
||||
# opts
|
||||
ssh_pubkey = lib.attrByPath ["ssh_pubkey"] null metadata; # metadata.ssh_pubkey??undefined
|
||||
users = lib.attrByPath ["users"] {} metadata;
|
||||
nixosVersion = lib.attrByPath ["nixosVersion"] nixosDefaultVersion metadata;
|
||||
system = lib.attrByPath ["system"] defaultSystem metadata;
|
||||
preset = lib.attrByPath ["preset"] "base" metadata;
|
||||
# infer
|
||||
hardwareConfig = import "${proj_root.hosts.path}/${hostName}/hardware-configuration.nix";
|
||||
in {
|
||||
inherit hostName ssh_pubkey users nixosVersion system preset hardwareConfig;
|
||||
nixosConfig = nixosConfig // {
|
||||
inherit system;
|
||||
lib = finalInputs.lib;
|
||||
modules = [
|
||||
{
|
||||
system.stateVersion = nixosVersion;
|
||||
networking.hostName = hostName;
|
||||
users.users = users;
|
||||
}
|
||||
{
|
||||
_module.args = finalInputs;
|
||||
}
|
||||
import "${proj_root.modules.path}/secrets.nix"
|
||||
import "${proj_root.modules.path}/${preset}.sys.nix"
|
||||
] ++ nixosConfig.modules;
|
||||
};
|
||||
};
|
||||
mkHostFromPropagated = propagatedHostConfig@{nixosConfig,...}: nixpkgs.lib.nixosSystem nixosConfig;
|
||||
mkHost = hostConfig: (lib.pipe [propagate mkHostFromPropagated] hostConfig);
|
||||
trimNull = lib.filterAttrs (name: value: value != null);
|
||||
flattenPubkey = lib.mapAttrs (hostName: meta_config: meta_config.metadata.ssh_pubkey);
|
||||
in {
|
||||
inherit config;
|
||||
# nixosConfigurations = lib.mapAttrs (name: hostConfig: mkHost hostConfig) config;
|
||||
nixosConfigurations = {};
|
||||
debug = {
|
||||
propagated = lib.mapAttrs (name: hostConfig: propagate hostConfig) config;
|
||||
};
|
||||
# {bao = "ssh-ed25519 ..."; another_host = "ssh-rsa ...";}
|
||||
hostKeys = trimNull (flattenPubkey config);
|
||||
}
|
||||
|
|
|
@ -18,31 +18,31 @@ in {
|
|||
) {});
|
||||
|
||||
# Configures hosts as nixosConfiguration
|
||||
mkHost = {hostName
|
||||
, nixosBareConfiguration
|
||||
, finalInputs
|
||||
, users ? {}
|
||||
, nixosVersion? nixosDefaultVersion
|
||||
, system? defaultSystem
|
||||
, preset? "base"}: # base | minimal
|
||||
let
|
||||
hardwareConfig = hostname: import "${proj_root.hosts.path}/${hostName}/hardware-configuration.nix";
|
||||
in nixpkgs.lib.nixosSystem (nixosBareConfiguration // {
|
||||
inherit system;
|
||||
modules = [
|
||||
{
|
||||
system.stateVersion = nixosVersion;
|
||||
networking.hostName = hostName;
|
||||
users.users = users;
|
||||
}
|
||||
{
|
||||
_module.args = finalInputs;
|
||||
}
|
||||
import "${proj_root.modules.path}/secrets.nix"
|
||||
import "${proj_root.modules.path}/${preset}.sys.nix"
|
||||
] ++ nixosBareConfiguration.modules;
|
||||
lib = finalInputs.lib;
|
||||
});
|
||||
# mkHost = {hostName
|
||||
# , nixosBareConfiguration
|
||||
# , finalInputs
|
||||
# , users ? {}
|
||||
# , nixosVersion? nixosDefaultVersion
|
||||
# , system? defaultSystem
|
||||
# , preset? "base"}: # base | minimal
|
||||
# let
|
||||
# hardwareConfig = hostname: import "${proj_root.hosts.path}/${hostName}/hardware-configuration.nix";
|
||||
# in nixpkgs.lib.nixosSystem (nixosBareConfiguration // {
|
||||
# inherit system;
|
||||
# modules = [
|
||||
# {
|
||||
# system.stateVersion = nixosVersion;
|
||||
# networking.hostName = hostName;
|
||||
# users.users = users;
|
||||
# }
|
||||
# {
|
||||
# _module.args = finalInputs;
|
||||
# }
|
||||
# import "${proj_root.modules.path}/secrets.nix"
|
||||
# import "${proj_root.modules.path}/${preset}.sys.nix"
|
||||
# ] ++ nixosBareConfiguration.modules;
|
||||
# lib = finalInputs.lib;
|
||||
# });
|
||||
inherit serde;
|
||||
inherit (serde) fromYaml fromYamlPath;
|
||||
}
|
||||
|
|
|
@ -10,6 +10,6 @@
|
|||
};
|
||||
rust-monorepo = {
|
||||
path = ./rust-monorepo;
|
||||
description = "hungtr's opinionated Rust monorepo, extended from ./rust, using Cargo workspace";
|
||||
description = "Opinionated Rust monorepo, extended from ./rust, using Cargo workspace";
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue