pkl icon indicating copy to clipboard operation
pkl copied to clipboard

Request to Add pkl (Configuration as Code Language) Package to NixOS

Open byteshiva opened this issue 1 year ago • 6 comments

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

  1. NixOS Website
  2. NixOS Package Search - pkl

Thank you for considering this request.

byteshiva avatar Feb 11 '24 08:02 byteshiva

To make it work in NixOS, I followed the steps below (using jpkl).

  1. 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
    
  2. Made the script executable:

    chmod +x jpkl
    
  3. Checked file type (confirmed as POSIX shell script executable):

    file jpkl
    jpkl: POSIX shell script executable (binary data)
    
  4. Checked dynamic dependencies:

    ldd ./jpkl
    not a dynamic executable
    
  5. 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
    
  6. Verified installation:

    ./jpkl --version
    Pkl 0.25.2 (Linux 6.1.69, Java 19.0.2)
    

byteshiva avatar Feb 11 '24 09:02 byteshiva

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>

byteshiva avatar Feb 11 '24 09:02 byteshiva

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

byteshiva avatar Feb 11 '24 10:02 byteshiva

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.

izzymelons avatar Feb 11 '24 19:02 izzymelons

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.

rafaelrc7 avatar Feb 12 '24 20:02 rafaelrc7

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.

lilyball avatar Jul 19 '24 18:07 lilyball