diff --git a/README.md b/README.md index b0211b5..cbf1cd4 100644 --- a/README.md +++ b/README.md @@ -25,8 +25,8 @@ Legend: | ✨ | `nixng-prowlarr` | | | ✨ | `nixng-deluge` | | | ✨ | `nixng-mealie` | | +| ✨ | `nixng-atuin` | | | ✅ | `jellyfin/jellyfin` | | -| ✅ | `ghcr.io/atuinsh/atuin` | | | ✅ | `postgres:14` | Database for Atuin | | ✅ | `ghcr.io/paperless-ngx/paperless-ngx` | | | ✅ | `docker.io/library/redis:7` | Database for Paperless-ngx | diff --git a/modules/atuin.nix b/modules/atuin.nix index 7485f9f..9552e8f 100644 --- a/modules/atuin.nix +++ b/modules/atuin.nix @@ -1,5 +1,6 @@ { config, + utils, globals, lib, ... @@ -29,35 +30,17 @@ metadata.labels.app = "atuin"; spec = { - volumes = { - data.persistentVolumeClaim.claimName = "data"; - database.persistentVolumeClaim.claimName = "database"; - }; + volumes.database.persistentVolumeClaim.claimName = "database"; containers = { atuin = { - image = globals.images.atuin; - imagePullPolicy = "IfNotPresent"; + image = utils.mkNixNGImage "atuin"; ports.web.containerPort = 8888; - args = ["server" "start"]; - env = { - ATUIN_HOST.value = "0.0.0.0"; - ATUIN_PORT.value = "8888"; - ATUIN_OPEN_REGISTRATION.value = "false"; - - ATUIN_DB_URI.valueFrom.secretKeyRef = { - name = "database"; - key = "databaseURL"; - }; + env.ATUIN_DB_URI.valueFrom.secretKeyRef = { + name = "database"; + key = "databaseURL"; }; - - volumeMounts = [ - { - name = "data"; - mountPath = "/config"; - } - ]; }; database = { @@ -106,16 +89,9 @@ }; }; - longhorn.persistentVolumeClaim = { - data = { - volumeName = "atuin"; - storage = "300Mi"; - }; - - database = { - volumeName = "atuin-db"; - storage = "300Mi"; - }; + longhorn.persistentVolumeClaim.database = { + volumeName = "atuin-db"; + storage = "300Mi"; }; }; }; diff --git a/modules/bootstrap-default.nix b/modules/bootstrap-default.nix index d9c419c..e685d58 100644 --- a/modules/bootstrap-default.nix +++ b/modules/bootstrap-default.nix @@ -92,7 +92,6 @@ longhorn.persistentVolume = { freshrss.storage = "1Gi"; radicale.storage = "200Mi"; - atuin.storage = "300Mi"; atuin-db.storage = "300Mi"; nextcloud.storage = "50Gi"; nextcloud-db.storage = "400Mi"; diff --git a/nixng-configurations/atuin.nix b/nixng-configurations/atuin.nix new file mode 100644 index 0000000..189895e --- /dev/null +++ b/nixng-configurations/atuin.nix @@ -0,0 +1,12 @@ +{ + dinit.enable = true; + init.services.atuin.shutdownOnExit = true; + + services.atuin = { + enable = true; + + settings = { + open_registration = false; + }; + }; +} diff --git a/nixng-configurations/default.nix b/nixng-configurations/default.nix index c1803c8..aa10a38 100644 --- a/nixng-configurations/default.nix +++ b/nixng-configurations/default.nix @@ -22,6 +22,7 @@ flake-utils.lib.eachDefaultSystem (system: let blog = ./blog.nix; deluge = ./deluge.nix; mealie = ./mealie.nix; + atuin = ./atuin.nix; }; in { nixngConfigurations = builtins.mapAttrs (name: configFile: @@ -44,7 +45,7 @@ in { self.nixngModules.sonarr self.nixngModules.prowlarr self.nixngModules.deluge - self.nixngModules.mealie + self.nixngModules.atuin { nixpkgs.overlays = [ (_final: _prev: { diff --git a/nixng-modules/atuin.nix b/nixng-modules/atuin.nix new file mode 100644 index 0000000..914f5a7 --- /dev/null +++ b/nixng-modules/atuin.nix @@ -0,0 +1,86 @@ +{ + pkgs, + lib, + nglib, + config, + ... +}: let + cfg = config.services.atuin; + cfgInit = config.init.services.atuin; + settingsFormat = pkgs.formats.toml {}; +in { + options.services.atuin = { + enable = lib.mkEnableOption "atuin"; + package = lib.mkPackageOption pkgs "atuin" {}; + + settings = lib.mkOption { + type = lib.types.submodule { + freeformType = settingsFormat.type; + + options = { + host = lib.mkOption { + type = lib.types.str; + default = "0.0.0.0"; + description = "The host to listen on"; + }; + + port = lib.mkOption { + type = lib.types.port; + default = 8888; + description = "The TCP port to listen on"; + }; + + open_registration = lib.mkOption { + type = lib.types.bool; + default = false; + description = "If true, accept new user registrations"; + }; + + db_uri = lib.mkOption { + type = with lib.types; nullOr str; + default = null; + description = "A valid PostgreSQL URI, for saving history"; + }; + + path = lib.mkOption { + type = lib.types.str; + default = ""; + description = "A path to prepend to all the routes of the server"; + }; + }; + }; + }; + }; + + config = lib.mkIf cfg.enable { + init.services.atuin = { + enabled = true; + user = lib.mkDefault "atuin"; + group = lib.mkDefault "atuin"; + + script = pkgs.writeShellScript "atuin-run" '' + ${lib.getExe cfg.package} server start + ''; + }; + + environment = { + systemPackages = [cfg.package]; + + variables.ATUIN_CONFIG_DIR = let + settingsFile = settingsFormat.generate "server.toml" (lib.filterAttrs (_: v: v != null) cfg.settings); + in + toString (pkgs.writeTextDir "server.toml" (builtins.readFile settingsFile)); + }; + + users.users.${cfgInit.user} = nglib.mkDefaultRec { + description = "atuin"; + inherit (cfgInit) group; + createHome = false; + home = "/var/empty"; + useDefaultShell = true; + uid = config.ids.uids.atuin; + }; + + users.groups.${cfgInit.group} = nglib.mkDefaultRec {gid = config.ids.gids.atuin;}; + }; +} diff --git a/nixng-modules/default.nix b/nixng-modules/default.nix index 629a244..01f9eed 100644 --- a/nixng-modules/default.nix +++ b/nixng-modules/default.nix @@ -9,5 +9,6 @@ _: { ids = import ./ids.nix; deluge = import ./deluge.nix; mealie = import ./mealie.nix; + atuin = import ./atuin.nix; }; } diff --git a/nixng-modules/ids.nix b/nixng-modules/ids.nix index 228b5da..1470307 100644 --- a/nixng-modules/ids.nix +++ b/nixng-modules/ids.nix @@ -9,6 +9,7 @@ prowlarr = 413; deluge = 414; mealie = 415; + atuin = 416; }; gids = { @@ -21,6 +22,7 @@ prowlarr = 413; deluge = 414; mealie = 415; + atuin = 416; }; }; }