Merge pull request 'clanModules/root-password: Add inventory feature' (#2795) from kenji/clan-core:feat-inventory/root-password into main
Reviewed-on: https://git.clan.lol/clan/clan-core/pulls/2795
This commit is contained in:
@@ -1,5 +1,7 @@
|
|||||||
---
|
---
|
||||||
description = "Automatically generates and configures a password for the root user."
|
description = "Automatically generates and configures a password for the root user."
|
||||||
|
categories = ["System"]
|
||||||
|
features = [ "inventory" ]
|
||||||
---
|
---
|
||||||
|
|
||||||
After the system was installed/deployed the following command can be used to display the root-password:
|
After the system was installed/deployed the following command can be used to display the root-password:
|
||||||
|
|||||||
@@ -1,35 +1,6 @@
|
|||||||
|
# Dont import this file
|
||||||
|
# It is only here for backwards compatibility.
|
||||||
|
# Dont author new modules with this file.
|
||||||
{
|
{
|
||||||
pkgs,
|
imports = [ ./roles/default.nix ];
|
||||||
config,
|
|
||||||
...
|
|
||||||
}:
|
|
||||||
{
|
|
||||||
users.mutableUsers = false;
|
|
||||||
users.users.root.hashedPasswordFile =
|
|
||||||
config.clan.core.vars.generators.root-password.files.password-hash.path;
|
|
||||||
|
|
||||||
clan.core.vars.generators.root-password = {
|
|
||||||
files.password-hash = {
|
|
||||||
neededFor = "users";
|
|
||||||
};
|
|
||||||
migrateFact = "root-password";
|
|
||||||
runtimeInputs = [
|
|
||||||
pkgs.coreutils
|
|
||||||
pkgs.mkpasswd
|
|
||||||
pkgs.xkcdpass
|
|
||||||
];
|
|
||||||
prompts.password.type = "hidden";
|
|
||||||
prompts.password.persist = true;
|
|
||||||
prompts.password.description = "You can autogenerate a password, if you leave this prompt blank.";
|
|
||||||
|
|
||||||
script = ''
|
|
||||||
prompt_value=$(cat $prompts/password)
|
|
||||||
if [[ -n ''${prompt_value-} ]]; then
|
|
||||||
echo $prompt_value | tr -d "\n" > $out/password
|
|
||||||
else
|
|
||||||
xkcdpass --numwords 3 --delimiter - --count 1 | tr -d "\n" > $out/password
|
|
||||||
fi
|
|
||||||
mkpasswd -s -m sha-512 < $out/password | tr -d "\n" > $out/password-hash
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|||||||
35
clanModules/root-password/roles/default.nix
Normal file
35
clanModules/root-password/roles/default.nix
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
{
|
||||||
|
pkgs,
|
||||||
|
config,
|
||||||
|
...
|
||||||
|
}:
|
||||||
|
{
|
||||||
|
users.mutableUsers = false;
|
||||||
|
users.users.root.hashedPasswordFile =
|
||||||
|
config.clan.core.vars.generators.root-password.files.password-hash.path;
|
||||||
|
|
||||||
|
clan.core.vars.generators.root-password = {
|
||||||
|
files.password-hash = {
|
||||||
|
neededFor = "users";
|
||||||
|
};
|
||||||
|
migrateFact = "root-password";
|
||||||
|
runtimeInputs = [
|
||||||
|
pkgs.coreutils
|
||||||
|
pkgs.mkpasswd
|
||||||
|
pkgs.xkcdpass
|
||||||
|
];
|
||||||
|
prompts.password.type = "hidden";
|
||||||
|
prompts.password.persist = true;
|
||||||
|
prompts.password.description = "You can autogenerate a password, if you leave this prompt blank.";
|
||||||
|
|
||||||
|
script = ''
|
||||||
|
prompt_value=$(cat $prompts/password)
|
||||||
|
if [[ -n ''${prompt_value-} ]]; then
|
||||||
|
echo $prompt_value | tr -d "\n" > $out/password
|
||||||
|
else
|
||||||
|
xkcdpass --numwords 3 --delimiter - --count 1 | tr -d "\n" > $out/password
|
||||||
|
fi
|
||||||
|
mkpasswd -s -m sha-512 < $out/password | tr -d "\n" > $out/password-hash
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user