Giter Site home page Giter Site logo

nixos-manager's Introduction

nixos-manager — manage your NixOS graphically

https://img.shields.io/badge/License-GPLv3-blue.svg https://travis-ci.com/pmiddend/nixos-manager.svg?branch=master

Rationale

The idea is to build something to configure NixOS graphically. To me, this means: managing the installed software packages, and managing the enabled services, as well as updating and garbage-collecting. For the moment, I’m focusing on a solution for a declarative, global configuration; so for the moment it’s not calling nix-env and it’s not supporting home-manager.

The goal is not to make all of NixOS accessible via a GUI, and not give an alternative to writing Nix expressions for your configuration. Instead, this is a project to explore how far you can get graphically after installing NixOS (which — in the future — might be possible via a GUI installer as well).

Approach

Since the NixOS configuration is very “free-form”, I have to make some assumptions about the structure of your configuration.nix file, as such:

  • You have two additional .nix files, referenced from the imports section in your configuration.nix: packages.nix and services.nix
  • packages.nix is a flat list of packages
  • services.nix is a list of service options, like services.xserver.enable = true.

In nixos-manager, you can mark packages for installation. They will be added to your local copy of packages.nix. You can then trigger a nixos-rebuild from inside nixos-manager, which copies your local installation to the global installation inside /etc/nixos/nixos-manager/packages.nix. Same for configuring services and services.nix.

To gather service definitions, nixos-manager downloads and parses https://nixos.org/nixos/options.json. This way, the service definitions might not accurately reflect your system configuration, but I just found no other way to gather the definitions, see this Discourse thread.

Screenshots

Welcome screen, featuring a frontend for nixos-rebuild

./screenshots/admin.png

Welcome screen for home-manager users

./screenshots/home-manager.png

Search and install (or try) packages

./screenshots/packages.png

Configure services

./screenshots/services.png

Screencast

Watch on YouTube

Please recommend to me another platform where I can upload this, preferably lossless as the source mkv that I have.

FAQ

Have you seen hnix? Why don’t you parse your you Nix files with

I’d love to! But sadly and ironically, it’s currently broken in nixpkgs. I’m waiting for someone to repair it, as I don’t have the knowledge to do that.

I’m using Haskell as the language of choice, simply because hnix is available and allows me to easily parse and serialize the relevant Nix configuration files. The GUI is made via gi-gtk-declarative, which serves me well and is pretty stable.

Can I configure NixOS using this tool and manually at the same time?

Yes, that’s possible. The files that nixos-manager uses shouldn’t be edited by hand, but you can configure services and packages the regular way as well, by editing configuration.nix. Thus, nixos-manager is just an enhancement.

The list of packages only lists packages installed by nixos-manager, not globally installed ones. How come?

The simple reason is: I haven’t gotten to that part yet, and my Nix knowledge is so limited I’d have to ask how do that first.

Building

nixos-manager isn’t in nixpkgs yet, so you’ll have to build it using…Nix!

nix-build -I nixpkgs=channel:nixos-unstable

The channel argument is necessary in case you’re not on nixos-unstable.

Setup and running

With home-manager

After building it (see above), you have to tell home-manager to read nixos-manager’s configuration files. To do that, open your ~/.config/nixpkgs/home.nix file and insert the following somewhere inside the main attribute set:

imports = [ ./hm-extra-services.nix ./hm-extra-packages.nix ];

manual.json.enable = true;

nixos-manager, when run in home-manager mode, will write these extra files. The second line enables JSON export of the available options in home-manager, which nixos-manager reads to generate the configuration UI.

To run nixos-manager in home-manager mode, simply run it with the --home-manager argument. For example, if you built it with Nix, run:

result/bin/nixos-manager --home-manager

If you’ve built it with cabal (for example, to try it out after changing the code), run:

cabal v2-run nixos-manager -- --home-manager

With NixOS

After building it (see above), you have to tell NixOS to read nixos-manager’s configuration files. To do that, open your /etc/nixos/configuration.nix file and look for a line containing imports = …. Usually it looks something like this:

{
  # …
  imports =
    [ # Include the results of the hardware scan.
      ./hardware-configuration.nix
    ];
  # …
}

So imports contains an array of Nix files. You can extend this array by just listing more files, separated by spaces. To use NixOS manager, extend the list as such:

{
  # …
  imports =
    [ # Include the results of the hardware scan.
      ./hardware-configuration.nix
      ./nixos-manager/services.nix
      ./nixos-manager/packages.nix
    ];
  # …
}

nixos-manager will create these two files when you apply changes.

Current status

  • The frontend for nixos-rebuild works. It supports --upgrade and --rollback.
  • nix-collect-garbage is also supported, supporting the -d flag.
  • Rebuilding copies packages.nix and services.nix to /etc/nixos/nixos-manager. Without these files being included in your configuration.nix, they’re worthless, though.
  • Configuring services works, with some minor quirks.
  • Trying packages works, and installing/uninstalling too. The packages.nix will be updated accordingly.

Contributing guide

Prerequisites

Code structure

