pmiddend / nixos-manager

Manage your NixOS packages and configuration via a simple, intuitive UI
GNU General Public License v3.0
175 stars 7 forks source link
declarative haskell nix nixos ui

[[https://www.gnu.org/licenses/gpl-3.0][https://img.shields.io/badge/License-GPLv3-blue.svg]] [[https://travis-ci.com/pmiddend/nixos-manager.svg?branch=master][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:

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 [[https://discourse.nixos.org/t/list-available-services-and-their-options/][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

[[https://www.youtube.com/watch?v=Fa4_9ueOdpY&feature=youtu.be][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 [[https://github.com/haskell-nix/hnix][hnix]]? Why don’t you parse your you Nix files with

I’d love to! But sadly and ironically, it’s currently [[https://github.com/NixOS/nixpkgs/issues/82233][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!

+begin_src bash

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

+end_src

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:

+begin_example

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

manual.json.enable = true;

+end_example

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:

+begin_example

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

+end_example

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

+begin_example

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

+end_example

*** 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:

+begin_src nix

{

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

}

+end_src

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:

+begin_src nix

{

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

}

+end_src

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

** Current status

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:

[[https://paypal.me/PhilippMiddendorf][PayPal.Me]]