From 745896c85a0de275ebb6e3358f4a1cecc38a5e1c Mon Sep 17 00:00:00 2001 From: Chris Dawkins Date: Wed, 23 Aug 2023 13:01:50 -0600 Subject: [PATCH] init nix scripts (#584) Commands for working with nix package manager. --- modules/nix/README.md | 26 ++++++++++++++++++++++++++ modules/nix/nix.nu | 18 ++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 modules/nix/README.md create mode 100644 modules/nix/nix.nu diff --git a/modules/nix/README.md b/modules/nix/README.md new file mode 100644 index 0000000..1925759 --- /dev/null +++ b/modules/nix/README.md @@ -0,0 +1,26 @@ +# Nix + +Commands for working with [nix](https://nixos.org/). + +### ns +Shorthand search (`nix search nixpkgs ...`) with much nicer output. +```shell +❯ > nix search nixpkgs diesel +* legacyPackages.x86_64-linux.diesel-cli (2.1.0) + Database tool for working with Rust projects that use Diesel + +* legacyPackages.x86_64-linux.diesel-cli-ext (0.3.13) + Provides different tools for projects using the diesel_cli +``` +```shell +❯ > ns diesel +╭───┬────────────────┬──────────────────────────────────────────────────────────────┬─────────╮ +│ # │ package │ description │ version │ +├───┼────────────────┼──────────────────────────────────────────────────────────────┼─────────┤ +│ 0 │ diesel-cli │ Database tool for working with Rust projects that use Diesel │ 2.1.0 │ +│ 1 │ diesel-cli-ext │ Provides different tools for projects using the diesel_cli │ 0.3.13 │ +├───┼────────────────┼──────────────────────────────────────────────────────────────┼─────────┤ +│ # │ package │ description │ version │ +╰───┴────────────────┴──────────────────────────────────────────────────────────────┴─────────╯ +``` + diff --git a/modules/nix/nix.nu b/modules/nix/nix.nu new file mode 100644 index 0000000..07dcc8a --- /dev/null +++ b/modules/nix/nix.nu @@ -0,0 +1,18 @@ +# Search nixpkgs and provide table output +export def ns [ + term: string # Search target. +] { + + let info = ( + sysctl -n kernel.arch kernel.ostype + | lines + | {arch: ($in.0|str downcase), ostype: ($in.1|str downcase)} + ) + + nix search --json nixpkgs $term + | from json + | transpose package description + | flatten + | select package description version + | update package {|row| $row.package | str replace $"legacyPackages.($info.arch)-($info.ostype)." ""} +}