andir/npins

Documentation providing guidance on how to use `npins` to manage a NixOS configuration?

bzm3r opened this issue · 2 comments

bzm3r commented

From what I have been able to piece together so far in order to figure out how to use npins to manage a NixOS configuration (flake-less):

  1. Inside configuration.nix, it is necessary to overlay the nixpkgs pinned by npins:
{ config, ... }:
{
  nixpkgs.overlays = 
    let 
      npinsOverlay = self: _super: {
        inherit (sources) nixpkgs;
      };
    in
      [ npinsOverlay ];
}
  1. Easily building with nixos-rebuild requires further steps still (adapted from a solution for niv), namely the creation of a shell.nix (possibly using the help of direnv to automatically switch into this shell when entering the the NixOS configuration directory).

The shell.nix probably looks like this:

let
  sources = import ./npins;
  pkgs = import sources.nixpkgs {};
in
pkgs.mkShell {
        buildInputs = with pkgs; [
                npins
                # what else should go here?
        ];
        shellHook = ''
                export nixpkgs=${sources.nixpkgs.outPath}
                export NIX_PATH=nixpkgs=${sources.nixpkgs.outPath}:nixos-config=/path/to/your/nixos-config/configuration.nix
        '';
}

I am not sure what other packages ought to be/are useful to include in buildInputs

  1. Building a custom live ISO will also need to happen inside this shell.

Am I missing anything else? I'd appreciate some feedback, and if there is interest, would be happy to help submit a PR which adds a small section documenting the above within README.

Your overlay looks weird. Why aren't you simply overriding the nixpkgs entirely?

Also in your shell.nix, you probably want to remove the function arguments and put them into a let binding instead.

Generally, I recommend using a build tool like colmena or morph to manage the NixOS configuration, as you then don't need to manually call the rebuild commands in a shell anymore. Many of these tools also support deploying to the local machine.

bzm3r commented

Your overlay looks weird. Why aren't you simply overriding the nixpkgs entirely?

Because it was (and is) much easier to figure out how to use an overlay, and an override operation is simply an overlay where super is not used. See:

Overlays are similar to other methods for customizing Nixpkgs, in particular the packageOverrides attribute described in the section called “Modify packages via packageOverrides”. (from: nixpkgs-man)

Also in your shell.nix, you probably want to remove the function arguments and put them into a let binding instead.

Yeah, fair enough. I made this change. (Although I learned that there are some cases where it is useful to have the function argument structure, for the sake of documentation, there's no need to go into that.)

Generally, I recommend using a build tool like colmena or morph to manage the NixOS configuration, as you then don't need to manually call the rebuild commands in a shell anymore. Many of these tools also support deploying to the local machine.

As a newcomer to the Nix ecosystem, I don't find using most third party tooling meant to help make things "more convenient", rather than adding missing functionality (e.g. as npins does). This is because:

  • these tools add their own layer of abstraction that a beginner must work through;
  • these layers of abstraction are often not in alignment with the core ideas of Nix/NixOs;
  • and finally, they remove valid learning opportunities for beginners to engage with Nix/NixOS at a level that is beyond superficial.

Since the time I opened this issue, I have figured out how to make progress with the help of a guide/example/protocol meant for use with niv.

It is trivial to convert that example to one for npins, and I have been using it in practice for the last week. So, to address the issue at hand, I plan on setting up a version of that repo as something that can be linked to by npins' documentation.