Skip to content

Commit

Permalink
wip: added user level service
Browse files Browse the repository at this point in the history
  • Loading branch information
brynblack committed Aug 22, 2024
1 parent a9c93c8 commit b41e52d
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 10 deletions.
1 change: 1 addition & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@
}) // (let
modules = import ./modules.nix {
inherit nixpkgs-matrix;
outputs = self.outputs;
system = "x86_64-linux";
};
in {
Expand Down
71 changes: 61 additions & 10 deletions modules.nix
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{ nixpkgs-matrix, system, ... }:
{ outputs, nixpkgs-matrix, system, ... }:

{
polykey = { config, ... }:
with nixpkgs-matrix.lib; {
with nixpkgs-matrix.lib.${system}; {
options = {
services.polykey = {
enable = mkEnableOption
Expand Down Expand Up @@ -41,8 +41,7 @@
config = mkIf config.services.polykey.enable {
users.groups.polykey = { };

environment.systemPackages =
[ self.outputs.packages.${system}.default ];
environment.systemPackages = [ outputs.packages.${system}.default ];

system.activationScripts.makeAgentPaths = ''
mkdir -p ${config.services.polykey.statePath}
Expand All @@ -61,18 +60,18 @@
LoadCredential =
[ "password:${config.services.polykey.passwordFilePath}" ];
ExecStartPre = ''
-${self.outputs.packages.${system}.default}/bin/polykey \
-${outputs.packages.${system}.default}/bin/polykey \
--password-file ''${CREDENTIALS_DIRECTORY}/password \
--node-path ${config.services.polykey.statePath} \
bootstrap ${
lib.optionalString
optionalString
(config.services.polykey.recoveryCodeFilePath != "")
"-rcf ${config.services.polykey.recoveryCodeFilePath}"
}\
--recovery-code-out-file ${config.services.polykey.recoveryCodeOutPath}
'';
ExecStart = ''
${self.outputs.packages.${system}.default}/bin/polykey \
${outputs.packages.${system}.default}/bin/polykey \
--password-file ''${CREDENTIALS_DIRECTORY}/password \
--node-path ${config.services.polykey.statePath} \
agent start \
Expand All @@ -83,15 +82,67 @@
};
};
polykey-home = { config, ... }:
with nixpkgs-matrix;
with lib; {
with nixpkgs-matrix.lib.${system}; {
options = {
programs.polykey = {
enable = mkEnableOption "Enable the user-space Polykey agent.";

passwordFilePath = mkOption {
type = with types; uniq str;
description = ''
The path to the Polykey password file. This is required to be set for the module to work, otherwise this module will fail.
'';
};

recoveryCodeFilePath = mkOption {
type = with types; uniq str;
default = "";
description = ''
The path to the Polykey recovery code file. This is not required, but if set will read a recovery code from the provided path to bootstrap a new state with.
'';
};

recoveryCodeOutPath = mkOption {
type = with types; uniq str;
description = ''
The path to the Polykey recovery code file output location.
'';
};

statePath = mkOption {
type = with types; uniq str;
default = "%h/.local/share/polykey";
description =
"The path to the Polykey node state directory. Will default to `$HOME/.local/share/polykey`, but can be overwritten to a custom path.";
};
};
};
config = mkIf config.programs.polykey.enable {
home.packages = [ self.outputs.packages.${system}.default ];
home.packages = [ outputs.packages.${system}.default ];

systemd.user.services.polykey = {
Unit = { Description = "Polykey Agent"; };
Service = {
ExecStartPre = ''
-${outputs.packages.${system}.default}/bin/polykey \
--password-file ${config.programs.polykey.passwordFilePath} \
--node-path ${config.programs.polykey.statePath} \
bootstrap ${
optionalString
(config.programs.polykey.recoveryCodeFilePath != "")
"-rcf ${config.programs.polykey.recoveryCodeFilePath}"
}\
--recovery-code-out-file ${config.programs.polykey.recoveryCodeOutPath}
'';
ExecStart = ''
${outputs.packages.${system}.default}/bin/polykey \
--password-file ${config.programs.polykey.passwordFilePath} \
--node-path ${config.programs.polykey.statePath} \
agent start \
--recovery-code-out-file ${config.programs.polykey.recoveryCodeOutPath}
'';
};
};
};
};
}

0 comments on commit b41e52d

Please sign in to comment.