diff options
Diffstat (limited to '')
| -rw-r--r-- | nix/module.hm.nix | 129 | ||||
| -rw-r--r-- | nix/module.nix | 2 | ||||
| -rw-r--r-- | nix/package.nix | 30 |
3 files changed, 147 insertions, 14 deletions
diff --git a/nix/module.hm.nix b/nix/module.hm.nix new file mode 100644 index 00000000..1891abb6 --- /dev/null +++ b/nix/module.hm.nix @@ -0,0 +1,129 @@ +{turtlePkg}: { + config, + pkgs, + lib, + ... +}: let + cfg = config.programs.turtle; + + tomlFormat = pkgs.formats.toml {}; + + inherit + (lib) + mkIf + mkOption + types + ; +in { + options.programs.turtle = { + enable = lib.mkEnableOption "turtle"; + + package = (lib.mkPackageOption pkgs "turtle" {}) // {default = turtlePkg;}; + + settings = mkOption { + type = with types; let + prim = oneOf [ + bool + int + str + ]; + primOrPrimAttrs = either prim (attrsOf prim); + entry = either prim (listOf primOrPrimAttrs); + entryOrAttrsOf = t: either entry (attrsOf t); + entries = entryOrAttrsOf (entryOrAttrsOf entry); + in + attrsOf entries // {description = "Turtle configuration";}; + default = {}; + example = lib.literalExpression '' + { + auto_sync = true; + sync_frequency = "5m"; + sync_address = "https://api.atuin.sh"; + search_mode = "prefix"; + } + ''; + description = '' + Configuration written to + {file}`$XDG_CONFIG_HOME/turtle/config.toml`. + ''; + }; + + daemon = { + logLevel = mkOption { + default = null; + type = types.nullOr ( + types.enum [ + "trace" + "debug" + "info" + "warn" + "error" + ] + ); + description = '' + Verbosity of Turtle daemon logging. + ''; + }; + }; + }; + + config = mkIf cfg.enable { + assertions = [ + { + assertion = config.systemd.user.enable || config.launchd.enable; + message = "The Turtle daemon can only be configured on systems with systemd or launchd."; + } + ]; + + # Always add the configured `turtle` package. + home.packages = [cfg.package]; + + # If there are user-provided settings, generate the config file. + xdg.configFile = lib.mkMerge [ + (mkIf (cfg.settings != {}) { + "turtle/config.toml" = { + source = tomlFormat.generate "turtle-config" cfg.settings; + }; + }) + ]; + + programs.turtle.settings.daemon = { + systemd_socket = config.systemd.user.enable; + socket_path = lib.mkIf (!config.systemd.user.enable) ( + lib.mkDefault "${config.xdg.dataHome}/turtle/daemon.sock" + ); + }; + + systemd.user.services.turtle-daemon = { + Unit = { + Description = "Turtle daemon"; + Requires = ["turtle-daemon.socket"]; + }; + Install = { + Also = ["turtle-daemon.socket"]; + WantedBy = ["default.target"]; + }; + Service = { + ExecStart = "${lib.getExe' cfg.package "turtle-daemon"} start"; + Environment = lib.optionals (cfg.daemon.logLevel != null) ["ATUIN_LOG=${cfg.daemon.logLevel}"]; + Restart = "on-failure"; + RestartSteps = 3; + RestartMaxDelaySec = 6; + }; + }; + + systemd.user.sockets.turtle-daemon = { + Unit = { + Description = "Turtle daemon socket"; + }; + Install = { + WantedBy = ["sockets.target"]; + }; + Socket = { + ListenStream = "%t/turtle.sock"; + SocketMode = "0600"; + RemoveOnStop = true; + }; + }; + }; +} diff --git a/nix/module.nix b/nix/module.nix index 60878e7e..30ff417b 100644 --- a/nix/module.nix +++ b/nix/module.nix @@ -89,7 +89,7 @@ in { wantedBy = ["multi-user.target"]; serviceConfig = { - ExecStart = "${lib.getExe' cfg.package "atuin"} server start"; + ExecStart = "${lib.getExe' cfg.package "turtle-server"} start"; EnvironmentFile = lib.mkIf (cfg.environmentFile != null) [cfg.environmentFile]; RuntimeDirectory = "turtle"; RuntimeDirectoryMode = "0700"; diff --git a/nix/package.nix b/nix/package.nix index 3fd24aee..8712c3a2 100644 --- a/nix/package.nix +++ b/nix/package.nix @@ -8,11 +8,11 @@ lib, stdenv, installShellFiles, - rustPlatform, libiconv, + craneLib, }: -rustPlatform.buildRustPackage { - name = "turtle"; +craneLib.buildPackage { + pname = "turtle"; version = "19.0.0"; src = lib.cleanSourceWith { @@ -36,21 +36,25 @@ rustPlatform.buildRustPackage { || (lib.strings.hasSuffix ".sql" (builtins.baseNameOf name)); }; - cargoLock = { - lockFile = ../Cargo.lock; - # Allow dependencies to be fetched from git and avoid having to set the outputHashes manually - allowBuiltinFetchGit = true; - }; + # env = { + # CARGO_PROFILE = "dev"; + # }; + + # cargoLock = { + # lockFile = ../Cargo.lock; + # # Allow dependencies to be fetched from git and avoid having to set the outputHashes manually + # allowBuiltinFetchGit = true; + # }; nativeBuildInputs = [installShellFiles]; buildInputs = lib.optionals stdenv.isDarwin [libiconv]; postInstall = '' - installShellCompletion --cmd atuin \ - --bash <($out/bin/atuin gen-completions -s bash) \ - --fish <($out/bin/atuin gen-completions -s fish) \ - --zsh <($out/bin/atuin gen-completions -s zsh) + installShellCompletion --cmd turtle \ + --bash <($out/bin/turtle gen-completions -s bash) \ + --fish <($out/bin/turtle gen-completions -s fish) \ + --zsh <($out/bin/turtle gen-completions -s zsh) ''; doCheck = false; @@ -59,6 +63,6 @@ rustPlatform.buildRustPackage { description = "Replacement for a shell history which records additional commands context with optional encrypted synchronization between machines"; homepage = "https://github.com/atuinsh/atuin"; license = licenses.mit; - mainProgram = "atuin"; + mainProgram = "turtle"; }; } |
