init nix scripts (#584)

Commands for working with nix package manager.
This commit is contained in:
Chris Dawkins 2023-08-23 13:01:50 -06:00 committed by GitHub
parent e5cf9b15ae
commit 745896c85a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 44 additions and 0 deletions

26
modules/nix/README.md Normal file
View File

@ -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 │
╰───┴────────────────┴──────────────────────────────────────────────────────────────┴─────────╯
```

18
modules/nix/nix.nu Normal file
View File

@ -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)." ""}
}