lib: standardize the required arguments

Just to make it consistent.
This commit is contained in:
Gabriel Arazas 2024-03-01 18:09:47 +08:00
parent d183306336
commit 40352d6a74
No known key found for this signature in database
GPG Key ID: ADE0C41DAB221FCC
5 changed files with 21 additions and 49 deletions

View File

@ -1,43 +1,14 @@
# All of the functions suitable only for NixOS.
{ pkgs, config, lib }:
{ pkgs, lib }:
rec {
# This is only used for home-manager users without a NixOS user counterpart.
mapHomeManagerUser = user: settings:
let
homeDirectory = "/home/${user}";
defaultUserConfig = {
extraGroups = pkgs.lib.mkDefault [ "wheel" ];
createHome = pkgs.lib.mkDefault true;
home = pkgs.lib.mkDefault homeDirectory;
isNormalUser = pkgs.lib.mkForce true;
};
in
({ lib, ... }: {
home-manager.users."${user}" = { ... }: {
imports = [
{
home.username = user;
home.homeDirectory = homeDirectory;
}
../configs/home-manager/${user}
];
};
users.users."${user}" = lib.mkMerge [
defaultUserConfig
settings
];
});
# Checks if the NixOS configuration is part of the nixos-generator build.
# Typically, we just check if there's a certain attribute that is imported
# from it.
hasNixosFormat =
hasNixosFormat = config:
pkgs.lib.hasAttrByPath [ "formatAttr" ] config;
# Checks if the NixOS config is being built for a particular format.
isFormat = format:
hasNixosFormat && config.formatAttr == format;
isFormat = config: format:
hasNixosFormat config && config.formatAttr == format;
}

View File

@ -1,6 +1,6 @@
{ config, pkgs, lib }:
{ pkgs, lib }:
{
isStandalone =
isStandalone = config:
!config?hmConfig && !config?nixosConfig && !config?darwinConfig;
}

View File

@ -1,15 +1,15 @@
# All of the extra module arguments to be passed as part of the home-manager
# environment.
{ options, pkgs, lib, ... }:
{ pkgs, lib, options, ... }:
let
foodogsquaredLib = import ../../../lib { inherit pkgs; };
in
{
_module.args.foodogsquaredLib =
foodogsquaredLib.extend (final: prev:
import ../../../lib/home-manager.nix { inherit pkgs; lib = prev; }
// lib.optionalAttrs (options?sops) {
foodogsquaredLib.extend (final: prev: {
home-manager = import ../../../lib/home-manager.nix { inherit pkgs; lib = prev; };
} // lib.optionalAttrs (options?sops) {
sops-nix = import ../../../lib/sops.nix { inherit pkgs; lib = prev; };
});
}

View File

@ -1,15 +1,15 @@
# All of the extra module arguments to be passed as part of the holistic NixOS
# system.
{ config, options, lib, pkgs, ... }:
{ pkgs, lib, options, ... }:
let
foodogsquaredLib = import ../../../lib { inherit pkgs; };
in
{
_module.args.foodogsquaredLib =
foodogsquaredLib.extend (final: prev:
import ../../../lib/nixos.nix { inherit pkgs config; lib = prev; }
// lib.optionalAttrs (options?sops) {
sops-nix = import ../../../lib/sops.nix { inherit pkgs; lib = prev; };
foodogsquaredLib.extend (final: prev: {
nixos = import ../../../lib/nixos.nix { inherit pkgs; lib = final; };
} // lib.optionalAttrs (options?sops) {
sops-nix = import ../../../lib/sops.nix { inherit pkgs; lib = final; };
});
}

View File

@ -6,6 +6,7 @@ let
in
{
_module.args.foodogsquaredLib =
foodogsquaredLib.extend (final: prev:
import ../../../lib/nixvim.nix { inherit config pkgs; lib = prev; });
foodogsquaredLib.extend (final: prev: {
nixvim = import ../../../lib/nixvim.nix { inherit pkgs; lib = prev; };
});
}