While you might be tempted to run all your applications natively in nix, there
might come the time when you find something that is not packaged in nix and only
available as a docker image. You obviously can run docker containers like you
would do on any other Linux distribution after installing the docker
package,
but you might want to specify the containers decoratively inside your
configuration.nix
.
Guess what? NixOS will happily do it for you! I've been using the bitwarden password manager for a while, specifically I'm hosting the bitwarden_rs bitwarden compatible server written in Rust.
Consider the following command used to run an instance of the container on my old server:
The usual "docker stuff" really, nothing special: An image, some environment
variables, some ports and a volume. The command above can be easily "translated"
into the following snippet inside your /etc/nixos/configuration.nix
file.
virtualisation.oci-containers.containers = {
bitwardenrs = {
autoStart = true;
image = "bitwardenrs/server:latest";
environment = {
ADMIN_TOKEN = "myAdminTokenString";
DOMAIN = "https://pw.mydomain.com";
INVITATIONS_ALLOWED="true";
SIGNUPS_ALLOWED = "true";
YUBICO_CLIENT_ID="12345" ;
YUBICO_SECRET_KEY="myYubicoSecretKeyString" ;
};
ports = [
"80:80"
];
volumes = [
"/var/docker/bitwarden/:/data/"
];
};
};
Not much to say here, the syntax should be self-explanatory. After running
nixos-rebuild switch
confirm that your container is running:
)