Veröffentlichungsdatum

nix Flakes für die Entwicklung

Autoren
  • avatar
    Name
    Thomas Waldecker

Nix Flakes sind noch besser geeignet als nix-shell, aber etwas komplizierter.

Sie sind jetzt meine Lösung für Entwicklungsumgebungen.

nix-flake-stylistic

Es funktioniert sehr gut unter Windows in WSL und auch in MacOS.

Hier ist ein Beispiel-Flake für ein nodejs und yarn Projekt:

{
  description = "nix nodejs development flake";

  inputs.nixpkgs.url = "github:NixOS/nixpkgs";

  outputs = { self, nixpkgs }:
    let
      supportedSystems = [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin" ];
      forEachSupportedSystem = f: nixpkgs.lib.genAttrs supportedSystems (system: f {
        pkgs = import nixpkgs { inherit system; };
      });
    in
    {
      devShells = forEachSupportedSystem ({ pkgs }: {
        default = pkgs.mkShell {
          packages = with pkgs; [ 
            nodejs_22
            yarn-berry
          ];
        };
      });
    };
}

Man startet es mit

nix develop -c $SHELL

Damit bleibt man in seiner Shell (z.B. zsh) und hat von nun an die spezifizierten Tools verfügbar.

Es ist meiner Meinung nach aktuell die beste