oliverdavies.uk/source/_daily_emails/2023-07-02.md

52 lines
1.6 KiB
Markdown
Raw Normal View History

2024-01-03 20:00:00 +00:00
---
title: >
2024-09-08 22:09:54 +00:00
Docker or Nix?
2024-01-03 20:00:00 +00:00
pubDate: 2023-07-02
permalink: >-
2024-09-08 22:09:54 +00:00
archive/2023/07/02/docker-or-nix
2024-01-03 20:00:00 +00:00
tags:
2024-09-08 22:09:54 +00:00
- docker
- nix
2024-01-03 20:00:00 +00:00
---
I've been a Nix user for about a year, starting with its package manager on my previously installed Linux distribution.
I started to use Home Manager for my user configuration and dotfiles and later switched to the NixOS operating system.
## Using Nix for software development
I've also been using Nix Flakes for per-project configuration.
A Flake file is a simple file written in the Nix language that defines the project's dependencies and installs them from the Nix package manager.
Here is an example Flake for a PHP CLI application:
```nix
{
  inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
  outputs = inputs@{ flake-parts, ... }:
    flake-parts.lib.mkFlake { inherit inputs; } {
      systems = [ "x86_64-linux" ];
      perSystem = { config, self', inputs', pkgs, system, ... }: {
        devShells = {
          default = pkgs.mkShell {
            buildInputs = with pkgs; [ php82 php82Packages.composer ];
          };
        };
      };
    };
}
```
It declares that PHP 8.2 and Composer are available, even if I have different versions installed globally.
## Will Nix replace Docker?
Nix and Flakes have replaced Docker for me on some projects.
If I have a simple setup and need a specific version of PHP or Node and some additional programs, I can get those from the Flake.
I don't know if it'll replace Docker for me completely and work on more complex projects, but it's working well for me where I'm using it.