Install a package with e.g. `hdn add pkgs.hello`

Related tags

Command-line hdn
Overview

hdn: utility for updating home.nix

Home Manager is great, but it's tedious to run home-manager edit, add your package to the file, and run home-manager switch every time you want to install a package.

I wanted a workflow like Poetry, where I could just add a package and install it in one command. So, I made hdn.

You can call it with e.g. hdn add pkgs.hello pkgs.cowsay:

image

This adds pkgs.hello and pkgs.cowsay to the home.packages attribute in home.nix, and calls home-manager switch.

If home-manager switch fails, it will automatically roll back home.nix to its original state.

Requirements

This program requires that:

  • you have home-manger on your PATH
  • home.nix lives in one of the default locations (namely, ~/.config/home-manager/, ~/.config/nixpkgs/, ~/.nixpkgs/)
  • home.nix contains the attribute home.packages, the list of packages in the user environment

These requirements should be satisfied with the default home-manager installation.

Disclaimer

This program uses Rust, and I don't actually know how to program in Rust.

(I chose Rust because I found a Rust library for easily reading and writing nix files.)

Someday I'll go back, actually learn Rust, and rewrite this, but for now, use at your own risk.

Installation

Releases are available on crates.io.

cargo install hdn

If you don't want to use cargo to build from source, you can download a pre-built binary from the Releases page (untested!).

Acknowledgements

This project was made possible by the work of others (that I stole legally incorporated).

I thank Victor Fuentes for his work on nix-editor; the code for nix parsing and writing comes from his project.

I thank Armin Ronacher for his work on similar; the code that displays the home.nix diff comes from his project.

