Last active
May 18, 2016 08:04
-
-
Save hschaeidt/6a64914284ad87853a027adf57004d84 to your computer and use it in GitHub Desktop.
nix read user keys
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ config, pkgs, ... }: | |
{ | |
## | |
## User management | |
## | |
users.users = | |
let loadUserConfiguration = userName: | |
# set structure chosen to fit the builtins.listToAttrs | |
{ | |
name = userName; | |
value = { | |
openssh = { | |
authorizedKeys = { | |
keyFiles = | |
let verifyKeyFile = fileName: | |
if (builtins.substring ((builtins.stringLength fileName) - 3) 3 fileName) == "pub" then (./users/- + userName + "-/-" + (builtins.substring 1 ((builtins.stringLength fileName) - 1) fileName)) else ""; | |
in map verifyKeyFile (builtins.attrNames (builtins.readDir (./users/- + userName + "-"))); | |
}; | |
}; | |
}; | |
}; | |
# read the user directory; map it to a substring removing the trailing and leading "-" dash; map it to the above declared function; convert the list to a set | |
in builtins.listToAttrs (map loadUserConfiguration (map (userName: builtins.substring 1 ((builtins.stringLength userName) - 2) userName) (builtins.attrNames (builtins.readDir ./users)))); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment