snowfallorg / nix-editor Goto Github PK
View Code? Open in Web Editor NEWA simple rust program to edit NixOS configuration files with just a command
License: MIT License
A simple rust program to edit NixOS configuration files with just a command
License: MIT License
when running using recommended flake one-liner, I get
$ nix run github:vlinkz/nix-editor
error: attribute 'defaultApp.x86_64-linux' should have type 'derivation'
Does it work for you?
nix run github:vlinkz/nix-editor#nix-editor
runs fine.
The latest version fixes many bugs and offers a better api.
Something along the lines of:
nix-editor [OPTIONS] <FILE> [<ATTRIBUTE> [--val <VAL>]]...
nix-editor file.nix name1 --val 0 name2 --val 2
or even perhaps take a json?
{
"name1": 0,
"name2": 2
}
Situation:
{
outputs = {...}: {
a = {};
};
}
Running nix-editor test.nix outputs.a -v 1
produces:
{
outputs = {...}: {
a = 1;
};
}
as expected. But nix-editor test.nix outputs.a.b -v 1
produces:
{
outputs = {...}: {
a = {};
};
outputs.a.b = 1;
}
where the attrset was not placed into the function call, but on the outside.
this should work
$ echo '{}' | nix-editor --val 1 /dev/stdin a
error: reading '/dev/stdin': No such file
$ echo '{}' | nix-editor --val 1 - a
error: reading '-': No such file
$ nix-editor --val 1 <(echo '{}') a
error: reading '/dev/fd/63': No such file
this works with standard CLI tools like cat
$ echo foo | cat /dev/stdin | head -c1
f
$ echo foo | cat - | head -c1
f
$ cat <(echo foo) | head -c1
f
https://github.com/clap-rs/clap is more widely used and supports more features. Using this along with refactoring the argument code can make the tool easier to use
it would be good if there was also a way to format using alejandra
add a shortcut for
nix-editor /etc/nixos/configuration.nix -o /etc/nixos/configuration.nix networking.hostName -v '"hello"'
for example
nix-editor -i /etc/nixos/configuration.nix networking.hostName -v '"hello"'
Currently reading or modifying a value only applies to a single configuration file. Being able to optionally modify attributes based on the import
option would be useful for applications like nixos-conf-editor
I have no idea how to use this and documentation will be helpful.
// main.rs
println!("{}", output);
should be print
or so
Currently, none of the public functions have proper documentation comments, so the generated docs are empty.
See: https://docs.rs/nix-editor/latest/nix_editor/
Documentation is needed describing what each function does, as well as providing some examples.
Getting started: https://doc.rust-lang.org/rustdoc/how-to-write-documentation.html
the interface could be better - similar to jq
$ echo '{}' | jq # identity
{}
$ echo '{}' | jq -c '.a=1 | .b=2' # set multiple values
{"a":1,"b":2}
$ echo '{}' | jq -c '.a=1 | .b=2' | jq -c '.c=3 | .d=4' # chaining
{"a":1,"b":2,"c":3,"d":4}
set multiple values
see also jaq - A jq clone focussed on correctness, speed, and simplicity
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.