mirror of
https://github.com/foo-dogsquared/nixos-config.git
synced 2025-02-12 06:19:00 +00:00
lib: privatize parts of library
Some of the functions cater to this specific setup so no need to export them.
This commit is contained in:
parent
d091d5c29d
commit
40492d55b7
@ -87,8 +87,9 @@
|
|||||||
|
|
||||||
# We're considering this as the variant since we'll export the custom
|
# We're considering this as the variant since we'll export the custom
|
||||||
# library as `lib` in the output attribute.
|
# library as `lib` in the output attribute.
|
||||||
lib' =
|
lib' = nixpkgs.lib.extend (final: prev:
|
||||||
nixpkgs.lib.extend (final: prev: import ./lib { lib = nixpkgs.lib; });
|
import ./lib { lib = prev; }
|
||||||
|
// import ./lib/private.nix { lib = final; });
|
||||||
|
|
||||||
mkHost = { system ? defaultSystem, extraModules ? [ ] }:
|
mkHost = { system ? defaultSystem, extraModules ? [ ] }:
|
||||||
(lib'.makeOverridable inputs.nixpkgs.lib.nixosSystem) {
|
(lib'.makeOverridable inputs.nixpkgs.lib.nixosSystem) {
|
||||||
|
@ -60,33 +60,6 @@ rec {
|
|||||||
let paths = lib.collect builtins.isPath attrs;
|
let paths = lib.collect builtins.isPath attrs;
|
||||||
in builtins.map (path: import path) paths;
|
in builtins.map (path: import path) paths;
|
||||||
|
|
||||||
/* Return an attribute set of valid users from a given list of users.
|
|
||||||
This is a convenience function for getting users from the `./users` directory.
|
|
||||||
|
|
||||||
Signature:
|
|
||||||
list -> attrset
|
|
||||||
Where:
|
|
||||||
- `list` is a list of usernames as strings
|
|
||||||
- `attrset` is a set of valid users with the name as the key and the path as the value.
|
|
||||||
Example:
|
|
||||||
# Assuming only 'foo-dogsquared' is the existing user for 'home-manager'.
|
|
||||||
getUsers "home-manager" [ "foo-dogsquared" "archie" "brad" ]
|
|
||||||
=> { foo-dogsquared = /home/foo-dogsquared/projects/nixos-config/users/foo-dogsquared; }
|
|
||||||
*/
|
|
||||||
getUsers = type: users:
|
|
||||||
let
|
|
||||||
userModules = filesToAttr ../users/${type};
|
|
||||||
invalidUsernames = [ "config" "modules" ];
|
|
||||||
in lib.filterAttrs (n: _: !lib.elem n invalidUsernames && lib.elem n users) userModules;
|
|
||||||
|
|
||||||
|
|
||||||
# Return the path of `user` from `type`.
|
|
||||||
getUser = type: user:
|
|
||||||
lib.getAttr user (getUsers type [ user ]);
|
|
||||||
|
|
||||||
# Return the path of `secrets` from `../secrets`.
|
|
||||||
getSecret = path: ../secrets/${path};
|
|
||||||
|
|
||||||
/* Count the attributes with the given predicate.
|
/* Count the attributes with the given predicate.
|
||||||
|
|
||||||
Examples:
|
Examples:
|
||||||
|
23
lib/private.nix
Normal file
23
lib/private.nix
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
# This is just a library intended solely for this flake.
|
||||||
|
# It is expected to use the nixpkgs library with `lib/default.nix`.
|
||||||
|
{ lib }:
|
||||||
|
|
||||||
|
rec {
|
||||||
|
getSecret = path: ../secrets/${path};
|
||||||
|
|
||||||
|
getUsers = type: users:
|
||||||
|
let
|
||||||
|
userModules = lib.filesToAttr ../users/${type};
|
||||||
|
invalidUsernames = [ "config" "modules" ];
|
||||||
|
|
||||||
|
users' = lib.filterAttrs (n: _: !lib.elem n invalidUsernames && lib.elem n users) userModules;
|
||||||
|
userList = lib.attrNames users';
|
||||||
|
|
||||||
|
nonExistentUsers = lib.filter (name: !lib.elem name userList) users;
|
||||||
|
in lib.trivial.throwIfNot ((lib.length nonExistentUsers) == 0)
|
||||||
|
"there are no users ${lib.concatMapStringsSep ", " (u: "'${u}'") nonExistentUsers} from ${type}"
|
||||||
|
(r: r) users';
|
||||||
|
|
||||||
|
getUser = type: user:
|
||||||
|
lib.getAttr user (getUsers type [ user ]);
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user