refactored leyla packages into several folders
This commit is contained in:
parent
1a4c2b2f95
commit
dd53735354
13 changed files with 275 additions and 233 deletions
|
@ -6,6 +6,7 @@
|
|||
...
|
||||
}: {
|
||||
options.programs.openssh = {
|
||||
enable = lib.mkEnableOption "should we enable openssh";
|
||||
authorizedKeys = lib.mkOption {
|
||||
type = lib.types.listOf lib.types.str;
|
||||
default = [];
|
||||
|
@ -37,63 +38,65 @@
|
|||
};
|
||||
};
|
||||
|
||||
config = lib.mkMerge [
|
||||
(
|
||||
lib.mkIf ((builtins.length config.programs.openssh.hostKeys) != 0) {
|
||||
services.ssh-agent.enable = true;
|
||||
programs.ssh = {
|
||||
enable = true;
|
||||
compression = true;
|
||||
addKeysToAgent = "confirm";
|
||||
extraConfig = lib.strings.concatLines (
|
||||
builtins.map (hostKey: "IdentityFile ~/.ssh/${hostKey.path}") config.programs.openssh.hostKeys
|
||||
config = lib.mkIf config.programs.openssh.enable (
|
||||
lib.mkMerge [
|
||||
(
|
||||
lib.mkIf ((builtins.length config.programs.openssh.hostKeys) != 0) {
|
||||
services.ssh-agent.enable = true;
|
||||
programs.ssh = {
|
||||
enable = true;
|
||||
compression = true;
|
||||
addKeysToAgent = "confirm";
|
||||
extraConfig = lib.strings.concatLines (
|
||||
builtins.map (hostKey: "IdentityFile ~/.ssh/${hostKey.path}") config.programs.openssh.hostKeys
|
||||
);
|
||||
};
|
||||
|
||||
systemd.user.services = builtins.listToAttrs (
|
||||
builtins.map (hostKey:
|
||||
lib.attrsets.nameValuePair "ssh-gen-keys-${hostKey.path}" {
|
||||
Install = {
|
||||
WantedBy = ["default.target"];
|
||||
};
|
||||
Service = let
|
||||
path = "${config.home.homeDirectory}/.ssh/${hostKey.path}";
|
||||
in {
|
||||
Restart = "always";
|
||||
Type = "simple";
|
||||
ExecStart = "${
|
||||
pkgs.writeShellScript "ssh-gen-keys" ''
|
||||
if ! [ -s "${path}" ]; then
|
||||
if ! [ -h "${path}" ]; then
|
||||
rm -f "${path}"
|
||||
fi
|
||||
mkdir -p "$(dirname '${path}')"
|
||||
chmod 0755 "$(dirname '${path}')"
|
||||
${pkgs.openssh}/bin/ssh-keygen \
|
||||
-t "${hostKey.type}" \
|
||||
${lib.optionalString (hostKey ? bits) "-b ${toString hostKey.bits}"} \
|
||||
${lib.optionalString (hostKey ? rounds) "-a ${toString hostKey.rounds}"} \
|
||||
${lib.optionalString (hostKey ? comment) "-C '${hostKey.comment}'"} \
|
||||
${lib.optionalString (hostKey ? openSSHFormat && hostKey.openSSHFormat) "-o"} \
|
||||
-f "${path}" \
|
||||
-N ""
|
||||
chown ${config.home.username} ${path}*
|
||||
chgrp ${config.home.username} ${path}*
|
||||
fi
|
||||
''
|
||||
}";
|
||||
};
|
||||
})
|
||||
config.programs.openssh.hostKeys
|
||||
);
|
||||
}
|
||||
)
|
||||
(lib.mkIf osConfig.host.impermanence.enable {
|
||||
home.persistence."/persist${config.home.homeDirectory}" = {
|
||||
files = lib.lists.flatten (
|
||||
builtins.map (hostKey: [".ssh/${hostKey.path}" ".ssh/${hostKey.path}.pub"]) config.programs.openssh.hostKeys
|
||||
);
|
||||
};
|
||||
|
||||
systemd.user.services = builtins.listToAttrs (
|
||||
builtins.map (hostKey:
|
||||
lib.attrsets.nameValuePair "ssh-gen-keys-${hostKey.path}" {
|
||||
Install = {
|
||||
WantedBy = ["default.target"];
|
||||
};
|
||||
Service = let
|
||||
path = "${config.home.homeDirectory}/.ssh/${hostKey.path}";
|
||||
in {
|
||||
Restart = "always";
|
||||
Type = "simple";
|
||||
ExecStart = "${
|
||||
pkgs.writeShellScript "ssh-gen-keys" ''
|
||||
if ! [ -s "${path}" ]; then
|
||||
if ! [ -h "${path}" ]; then
|
||||
rm -f "${path}"
|
||||
fi
|
||||
mkdir -p "$(dirname '${path}')"
|
||||
chmod 0755 "$(dirname '${path}')"
|
||||
${pkgs.openssh}/bin/ssh-keygen \
|
||||
-t "${hostKey.type}" \
|
||||
${lib.optionalString (hostKey ? bits) "-b ${toString hostKey.bits}"} \
|
||||
${lib.optionalString (hostKey ? rounds) "-a ${toString hostKey.rounds}"} \
|
||||
${lib.optionalString (hostKey ? comment) "-C '${hostKey.comment}'"} \
|
||||
${lib.optionalString (hostKey ? openSSHFormat && hostKey.openSSHFormat) "-o"} \
|
||||
-f "${path}" \
|
||||
-N ""
|
||||
chown ${config.home.username} ${path}*
|
||||
chgrp ${config.home.username} ${path}*
|
||||
fi
|
||||
''
|
||||
}";
|
||||
};
|
||||
})
|
||||
config.programs.openssh.hostKeys
|
||||
);
|
||||
}
|
||||
)
|
||||
(lib.mkIf osConfig.host.impermanence.enable {
|
||||
home.persistence."/persist${config.home.homeDirectory}" = {
|
||||
files = lib.lists.flatten (
|
||||
builtins.map (hostKey: [".ssh/${hostKey.path}" ".ssh/${hostKey.path}.pub"]) config.programs.openssh.hostKeys
|
||||
);
|
||||
};
|
||||
})
|
||||
];
|
||||
})
|
||||
]
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue