add nixos and darwin-nix modules
This commit is contained in:
parent
eeb8a69740
commit
ba34ac0d67
4 changed files with 129 additions and 12 deletions
62
home-module.nix
Normal file
62
home-module.nix
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
{
|
||||
config,
|
||||
lib,
|
||||
...
|
||||
}:
|
||||
let
|
||||
cfg = config.services.nix-cache-login;
|
||||
in
|
||||
{
|
||||
options.services.nix-cache-login = {
|
||||
enable = lib.mkEnableOption "nix-cache-login automatic token refresh";
|
||||
package = lib.mkOption {
|
||||
type = lib.types.package;
|
||||
description = "The nix-cache-login package to use.";
|
||||
};
|
||||
refreshInterval = lib.mkOption {
|
||||
type = lib.types.ints.positive;
|
||||
default = 900;
|
||||
description = ''
|
||||
How often to attempt token refresh, in seconds.
|
||||
If no valid session exists, the service logs an error and retries on
|
||||
the next interval. Run {command}`nix-cache-login` to log in.
|
||||
'';
|
||||
example = 1800;
|
||||
};
|
||||
};
|
||||
|
||||
config = lib.mkIf cfg.enable {
|
||||
home.packages = [ cfg.package ];
|
||||
systemd.user.services.nix-cache-login = {
|
||||
Unit.Description = "Nix cache login - refresh access token";
|
||||
Service = {
|
||||
Type = "oneshot";
|
||||
ExecStart = "${cfg.package}/bin/nix-cache-login refresh";
|
||||
};
|
||||
};
|
||||
|
||||
systemd.user.timers.nix-cache-login = {
|
||||
Unit.Description = "Nix cache login - periodic token refresh";
|
||||
Timer = {
|
||||
OnBootSec = "2min";
|
||||
OnUnitActiveSec = "${toString cfg.refreshInterval}s";
|
||||
};
|
||||
Install.WantedBy = [ "timers.target" ];
|
||||
};
|
||||
|
||||
launchd.agents.nix-cache-login = {
|
||||
enable = true;
|
||||
config = {
|
||||
ProgramArguments = [
|
||||
"${cfg.package}/bin/nix-cache-login"
|
||||
"refresh"
|
||||
];
|
||||
StartInterval = cfg.refreshInterval;
|
||||
RunAtLoad = true;
|
||||
ProcessType = "Background";
|
||||
StandardOutPath = "${config.home.homeDirectory}/Library/Logs/nix-cache-login.log";
|
||||
StandardErrorPath = "${config.home.homeDirectory}/Library/Logs/nix-cache-login.log";
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue