Skip to content
This repository has been archived by the owner on Nov 7, 2024. It is now read-only.

Commit

Permalink
Merge pull request #20 from NotLebedev/nu-87
Browse files Browse the repository at this point in the history
Update to nushell 0.87.1
  • Loading branch information
lucperkins authored Dec 6, 2023
2 parents 9f80441 + 7ded9b6 commit cbc3cc7
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 37 deletions.
23 changes: 13 additions & 10 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
description = "Nuenv: a Nushell environment for Nix";

inputs = {
nixpkgs.url = "https://flakehub.com/f/NixOS/nixpkgs/0.2305.*.tar.gz"; # Provides Nushell v0.81.0
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; # Provides Nushell v0.87.1
rust-overlay = {
url = "github:oxalica/rust-overlay";
inputs.nixpkgs.follows = "nixpkgs";
Expand Down Expand Up @@ -128,7 +128,7 @@
def info [msg: string] { print $"(color "blue" "INFO"): ($msg)" }
def success [msg: string] { print $"(color "green" $msg)" }
info $"Hello, NixCon (date now | date format "%Y")!"
info $"Hello, NixCon (date now | format date "%Y")!"
info "So lovely to see everyone today"
info "Conference status:"
success "SUCCESS"
Expand Down
2 changes: 1 addition & 1 deletion nuenv/bootstrap.nu
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ for file in $attrs.__nu_env {

# Set the PATH so that Nushell itself is discoverable. The PATH will be
# overwritten later.
let-env PATH = ($attrs.__nu_nushell | parse "{root}/nu" | get root.0)
$env.PATH = ($attrs.__nu_nushell | parse "{root}/nu" | get root.0)

# Run the Nushell builder
nu --commands (open $attrs.__nu_builder)
14 changes: 7 additions & 7 deletions nuenv/builder.nu
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## Utility commands

source env.nu
export use env.nu *

## Parse the build environment

Expand Down Expand Up @@ -85,7 +85,7 @@ let packagesPath = (
| each { |pkg| $"($pkg)/bin" } # Append /bin to each package path
| str join (char esep) # Collect into a single colon-separated string
)
let-env PATH = $packagesPath
$env.PATH = $packagesPath

# Set user-supplied environment variables (à la FOO="bar"). Nix supplies this
# list by removing reserved attributes (name, system, build, src, system, etc.).
Expand All @@ -96,13 +96,13 @@ if $numAttrs != 0 {

for attr in $drv.extraAttrs {
if $nix.debug { item $"(yellow $attr.key) = \"($attr.value)\"" }
let-env $attr.key = $attr.value
load-env {$attr.key: $attr.value}
}
}

# Copy sources into sandbox
if $nix.debug { info "Copying sources" }
for src in $drv.src { cp -r $src $nix.sandbox }
for src in $drv.src { cp -r -f $src $nix.sandbox }

# Set environment variables for all outputs
if $nix.debug {
Expand All @@ -113,7 +113,7 @@ for output in ($drv.outputs) {
let name = ($output | get key)
let value = ($output | get value)
if $nix.debug { item $"(yellow $name) = \"($value)\"" }
let-env $name = $value
load-env {$name: $value}
}

## The realisation process
Expand All @@ -134,14 +134,14 @@ def runPhase [
# commands are registered. Right now there's a single env file but in
# principle there could be per-phase scripts.
do --capture-errors {
nu --log-level warn --env-config $nushell.userEnvFile --commands $phase
nu --log-level warn --env-config $nushell.userEnvFile --commands $phase | print

let exitCode = $env.LAST_EXIT_CODE

if ($exitCode | into int) != 0 {
exit $exitCode
}
} | default {} # To prevent `empty list` being displayed (until Nushell fixes this)
}
} else if $nix.debug { info $"Skipping empty (blue $name) phase" }
}

Expand Down
28 changes: 14 additions & 14 deletions nuenv/env.nu
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
# Logging

def color [color: string, msg: string] { $"(ansi $color)($msg)(ansi reset)" }
export def color [color: string, msg: string] { $"(ansi $color)($msg)(ansi reset)" }

def blue [msg: string] { color "blue" $msg }
def green [msg: string] { color "green" $msg }
def red [msg: string] { color "red" $msg }
def purple [msg: string] { color "purple" $msg }
def yellow [msg: string] { color "yellow" $msg }
export def blue [msg: string] { color "blue" $msg }
export def green [msg: string] { color "green" $msg }
export def red [msg: string] { color "red" $msg }
export def purple [msg: string] { color "purple" $msg }
export def yellow [msg: string] { color "yellow" $msg }

def banner [text: string] { print $"(red ">>>") (green $text)" }
def info [msg: string] { print $"(blue ">") ($msg)" }
def error [msg: string] { print $"(red "ERROR") ($msg)" }
def item [msg: string] { print $"(purple "+") ($msg)"}
export def banner [text: string] { print $"(red ">>>") (green $text)" }
export def info [msg: string] { print $"(blue ">") ($msg)" }
export def error [msg: string] { print $"(red "ERROR") ($msg)" }
export def item [msg: string] { print $"(purple "+") ($msg)"}

# Misc helpers

## Add an "s" to the end of a word if n is greater than 1
def plural [n: int] { if $n > 1 { "s" } else { "" } }
export def plural [n: int] { if $n > 1 { "s" } else { "" } }

## Convert a Nix Boolean into a Nushell Boolean ("1" = true, "0" = false)
def envToBool [var: string] {
export def envToBool [var: string] {
($var | into int) == 1
}

## Get package root
def getPkgRoot [path: path] { $path | parse "{root}/bin/{__bin}" | get root.0 }
export def getPkgRoot [path: path] { $path | parse "{root}/bin/{__bin}" | get root.0 }

## Get package name fro full store path
def getPkgName [storeRoot: path, path: path] {
export def getPkgName [storeRoot: path, path: path] {
$path | parse $"($storeRoot)/{__hash}-{pkg}" | select pkg | get pkg.0
}
8 changes: 5 additions & 3 deletions nuenv/user-env.nu
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@ def relativePath [
# Display the <msg> in a pretty way.
def log [
msg: string # The message to log.
] { $"(ansi green)+(ansi reset) ($msg)" }
] {
print $"(ansi green)+(ansi reset) ($msg)"
}

# Output the error <msg> in a flashy way.
def err [
msg: string # The error string to log
] {
$"(ansi red)ERROR(ansi reset): ($msg)"
print $"(ansi red)ERROR(ansi reset): ($msg)"
}

# Check that <file> exists and throw an error if it doesn't.
Expand Down Expand Up @@ -67,7 +69,7 @@ def substituteInPlace [
--replace (-r): string, # The string to replace in <file>
--with (-w): string # The replacement for <replace>
] {
$files | each { |file| substitute $file $file --replace $replace --with $with }
for $file in $files { substitute $file $file --replace $replace --with $with }
}

# Display Nuenv-specific commands.
Expand Down

0 comments on commit cbc3cc7

Please sign in to comment.