Skip to content

Explore nushell usage - #192

Open
jonringer wants to merge 3 commits into
masterfrom
jonringer/nu-shell
Open

jonringer wants to merge 3 commits into
masterfrom
jonringer/nu-shell

Conversation

@jonringer

Copy link
Copy Markdown
Collaborator

Package jq using it to see how it "feels". Pretty different from bash, but it's not like heavy bash usage is pretty, and least the complexity seems more manageable with nu.

Replace bash (setup.sh) with nushell (setup.nu) as the builder for
mkEkaPackage derivations. stdenv.mkDerivation remains unchanged.

Key changes:
- Add nushell prebuilt binary package (0.115.1, musl static)
- Create stdenv/nushell-builder/setup.nu as the main builder entry point
- Create nushell equivalents of fixup hooks (strip, patch-shebangs,
  multiple-outputs, compress-man-pages, move-docs, move-lib64,
  move-sbin, propagated-deps)
- Force __structuredAttrs = true for all mkEkaPackage derivations
- Expose cmake.nushellHook and meson.nushellHook as passthru attrs
- Phase override strings are nushell syntax, not bash
Translation of jq from stdenv.mkDerivation (bash) to mkEkaPackage
(nushell). Demonstrates the phase syntax differences:

- preConfigure: nushell `save` instead of bash `echo >>`
- preBuild: `rm -rf` works the same (external command)
- postFixup: `^remove-references-to` with $env.dev/$env.man/$env.doc
- configureFlags: passed through autotools configure
- All phase strings are nushell syntax

Also fixes several nushell builder bugs found during testing:
- patch-shebangs: use try/catch instead of `complete` on builtins
- strip: use hex magic byte check instead of `complete` on open
- compress-man-pages: use -f flag and try/catch for existing .gz
- fixupPhase: ensure all output directories exist
if not ($manDir | path exists) { return }

# Find and gzip uncompressed man pages
let files = (do { ^find $manDir -type f -not -name "*.gz" -not -name "*.bz2" -not -name "*.xz" } | complete | get stdout)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use glob i.o. find:

Suggested change
let files = (do { ^find $manDir -type f -not -name "*.gz" -not -name "*.bz2" -not -name "*.xz" } | complete | get stdout)
let files = glob $manDir --exclude [*.gz *.bz2 *.xz]

something along these lines

let destFile = $"($dest)($rel)"
let destDir = ($destFile | path dirname)
mkdir $destDir
^mv $file $destFile

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not builtin mv, they're just fine

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Honestly, just vibed this up, to see if it's possible. But you're right ;)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep, slop machines are not very familiar with nushell yet

# NIX_BUILD_CORES
let cores = ($env | get -o NIX_BUILD_CORES | default "1")
let coresInt = if ($cores | into int) <= 0 {
try { ^nproc | str trim | into int } catch { 1 }

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
try { ^nproc | str trim | into int } catch { 1 }
sys cpu | length

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

Successfully merging this pull request may close these issues.

2 participants