# How to setup redis server configuration.nix?

**URL:** https://discourse.nixos.org/t/how-to-setup-redis-server-configuration-nix/21878
**Category:** Help
**Created:** [September 21, 2022, 4:20pm UTC](https://discourse.nixos.org/t/how-to-setup-redis-server-configuration-nix/21878 "2022-09-21T16:20:51Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![jdaly](https://discourse.nixos.org/letter_avatar_proxy/v4/letter/j/c89c15/32.png) [@jdaly](https://discourse.nixos.org/u/jdaly)
#### Post date: [September 21, 2022, 4:20pm UTC](https://discourse.nixos.org/t/how-to-setup-redis-server-configuration-nix/21878/1 "2022-09-21T16:20:51Z")

</div>

Hi All –

New to Nixos and looking for some help on how to setup a redis server in my configuration.nix.

Both the repl and nixos search options show a wide number of options ([https://search.nixos.org/options?channel=22.05&from=0&size=50&sort=relevance&type=packages&query=services.redis.servers](https://search.nixos.org/options?channel=22.05&from=0&size=50&sort=relevance&type=packages&query=services.redis.servers)) of the form:

`services.redis.servers.<name>.<option`

For example:

```auto
services.redis.servers.<name>.enable
services.redis.servers.<name>.user
services.redis.servers.<name>.port
...
...

```

All appear to have reasonable defaults, so I’ve added the following to my configuration.nix but no redis server seems to be running.

`services.redis.servers."my-redis".enable=true;`

Thoughts?

---

<div class="post-metadata">

### Author: ![jdaly](https://discourse.nixos.org/letter_avatar_proxy/v4/letter/j/c89c15/32.png) [@jdaly](https://discourse.nixos.org/u/jdaly)
#### Post date: [September 21, 2022, 4:27pm UTC](https://discourse.nixos.org/t/how-to-setup-redis-server-configuration-nix/21878/2 "2022-09-21T16:27:29Z")

</div>

I’ve verified the redis server is install and can run it manually from the command-line as follows:

````auto
redis-server
      _.-`` `. `_. ''-._ Redis 7.0.4 (00000000/0) 64 bit
  .-`` .-```. ```\/ _.,_ ''-._                                  
 ( ' , .-` | `, ) Running in standalone mode
 |`-._`-...-` __...-.``-._|'` _.-'| Port: 6379
 | `-._ `._ / _.-' | PID: 4117
  `-._ `-._ `-./ _.-' _.-'                                   
 |`-._`-._ `-.__.-' _.-'_.-'|                                  
 | `-._`-._ _.-'_.-' | https://redis.io       
  `-._ `-._`-.__.-'_.-' _.-'                                   
 |`-._`-._ `-.__.-' _.-'_.-'|                                  
 | `-._`-._ _.-'_.-' |                                  
  `-._ `-._`-.__.-'_.-' _.-'                                   
      `-._ `-.__.-' _.-'                                       
          `-._ _.-'                                           
              `-.__.-'                                               

4117:M 21 Sep 2022 10:25:25.276 # Server initialized
4117:M 21 Sep 2022 10:25:25.276 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
4117:M 21 Sep 2022 10:25:25.276 * Loading RDB produced by version 7.0.4
4117:M 21 Sep 2022 10:25:25.276 * RDB age 96 seconds
4117:M 21 Sep 2022 10:25:25.276 * RDB memory usage when created 0.85 Mb
4117:M 21 Sep 2022 10:25:25.276 * Done loading RDB, keys loaded: 0, keys expired: 0.
4117:M 21 Sep 2022 10:25:25.276 * DB loaded from disk: 0.000 seconds
4117:M 21 Sep 2022 10:25:25.276 * Ready to accept connections

````

And I can ping it with:

```auto
redli ping
PONG

```

So, its definitely installed and running, but why doesn’t my configuration.nix start the server automatically?

---

<div class="post-metadata">

### Author: ![aanderse](https://discourse.nixos.org/user_avatar/discourse.nixos.org/aanderse/32/1420_2.png) [@aanderse](https://discourse.nixos.org/u/aanderse)
#### Post date: [September 21, 2022, 5:48pm UTC](https://discourse.nixos.org/t/how-to-setup-redis-server-configuration-nix/21878/3 "2022-09-21T17:48:35Z")

</div>

`services.redis.servers.<name>.enable` defaults to `false`, which contradicts a fair bit of other design in NixOS.

---

<div class="post-metadata">

### Author: ![jdaly](https://discourse.nixos.org/letter_avatar_proxy/v4/letter/j/c89c15/32.png) [@jdaly](https://discourse.nixos.org/u/jdaly)
#### Post date: [September 21, 2022, 6:42pm UTC](https://discourse.nixos.org/t/how-to-setup-redis-server-configuration-nix/21878/4 "2022-09-21T18:42:49Z")

</div>

@aanderse Yes, I discovered that, however, my current configuration.nix contains:

```auto
  #-------------------------------------------------------------------------
  # Enable redis server
  #-------------------------------------------------------------------------
  services.redis.servers."talos-redis".enable=true;

```

Yet, the redis server – does not start.

Any ideas?

---

<div class="post-metadata">

### Author: ![aanderse](https://discourse.nixos.org/user_avatar/discourse.nixos.org/aanderse/32/1420_2.png) [@aanderse](https://discourse.nixos.org/u/aanderse)
#### Post date: [September 21, 2022, 9:47pm UTC](https://discourse.nixos.org/t/how-to-setup-redis-server-configuration-nix/21878/5 "2022-09-21T21:47:30Z")

</div>

What does `systemctl status redis-talon-redis.service` say? What about `journalctl -u redis-talon-redis.service`?

---

<div class="post-metadata">

### Author: ![jdaly](https://discourse.nixos.org/letter_avatar_proxy/v4/letter/j/c89c15/32.png) [@jdaly](https://discourse.nixos.org/u/jdaly)
#### Post date: [September 22, 2022, 7:44pm UTC](https://discourse.nixos.org/t/how-to-setup-redis-server-configuration-nix/21878/6 "2022-09-22T19:44:39Z")

</div>

@aanderse

```auto
systemctl status redis-talon-redis.service 
Unit redis-talon-redis.service could not be found.

```

and

```auto
journalctl -u redis-talon-redis.service
-- No entries --

```

Strangely, I can see messages during booting on the console stating “Starting redis server …”

and

journalctl -b

```auto
Sep 22 13:41:23 talos-devenv redis-server[1126]: Supervised by systemd. Please make sure you set appropriate values for TimeoutStartSec and TimeoutStopSec in your service unit.
Sep 22 13:41:23 talos-devenv redis-server[1126]: oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
Sep 22 13:41:23 talos-devenv redis-server[1126]: Redis version=7.0.4, bits=64, commit=00000000, modified=0, pid=1126, just started
Sep 22 13:41:23 talos-devenv redis-server[1126]: Configuration loaded
Sep 22 13:41:23 talos-devenv redis[1126]: monotonic clock: POSIX clock_gettime
Sep 22 13:41:23 talos-devenv redis[1126]: Running mode=standalone, port=0.
Sep 22 13:41:23 talos-devenv redis[1126]: Server initialized
Sep 22 13:41:23 talos-devenv redis[1126]: WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = >
Sep 22 13:41:23 talos-devenv redis[1126]: Loading RDB produced by version 7.0.4
Sep 22 13:41:23 talos-devenv redis[1126]: RDB age 113 seconds
Sep 22 13:41:23 talos-devenv redis[1126]: RDB memory usage when created 0.82 Mb
Sep 22 13:41:23 talos-devenv redis[1126]: Done loading RDB, keys loaded: 0, keys expired: 0.
Sep 22 13:41:23 talos-devenv redis[1126]: DB loaded from disk: 0.000 seconds
Sep 22 13:41:23 talos-devenv redis[1126]: The server is now ready to accept connections at /run/redis-talos-redis/redis.sock

```

It certainly appears to be running … and should be ‘ping-able’ on port 6379 – the default port, but alas I’, seeing ‘connection refused’.

```auto
2022/09/22 13:49:05 Dial dial tcp 127.0.0.1:6379: connect: connection refused

```

If I start the server manually, ‘redis-server’ , I can ping it ‘redli ping’ as expected.

---

<div class="post-metadata">

### Author: ![jdaly](https://discourse.nixos.org/letter_avatar_proxy/v4/letter/j/c89c15/32.png) [@jdaly](https://discourse.nixos.org/u/jdaly)
#### Post date: [September 22, 2022, 8:46pm UTC](https://discourse.nixos.org/t/how-to-setup-redis-server-configuration-nix/21878/7 "2022-09-22T20:46:19Z")

</div>

@aanderse Solved redis server startup. Thanks for all your suggestions!

For what its worth, the problem appeared to be that both a ‘named’ server and ‘port’ are required.

```auto
  #-------------------------------------------------------------------------
  # Enable redis service
  #-------------------------------------------------------------------------
  services.redis.servers."talos".enable=true;
  services.redis.servers."talos".port=6379;

```

The [Nixos redis options docs](https://search.nixos.org/options?channel=22.05&show=services.redis.servers.%3Cname%3E.port&from=0&size=50&sort=relevance&type=packages&query=services.redis.servers) for “services.redis.servers..port” state if no port is supplied, the default port of 6379 will be used, however, that doesn’t seem to be the case.

```auto
services.redis.servers.<name>.port

Name

services.redis.servers.<name>.port

Description
The TCP port to accept connections. If port 0 is specified Redis will not listen on a TCP socket.
Type

16 bit unsigned integer; between 0 and 65535 (both inclusive)

Default

if name == "" then 6379 else 0

Declared in
nixos/modules/services/databases/redis.nix

```