Comments
  • What assumptions are made?

    What assumptions are made?

    The premise of this tool is problematic. At the very least, the assumptions that are made regarding where your code is and what it looks like must be documented in the readme.

    opened by mightyiam 3
  • Let the child process inherit the parent's std{out,err}

    Let the child process inherit the parent's std{out,err}

    I haven't tested this, but if you're piping home-manager's std{out,err} to pipes just to print them as is afterwards, then you don't need pipes at all. POSIX processes inherit their parent's std{in,out,err} so the spawned home-manager should just print to the same output than your program

    opened by ThibaultLemaire 1
  • Provide context for other home-manager switch errors

    Provide context for other home-manager switch errors

    After #14, we no longer print out an error message when run_home_manager_switch returns an error. This is good for the case where home-manager switch runs and fails (as home-manager prints an error), but for other cases, we have less information.

    Example: home-manager not in PATH image

    We should print out an error message for these cases.

    opened by seasonedfish 0
  • Don't error when home-manager switch errors

    Don't error when home-manager switch errors

    hdn currently outputs an error when hm returns an error. image

    This may be confusing for users, as they might think this is two separate errors. Consider only showing an error when home.nix could not be rolled back.

    opened by seasonedfish 0
  • Support --show-trace flag for HM

    Support --show-trace flag for HM

    Here is an example of when HM fails:

    [fisher@workshop hdn]$ ./target/debug/hdn add jafefabghsa 
    Using /Users/fisher/.config/home-manager/home.nix as home.nix
    Adding ["jafefabghsa"] to home.nix
    Running home-manager switch: PID 99134
    error: undefined variable 'jafefabghsa'
    
           at /nix/store/grz4jrp7ykdn7jqwnjkmwzdmpbz5xxl1-source/home.nix:68:5:
    
               67|     pkgs.vhs
               68|     jafefabghsa
                 |     ^
               69| ];
    (use '--show-trace' to show detailed location information)
    Running home-manager switch resulted in an error, reverting home.nix
    

    Since we are showing HM output directly, we output to the user (use '--show-trace' to show detailed location information); however, this is a HM flag that hdn doesn't support.

    Support this flag to make things nicer for the user.

    opened by seasonedfish 0
  • Vendor nix-editor or rely on rnix directly

    Vendor nix-editor or rely on rnix directly

    We rely on nix-editor's functions to parse and edit home.nix, but since those functions aren't documented and nix-editor isn't at a stable release, they could change.

    Furthermore, nix-editor depends on several crates to provide its CLI. To reduce distribution size, my current approach is to use those same crates, but ideally we shouldn't have to pull those crates in for just the parsing and editing functionality.

    opened by seasonedfish 0
  • hdn does not handle builtins.attrValues home.packages expressions

    hdn does not handle builtins.attrValues home.packages expressions

    Bug

    If I have the following valid Nix config:

      home.packages =   builtins.attrValues {
          inherit (pkgs)
             gnome-2048
             ;
          };
    

    hdn can't figure out how to read the package list.

    $ hdn remove gnome-2048
    error: could not update home.packages attribute in home.nix
    caused by: could not read values of home.packages attribute in home.nix
    caused by: Error with array
    

    Suggested Fixes

    Either or both of:

    1. Ensure these sorts of expressions can be read
    2. Handle a # hdn anchor override that I can put into my file to denote where hdn can pretend a [ list ] begins, ignoring surrounding syntax

    Context

    The impl might be a bit involved on this one, but I'm doing it for a reason (it's not academic). I do the following, basically:

      home.packages = [
            pkgs.python310Packages.autopep8
          ] ++ builtins.attrValues {
          inherit (pkgs)
              # many
              # Many
              # MANY
              # pkgs.packages ;-) 
              ;
          };
    

    That allows me to not have to put pkgs on everything, yet still also use the python310Packages.autopep8 which does not work if I just bake it in the list.

    error: syntax error, unexpected '.'
    
           at /home/bujiraso/.config/home-manager/home.nix:181:28:
    
              181|           python310Packages.autopep8
                 |                            ^
    (use '--show-trace' to show detailed location information)
    

    Perhaps a bug is required for home-manager, too, on that one, but I haven't gotten around to it.

    opened by Bujiraso 1
  • hdn does not work unless using `with pkgs` for home.packages

    hdn does not work unless using `with pkgs` for home.packages

    When I run a simple command, it fails

    bash $ hdn remove gnome-2048
    home.nix doesn't contain any of the specified packages, home-manager switch was not run
    

    Here's my home.packages:

    bash $ grep -m 1 home.pack home.nix 
      home.packages = [ pkgs.gnome-2048 ];
    

    If I modify to

    home.packages = with pkgs; [ gnome-2048 ];
    

    It works. I also notice the add command does not check if pkgs is necessary, in the other direction, leading to errors on install.

    opened by Bujiraso 2
  • Add support for installing flakes outside of nixpkgs

    Add support for installing flakes outside of nixpkgs

    A nix flake can be installed with e.g. nix profile install github:peterldowns/nix-search-cli.

    hdn should support installing a flake with a similar syntax: hdn add github:peterldowns/nix-search-cli.

    help wanted 
    opened by seasonedfish 3
Owner
Fisher Sun
Avid CS student
Fisher Sun
TMM is a Linux native game modding tool. it allows to install and depoly mods for Linux native and wine games.

Tux Mod Manager TMM is a Linux native mod manager made with the Tauri toolkit. It can install, load, remove and deploy mods for both Linux native and

Mathiew May 119 Dec 27, 2022
A simple gtk4/libadwaita software center to easily install and manage nix packages

Nix Software Center A graphical app store for Nix built with libadwaita, GTK4, and Relm4. Heavily inspired by GNOME Software. Features Install package

Victor Fuentes 169 Dec 30, 2022
My own image file format created for fun! Install the "hif_opener.exe" to open hif files. clone the repo and compile to make your own hif file

Why am i creating this? I wanted to create my own image format since I was 12 years old using Windows 7, tryna modify GTA San Andreas. That day, when

hiftie 3 Dec 17, 2023
A Rust program/library to write a Hello World message to the standard output.

