dotfiles/lib/default.nix

62 lines
1.9 KiB
Nix
Raw Normal View History

2023-01-13 06:42:21 +00:00
{ pkgs
# ,nixpkgs
, proj_root
# ,agenix
, nixosDefaultVersion ? "22.05"
, defaultSystem ? "x86_64-linux"
, ...
}@inputs:
let
lib = pkgs.lib;
2023-01-13 06:42:21 +00:00
inputs_w_lib = (inputs // { inherit lib; });
2022-12-27 10:47:58 +00:00
serde = import ./serde.nix inputs_w_lib;
2023-01-13 06:42:21 +00:00
shellAsDrv = { script, pname }: (pkgs.callPackage
(
# just a pattern that we must remember: args to this are children of pkgs.
{ writeShellScriptBin }: writeShellScriptBin pname script
)
{ });
2022-12-27 10:47:58 +00:00
trimNull = lib.filterAttrs (name: value: value != null);
# ssh
2023-01-13 06:42:21 +00:00
flattenPubkey = lib.mapAttrs (_identity: meta_config: lib.attrByPath [ "metadata" "ssh_pubkey" ] null meta_config);
getPubkey = config: (lib.pipe config [ flattenPubkey trimNull ]);
# procedure =
2023-01-13 06:42:21 +00:00
in
{
# short-hand to create a shell derivation
# NOTE: this is pure. This means, env vars from devShells might not
# be accessible unless MAYBE they are `export`ed
2022-12-27 10:47:58 +00:00
inherit shellAsDrv trimNull flattenPubkey getPubkey;
ssh = {
inherit flattenPubkey getPubkey;
};
# Configures hosts as nixosConfiguration
2022-12-27 05:58:24 +00:00
# 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;
# });
2022-12-27 04:22:07 +00:00
inherit serde;
inherit (serde) fromYaml fromYamlPath;
}