pkl
pkl copied to clipboard
Request to Add pkl (Configuration as Code Language) Package to NixOS
Issue Description
Problem
The pkl
package, a Configuration as Code language developed by Apple, is not currently available in the NixOS packages.
Desired Outcome
Include the pkl
package in NixOS packages.
Package Information
- Package Name: pkl
- GitHub Repository: apple/pkl
Additional Context
pkl is a Configuration as Code language with rich validation and tooling. Adding it to NixOS packages would benefit users involved in configuration management and development workflows.
Environment Information
- NixOS Version: 23.11 or current
- Nixpkgs Channel: unstable
Reference Links
Thank you for considering this request.
To make it work in NixOS, I followed the steps below (using jpkl).
-
Downloaded jpkl:
curl -L -o jpkl https://repo1.maven.org/maven2/org/pkl-lang/pkl-cli-java/0.25.2/pkl-cli-java-0.25.2.jar
-
Made the script executable:
chmod +x jpkl
-
Checked file type (confirmed as POSIX shell script executable):
file jpkl jpkl: POSIX shell script executable (binary data)
-
Checked dynamic dependencies:
ldd ./jpkl not a dynamic executable
-
Set up a Nix shell with the appropriate JDK:
nix-shell -I nixpkgs=https://github.com/NixOS/nixpkgs/archive/nixos-unstable.tar.gz -p jdk
-
Verified installation:
./jpkl --version Pkl 0.25.2 (Linux 6.1.69, Java 19.0.2)
output
~/jpkl eval bird.pkl
name = "Swallow"
job {
title = "Sr. Nest Maker"
company = "Nests R Us"
yearsOfExperience = 2
}
~/jpkl eval -f json bird.pkl
{
"name": "Swallow",
"job": {
"title": "Sr. Nest Maker",
"company": "Nests R Us",
"yearsOfExperience": 2
}
}
~/jpkl eval -f plist bird.pkl
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>name</key>
<string>Swallow</string>
<key>job</key>
<dict>
<key>title</key>
<string>Sr. Nest Maker</string>
<key>company</key>
<string>Nests R Us</string>
<key>yearsOfExperience</key>
<integer>2</integer>
</dict>
</dict>
</plist>
I've written a brief blog post on setting up Pkl using Nix flakes on NixOS.
Details available at https://byteshiva.medium.com/simplifying-configuration-with-pkl-cli-on-nixos-08790fbe4e5c
There's a request (https://github.com/NixOS/nixpkgs/issues/286104) with a WIP PR for packaging pkl on the nixpkgs repo: https://github.com/NixOS/nixpkgs/pull/286658
There's also another flake (https://github.com/capslock/pkl-flake) which I've been using for the last few days. I think it just repackages the official native binary releases, so it doesn't require pulling in the entire JDK.
I've been trying to package it for NixOS. The ideal way would be to build from source and not download the binary, the latter is only done for proprietary programs, in which case it is the only option. However, I've been having some issues, as described in the PR (https://github.com/NixOS/nixpkgs/pull/286658), and any help would be appreciated.
However, it is not hard to build pkl yourself in nix, if you desire. To build the Java version, you just need gradle_7
and jdk17
and run gradle build
. To build the native package it is a bit harder... You need graalvm for JDK 11, that got removed and is only available in 23.05 (github:nixos/nixpkgs/23.05#graalvm11-ce
). You then need to edit pkl-cli.gradle.kts
, removing the dependsOn(":installGraalVm")
from Exec.configureExecutable
and in the same function, change executable
into just native-image
, this way gradle will use the graalvm downloaded from nix instead of trying to download it itself, what will not work. Then gradle nativeBuild
will work.
According to https://github.com/NixOS/nixpkgs/pull/286658#issuecomment-2229226963 the PR NixOS/nixpkgs#272380 (gradle: add setup hook) got merged, which might unblock the pkl work.