Member-only story

Simplifying Configuration with Pkl CLI on NixOS

Siva
2 min readFeb 11, 2024

Configuring applications and tools can sometimes be a complex task, especially in diverse environments. Pkl, a versatile CLI tool, aims to simplify configuration processes. In this blog post, we’ll guide you through the setup and utilization of Pkl on NixOS using a flake.

Getting Started

NixOS, known for its declarative configuration approach, provides an excellent foundation for managing development environments. We’ll harness the power of NixOS to seamlessly integrate Pkl into our setup.

Flake.nix Configuration

Our development environment will be defined in a flake.nix file. This snippet outlines the basic configuration:


# flake.nix

{
description = "Configuration CLI tool with Pkl on NixOS";

inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
};

outputs = { self, nixpkgs }: {
devShell.x86_64-linux =
let
pkgs = nixpkgs.legacyPackages.x86_64-linux;
jpklUrl = "https://repo1.maven.org/maven2/org/pkl-lang/pkl-cli-java/0.25.2/pkl-cli-java-0.25.2.jar";
jpklPath = "./jpkl";
in pkgs.mkShell {
buildInputs = [
pkgs.jdk # Add JDK as a dependency
];

shellHook = ''
# Download jpkl only if it doesn't exist
if [ ! -e ${jpklPath} ]; then
curl -L -o ${jpklPath} ${jpklUrl}
chmod +x ${jpklPath}
fi

export PATH="$PWD:$PATH" # Add the current…

--

--

No responses yet