Giter VIP home page Giter VIP logo

npkg's Introduction

Npkg

Built with Nix License: MIT

Npkg is a small tool that allows you to configure all your NixOS packages in one place.

Npkg is written with rust and uses nix-editor and rnix-parser to parse and edit configuration files.

WARNING

This tool is still new/experimental, and being that it directly modifies critical files, such as /etc/nixos/configuration.nix, make sure you have backups in case it messes it up or deletes such files. I've already sacrificed some of my files to the void, don't let that happen to you!

NixOS Installation

git clone https://github.com/vlinkz/npkg
nix-env -f npkg -i npkg

Then modify ~/npkg/config.json to match your configuration.

Usage with Nix Flakes

nix run github:vlinkz/npkg -- --help

Declarative System Installation

Head of configuration.nix

{ config, pkgs, lib, ... }:

let
  npkg = (import (pkgs.fetchFromGitHub {
    owner = "vlinkz";
    repo = "npkg";
    rev = "0.1.2";
    sha256 = "0000000000000000000000000000000000000000000000000000";
  })).default;
in 
{
  imports =
# rest of configuration

Packages:

environment.systemPackages =
with pkgs; [
  npkg
  # rest of your packages
];

Arguments

USAGE:
    npkg [OPTIONS] [PACKAGES]...

ARGS:
    <PACKAGES>...    Packages

OPTIONS:
    -d, --dry-run            Do not build any packages, only edit configuration file
    -E, --env                Use nix environment 'nix-env'
    -h, --help               Print help information
    -H, --home               Use home-manager 'home.nix'
    -i, --install            Install a package
    -l, --list               List installed packages
    -o, --output <OUTPUT>    Output modified configuration file to a specified location
    -r, --remove             Remove a package
    -s, --search             Search for a package
    -S, --system             Use system 'configuration.nix'
    -u, --update             Update packages
    -V, --version            Print version information

Use cases

Installing packages

To install a package, you can run:

npkg -i <PACKAGE>

By default, this will use nix-env and install the package in you current environment. You can choose to use a specific available installer by using the -S, -H, or -E flags.

  • npkg -iS hello
    

    will install the hello package as a system package by modifying your /etc/nixos/configuration.nix file and then calling nixos-rebuild switch.

  • npkg -iH hello
    

    will install the hello package using home-manager if it is installed. It will modify ~/.config/nixpkgs/home.nix and then call home-manager switch.

  • npkg -iE hello
    

    will install the hello package to the current nix environment by calling nix-env -iA nixos.hello.

Removing packages

Very similar to installing packages:

npkg -r <PACKAGE>

The same -S, -H, and -E flags apply.

Updating packages

To update all packages:

npkg -u

To specify only one type, the same -S, -H, and -E flags apply.

List installed packages

npkg -l

This will list all packages installed in /etc/nixos/configuration.nix, ~/.config/nixpkgs/home.nix, and with nix-env.

You can specify only one of these by using the -S, -H, and -E flags.

Search for a package

npkg -s <QUERY>

This will print a list of packages that match the query specified. For example:

$ npkg -s hello greeting

* hello (2.12) (nix env)
  A program that produces a familiar, friendly greeting

This means that package hello version 2.12 is currently installed with nix-env.

Configuration

A configuration file is stored in ~/.config/npkg/config.json, by default, it contains:

{
  "systemconfig": "/etc/nixos/configuration.nix",
  "homeconfig": "/home/$HOME/.config/nixpkgs/home.nix",
  "flake": null
}

These values can be edited to point to other locations. This is useful in nix flake based systems or any system where config files are not in expected locations.

But why?

I wanted to code something as a proof of concept for using nix-editor as a backed for other tools. But so far I've been using it almost daily!

Future plans

  • Check for installed packages in other locations.

    For example, if installing hello with home-manager, and it's already installed with nix-env, give an option to switch it over.

  • When removing packages, automatically detect where installed instead of defaulting to nix-env

  • Whatever else pops into my head

npkg's People

Contributors

vlinkz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

npkg's Issues

declarative installation of npkg

Heya! Right now npkg is not in nixpkgs and you only explain how to install this package imperatively with nix-env -f npkg -i npkg. But I would like to be able to add it to my configuration.nix. I tried the following which didn't work and I have no clue how to move on... ๐Ÿ˜…

let
    npkg_package = (pkgs.fetchFromGitHub { owner = "vlinkz"; repo = "npkg"; rev = "0.1.1"; sha256 = "sha256-pEsAh7MPNXtQYe2aPaPppdHAcHrctJRGAkP1TOwzaxs="; });
in {
  home-manager.users.melkor333.home.packages = [npkg_package];
}

This doesn't fail, but also doesn't add the package...

Do you know what my mistake is? Since your default.nix only contains a weird looking import which I don't understand, I'm not sure where to start debugging. :/

nix profile

Add support for nix profile. nix-env causes too many headaches

I get the error "Url using bad/illegal format or missing URL"

I don't know where I have a bad URL, the Stack trace from rust isn't helping that much either:

[samuelh@afonil:~/git]$ RUST_BACKTRACE=full npkg -i openconnect
Installing package to nix environment
Out of date, updating cache
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Error { description: "URL using bad/illegal format or missing URL", code: 3, extra: None }', src/npkgcmd/search.rs:193:28
stack backtrace:
   0:     0x55c22437a7bd - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h8a90a2dc0368e92a
   1:     0x55c2243b158c - core::fmt::write::h22e27476e719d048
   2:     0x55c224385631 - std::io::Write::write_fmt::h38c85fae8ab684f6
   3:     0x55c224390fc5 - std::panicking::default_hook::{{closure}}::h1efe1958ecadfc56
   4:     0x55c224390c79 - std::panicking::default_hook::h421ef9590936ba8a
   5:     0x55c2243915fd - std::panicking::rust_panic_with_hook::h6e5c670a80137632
   6:     0x55c22437aaf7 - std::panicking::begin_panic_handler::{{closure}}::ha598c0022793c63e
   7:     0x55c22437a8d4 - std::sys_common::backtrace::__rust_end_short_backtrace::h42cbca7399dc1d94
   8:     0x55c224391122 - rust_begin_unwind
   9:     0x55c224271603 - core::panicking::panic_fmt::hae240fade5210bfd
  10:     0x55c2242716e3 - core::result::unwrap_failed::hb45588f4ae17e144
  11:     0x55c2242a7ccd - npkg::npkgcmd::search::setupcache::h0389a6f3eed3c10e
  12:     0x55c2242a63f1 - npkg::npkgcmd::search::checkcache::hc5e126de41e544f0
  13:     0x55c2242a573c - npkg::npkgcmd::search::name_to_pname::h805d6ad2861ef5f8
  14:     0x55c224281282 - npkg::npkgcmd::parse::envpkgs::h71b484f82939b0a6
  15:     0x55c224291abb - npkg::npkgcmd::run::pklst::h6da1e4a9785de851
  16:     0x55c224291c82 - npkg::npkgcmd::run::pkinstall::h7a15dac7101e9418
  17:     0x55c224293850 - npkg::npkgcmd::run::main::h3a7f391f849f520b
  18:     0x55c224285953 - std::sys_common::backtrace::__rust_begin_short_backtrace::hd14216cf59bd4e17
  19:     0x55c224288c09 - std::rt::lang_start::{{closure}}::hf021ccd73c4cf716
  20:     0x55c224383931 - std::rt::lang_start_internal::hda73c7e8894fc483
  21:     0x55c224283522 - main
  22:     0x7fa2d5e64237 - __libc_start_call_main
  23:     0x7fa2d5e642f5 - __libc_start_main_impl
  24:     0x55c2242717e1 - _start
  25:                0x0 - <unknown>

Could it be that the problem is due to me having added a user nix-channel and then removed it again? That's the only thing I can remember where I have done something with an url. nix-env -u exits with exit code 0 but seems to just do nothing...

nix-env -iA nixos.packages still works.

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.