Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
byteshiva opened this issue Feb 11, 2024 · 6 comments
Open

Comments

@byteshiva
Copy link

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
Copy link
Author

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
Copy link
Author

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
Copy link
Author

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

@izzymelons
Copy link

There's a request (NixOS/nixpkgs#286104) with a WIP PR for packaging pkl on the nixpkgs repo: NixOS/nixpkgs#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.

@rafaelrc7
Copy link

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 (NixOS/nixpkgs#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.

@lilyball
Copy link
Contributor

According to NixOS/nixpkgs#286658 (comment) the PR NixOS/nixpkgs#272380 (gradle: add setup hook) got merged, which might unblock the pkl work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants