-
-
Notifications
You must be signed in to change notification settings - Fork 14.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #196417 from jfroche/feat/cachix-watch-store
nixos: add cachix watch-store service
- Loading branch information
Showing
1 changed file
with
87 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
{ config, pkgs, lib, ... }: | ||
|
||
with lib; | ||
|
||
let | ||
cfg = config.services.cachix-watch-store; | ||
in | ||
{ | ||
meta.maintainers = [ lib.maintainers.jfroche lib.maintainers.domenkozar ]; | ||
|
||
options.services.cachix-watch-store = { | ||
enable = mkEnableOption (lib.mdDoc "Cachix Watch Store: https://docs.cachix.org"); | ||
|
||
cacheName = mkOption { | ||
type = types.str; | ||
description = lib.mdDoc "Cachix binary cache name"; | ||
}; | ||
|
||
cachixTokenFile = mkOption { | ||
type = types.path; | ||
description = lib.mdDoc '' | ||
Required file that needs to contain the cachix auth token. | ||
''; | ||
}; | ||
|
||
compressionLevel = mkOption { | ||
type = types.nullOr types.int; | ||
description = lib.mdDoc "The compression level for XZ compression (between 0 and 9)"; | ||
default = null; | ||
}; | ||
|
||
jobs = mkOption { | ||
type = types.nullOr types.int; | ||
description = lib.mdDoc "Number of threads used for pushing store paths"; | ||
default = null; | ||
}; | ||
|
||
host = mkOption { | ||
type = types.nullOr types.str; | ||
default = null; | ||
description = lib.mdDoc "Cachix host to connect to"; | ||
}; | ||
|
||
verbose = mkOption { | ||
type = types.bool; | ||
description = lib.mdDoc "Enable verbose output"; | ||
default = false; | ||
}; | ||
|
||
package = mkOption { | ||
type = types.package; | ||
default = pkgs.cachix; | ||
defaultText = literalExpression "pkgs.cachix"; | ||
description = lib.mdDoc "Cachix Client package to use."; | ||
}; | ||
|
||
}; | ||
|
||
config = mkIf cfg.enable { | ||
systemd.services.cachix-watch-store-agent = { | ||
description = "Cachix watch store Agent"; | ||
after = [ "network-online.target" ]; | ||
path = [ config.nix.package ]; | ||
wantedBy = [ "multi-user.target" ]; | ||
serviceConfig = { | ||
# we don't want to kill children processes as those are deployments | ||
KillMode = "process"; | ||
Restart = "on-failure"; | ||
DynamicUser = true; | ||
LoadCredential = [ | ||
"cachix-token:${toString cfg.cachixTokenFile}" | ||
]; | ||
}; | ||
script = | ||
let | ||
command = [ "${cfg.package}/bin/cachix" ] | ||
++ (lib.optional cfg.verbose "--verbose") ++ (lib.optionals (cfg.host != null) [ "--host" cfg.host ]) | ||
++ [ "watch-store" ] ++ (lib.optionals (cfg.compressionLevel != null) [ "--compression-level" (toString cfg.compressionLevel) ]) | ||
++ (lib.optionals (cfg.jobs != null) [ "--jobs" (toString cfg.jobs) ]) ++ [ cfg.cacheName ]; | ||
in | ||
'' | ||
export CACHIX_AUTH_TOKEN="$(<"$CREDENTIALS_DIRECTORY/cachix-token")" | ||
${lib.escapeShellArgs command} | ||
''; | ||
}; | ||
}; | ||
} |