Each module has haddock documentation. Finding information about the code just from that might be difficult though, so let me give you a short overview:

  • Each of the tabs you see (notebook pages, in GTK-Speak) has a submodule. There’s NixManager.Admin, NixManager.Services and NixManager.Packages, respectively.
  • Inside each such submodule you have modules Event, Update and View.
    • Event contains the even data type for the submodule (which is then embedded in NixManager.ManagerEvent)
    • Update contains the update handler (a function receiving the current state and an event and returns a new state, as well as an event and IO side-effects)
    • View contains the gi-gtk-declarative classes for the notebook page.
    • State contains the state corresponding to the subsystem
  • When starting a process, such as the rebuild process, we cannot easily run it in the background and emit an event when it’s finished (at least I don’t know how to do that comfortably with gi-gtk-declarative-app-simple). Instead, we are spawning the process (in the background, mind you), then wait for a small amount of time (which doesn’t block the GUI, fortunately) and then emit a “watch” event, which does the same thing, until the process signals completion. It sounds hacky, and it is, but it’s not that bad.

Alternatives

  • nix42b — is another user-friendly Nix package manager, also written in Haskell. It doesn’t seem to be actively maintained anymore.

Donations

PayPal.Me

nixos-manager's People

Contributors

mic92 avatar pmiddend avatar xaverdh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

nixos-manager's Issues

Generate options.json locally

I think the options.json list should be generated locally instead of downloaded from channels.nixos.org. That will make it consistent with other operations which take nixpkgs to be the local version from NIX_PATH.

I wrote a quick dirty demonstration of this approach here.

rebuild process

When starting a process, such as the rebuild process, we cannot easily run it in the background and emit an event when it’s finished (at least I don’t know how to do that comfortably with gi-gtk-declarative-app-simple). Instead, we are spawning the process (in the background, mind you), then wait for a small amount of time (which doesn’t block the GUI, fortunately) and then emit a “watch” event, which does the same thing, until the process signals completion. It sounds hacky, and it is, but it’s not that bad.

Can you point me to the place in the code, where that happens? I couldn't find it :-/
It sounds to me like this could be handled by forking a completely separate daemon process before any gtk related stuff happens, to which the building gets delegated.

Requires gksudo but not included in

After pressing "Collect garbage":

Executing: gksudo --description "NixOS Manager" --print-pass
nixos-manager: gksudo: createProcess: runInteractiveProcess: exec: does not exist (No such file or directory)
Executing: gksudo --description "NixOS Manager" --print-pass
nixos-manager: gksudo: createProcess: runInteractiveProcess: exec: does not exist (No such file or directory)
Executing: gksudo --description "NixOS Manager" --print-pass
nixos-manager: gksudo: createProcess: runInteractiveProcess: exec: does not exist (No such file or directory)

Suggestion: use makeWrapper to include gksu in the PATH of nixos-manager.

Can't run nixos-manager when home-manager is used within configuration.nix

I want to try out nixos-manager, but I can't get it to work. I am on NixOS and have home-manager configured inside my configuration.nix (my configuration is split in multiple files which are imported, if that matters). From what I understand this shouldn't be a problem at all and nixos-manager should be able to run without using the home-manager. But I always get the following message:

# /home/sam/nixos-manager/result/bin/nixos-manager 
Executing: nix search  --json
nixos-manager: /root/.nix-profile/share/doc/home-manager/options.json: openBinaryFile: does not exist (No such file or directory)

This happens with my personal and the root user.

Since I am using home-manager in the NixOS config, I added manual.json.enable = true; to my user config and now I get the following error when trying to run nixos-manager as user (which probably has to do with home-manager not being in the path):

$ /nix/store/32xycr35ajmhqznj3cnmch6r2kdj0567-nixos-manager-1.0/bin/nixos-manager 
Executing: nix search  --json
Executing: home-manager generations
nixos-manager: home-manager: createProcess: runInteractiveProcess: exec: does not exist (No such file or directory)

I also tried removing home-manager-path from my user env (which probably was a mistake) and since the ~/.nix-profile folder disappeared it went back to the first error.

Does the nixos-manager currently only run with home-manager or is this some kind of bug/current incompatibility with my setup?
I also wonder why it isn't in the nixpkgs yet. Is there some reason for that or have you just not yet gotten to creating a PR?

[Feature request] README snippet for usage outside NixOS

As many people get started using Nix on other distros, because they're not ready to take the plunge and install NixOS or are intimidated by the install process, it'd be cool if this tool could be used with nix-env or home-manager.

Since packages.nix is supposed to be a flat list of packages I think it could easily be used as the paths for a buildEnv, something like this overlay maybe:

self: super: {
  nixos-manager-packages = pkgs.buildEnv {
      name = "nixos-manage-packagesr";
      paths = import ./packages.nix;  # Expects a list of packages
    };
}

For home-manager I'm sure a similar snippet could be added to the README. Including support for configuring home-manager's services and other configuration would probably require changes to the implementation?

Search for packages with a specific file (via nix-index/nix-locate)

Perhaps the package search (or a separate search window) could defer to something like nix-locate (via nix-index) to allow users to search for packages containing a specific file.

I imagine this could be like a frontend for nix-locate, allowing users to utilize the nixos-manager GUI and skip any terminal commands, as nix-locate results can often be quite overwhelming, especially if --top-level or similar flags are neglected.


e.g.
command:
nix-locate glib-2.0.so -w1 --top-level

output:

spice-gtk.out
signal-desktop.out
glib.out

nix-index must be run before nix-locate, and I'm not sure how or if that would need to be implemented--vs simply telling the user they must run it first to utilize such features--but I figure such a feature would be quite helpful and not too difficult to implement... should it be deferred to something that already handles such indexing/searching, or at least the indexing.

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.