Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/71/nixcfg
Command line utility to query and modify .nix files.
https://github.com/71/nixcfg
nix nixpkgs rust rust-bin
Last synced: 12 days ago
JSON representation
Command line utility to query and modify .nix files.
- Host: GitHub
- URL: https://github.com/71/nixcfg
- Owner: 71
- License: mit
- Created: 2018-09-07T23:01:09.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2018-09-09T11:25:29.000Z (over 6 years ago)
- Last Synced: 2024-12-23T18:10:33.685Z (16 days ago)
- Topics: nix, nixpkgs, rust, rust-bin
- Language: Rust
- Size: 9.77 KB
- Stars: 2
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
nixcfg
======
![Crates.io](https://img.shields.io/crates/v/nixcfg.svg)Command line utility to query and modify .nix files.
## Usage
```
nixcfg 0.1.0
Grégoire Geis
Command line utility to query and modify .nix files.USAGE:
nixcfg [FLAGS] [OPTIONS]FLAGS:
-h, --help Prints help information
-i, --in-place Modify in place instead of printing result to stdout.
-V, --version Prints version informationOPTIONS:
-f, --file Input .nix file to query or modify. [default: /etc/nixos/configuration.nix]SUBCOMMANDS:
get Get the value at the given path.
set Set the value at the given path.
```## Examples
Let's consider the following file:
```nix
# file.nix
{ pkgs, config, ... }:{
environment.systemPackages = with pkgs; [ ];networking.firewall.enable = true;
networking.firewall.allowedTCPPorts = [ 80 8080 8000 24800 ];nixpkgs.config = { allowBroken = false; allowUnfree = true; };
}
```### Querying values
- `nixpkg -f file.nix get environment.systemPackages` yields `with pkgs; [ ]`.
- `nixpkg -f file.nix get nixpkgs.config` yields `{ allowBroken = false; allowUnfree = true; }`.
- `nixpkg -f file.nix get nixpkgs.config.allowBroken` yields `false`.**Please note that `nixcfg` does not recognize values belonging to a same object.**
- `nixpkg -f file.nix get networking.firewall.enable` yields `true`.
- `nixpkg -f file.nix get networking.firewall.allowedTCPPorts` yields `[ 80 8080 8000 24800 ]`.
- `nixpkg -f file.nix get networking.firewall` fails to find a matching value.### Updating values
`nixpkg -f file.nix set networking.firewall.enable false`yields
```nix
# file.nix
{ pkgs, config, ... }:{
environment.systemPackages = with pkgs; [ ];networking.firewall.enable = false;
networking.firewall.allowedTCPPorts = [ 80 8080 8000 24800 ];nixpkgs.config = { allowBroken = false; allowUnfree = true; };
}
```## To do
- [ ] Add ability to insert the value, if the key did not previously exist.## Disclaimer
This project is very new, and has only been tested in limited test suites.
Use at your own risks.