Code Monkey home page Code Monkey logo

nix-editor's Introduction

Nix Editor

crates.io Coverage Status Built with Nix License: MIT

A command line utility for modifying NixOS configuration values.

Installation

nix-env

git clone https://github.com/snowfallorg/nix-editor
nix-env -f nix-editor -i nix-editor

nix profile

nix profile install github:snowfallorg/nix-editor

Run with Nix Flakes

nix run github:snowfallorg/nix-editor -- --help
Usage: nix-editor [OPTIONS] <FILE> <ATTRIBUTE>

Arguments:
  <FILE>       Configuration file to read
  <ATTRIBUTE>  Nix configuration option arribute

Options:
  -v, --val <VAL>        Value to write
  -a, --arr <ARR>        Element to add
  -d, --deref            Dereference the value of the attribute
  -i, --inplace          Edit the file in-place
  -o, --output <OUTPUT>  Output file for modified config or read value
  -r, --raw              Prints console output without newlines or trimmed output
  -f, --format           Formats output using nixpkgs-fmt. Helps when writing new values
  -h, --help             Print help
  -V, --version          Print version

nix-editor's People

Contributors

vlinkz avatar ahoneybun avatar milahu avatar

Stargazers

Phileas Lebada avatar Olivier Richard avatar Rusty avatar RAVENz46 avatar Brian Cooper avatar dj8yf0μl avatar Alex Mills avatar Johnny Nomad avatar  avatar  avatar Oliver Evans avatar Mr.HyperBit avatar Matthew McLeod avatar dnkmmr avatar jacobi petrucciani avatar  avatar Tsiry Sandratraina avatar Avi Dessauer avatar Mark Pashmfouroush avatar Andrejs Agejevs avatar Brian Ketelsen avatar  avatar Edgar B avatar Octelly avatar  avatar Aroun avatar Tom Hubrecht avatar  avatar Redstone avatar Chad Boyce avatar Serhii Chebanenko avatar Suraj avatar  avatar Tibor Pilz avatar Federico Damián Schonborn avatar  avatar João Figueira avatar Oleg Pykhalov avatar Marc Jakobi avatar Torsten Schmits avatar Jonan CM avatar  avatar Benjamin Levy avatar Perma avatar khaled agrama avatar Eric Bailey avatar Rosario Pulella avatar Kylie McClain avatar Thomas Wehmöller avatar Sandro avatar  avatar vi|vi|vi avatar Shayon avatar  avatar Justin Restivo avatar Samuel Boyden avatar  avatar Bryan A. S. avatar Rick van Schijndel avatar luxus avatar Nikita avatar  avatar Jeff Carpenter avatar chris montgomery avatar Parthiv Seetharaman avatar

Watchers

Alexander Polyakov avatar Olivier Richard avatar pinage404 avatar Suraj avatar  avatar  avatar

nix-editor's Issues

edit file in-place

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"'

read input from stdin or fd special file

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

multiple updates

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
}

interface could be better - similar to jq

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

#5

see also jaq - A jq clone focussed on correctness, speed, and simplicity

Create new attributes inside lambda

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.

Handle imports recursively

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.