hello-world Description hello-world is a Rust program and library that prints the line Hello, world! to the console. Why was this created? This progra

null 0 May 11, 2022
Easy access of struct fields in strings using different/custom pre/postfix: "Hello, {field}" in rust

Easy access to struct fields in strings ?? add strung to the dependencies in the Cargo.toml: [dependencies] strung = "0.1.3" ?? use/import everything

Dekirisu 2 Sep 19, 2022
A "Hello, Rust!" program for the Flipper Zero

"Hello, Rust!" for the Flipper Zero This is an example of how to build a Rust-based Flipper application that runs from the SD-card. Note: This depends

David Coles 15 Dec 17, 2022
Hello Embedded!

Hello Embedded! ?? This repository contains a sketch of an embedded API described in Wit, and a simple example Wasm application that builds with it th

Dan Gohman 15 Mar 4, 2024
Add path effects to open glyphs in a UFO file

ufostroker Add path effects to open contours in a UFO file Given a glyph with open contours: You can apply a noodle effect: ufostroker -i Open.ufo -o

Simon Cozens 5 Jun 28, 2021
Add CLI & form interface to your program

Add CLI & form interface to your program

null 292 Nov 4, 2022
Simple CLI to (add, delete, update, create) i18n translation file 🔤 🦀

, Inrs Simple CLI to (add, delete, update, create) i18n translation file Copyright (C) 2020-2022 TheAwiteb https://github.com/TheAwiteb/inrs This pr

TheAwiteb 4 Oct 4, 2022
Generate commands that add node_modules/.bin to PATH

npx-bin-helper Generate commands that add node_modules/.bin to PATH. Supports Linux, MacOS and Windows. Installation cargo install npx-bin-helper Usag

Yumeoto Zorin 2 Nov 11, 2022
This is a placeholder repository for Ludum Dare 52. We'll add more soon!

Ludum Dare 52 This is a placeholder repository for Ludum Dare 52. How to play TBD Developing Only Rust (edition 2021) is required to develop and build

Matan Lurey 4 Jan 9, 2023
A simple CLI utility to add rounded borders, padding, and shadows to images.

shadower a simple command-line utility to add rounded corners and shadows to images Installation From AUR paru -S shadower-git From source cargo build

Michał 5 Mar 16, 2023
A CLI tool you can pipe code and then ask for changes, add documentation, etc, using the OpenAI API.

AiBro This is your own little coding bro, immersed in the world of AI, crypto, and all other types of over hyped tech trends. You can pipe it code and

Josh Bainbridge 5 Sep 5, 2023
The official CLI for FlakeHub: search for flakes, and add new inputs to your Nix flake.

fh, the official FlakeHub CLI fh is a scrappy CLI for searching FlakeHub and adding new inputs to your Nix flakes. Usage Using fh from FlakeHub: nix s

Determinate Systems 35 Oct 11, 2023
Print pacman package files

Paccat Print pacman package files Usage paccat [options] <targets> -- <files> a target can be specified as <pkgname>, <repo>/<pkgname>, <url> or <file

Lulu 25 May 1, 2022
Tool to build OSX package installers

?? Pak MacOS package installer builder What does pak do? Pak builds MacOS package installers from a project file. Since apple removed PackageBuilder f

ash 2 Feb 21, 2022
Rust crate `needleman_wunsch` of the `fasebare` package: reading FASTA sequences, Needleman-Wunsch alignment

fasebare Rust crate needleman_wunsch of the fasebare package: reading FASTA sequences, Needleman-Wunsch alignment. Synopsis The crate needleman_wunsch

Laurent Bloch 2 Nov 19, 2021
Gecko's trusty package manager and command-line utility.

Geckos have super-powers, ya'know? Grip is Gecko's trusty package manager and command-line utility. USAGE: grip [FLAGS] [file] [SUBCOMMAND] FLAGS

Gecko 2 Jan 3, 2022