Flake Derivation Debug Process

I am trying to package schroot for nixos and thought I’ll just add an overlay directory to my config that contains flakes of packages I want to package myself and provide an overlay to be used in the config. The main flake looks like:

{
  description = "Nixos config flake";

  inputs = {
    nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
    home-manager = {
      url = "github:nix-community/home-manager/master";
      inputs.nixpkgs.follows = "nixpkgs";
    };
    debootstrapPin.url = "github:nixos/nixpkgs/9d757ec498666cc1dcc6f2be26db4fd3e1e9ab37";
    # -- Local Overlays --
   schroot.url = "path:/home/beat/.nix/modules/overlays/schroot/flake.nix";
  };

  outputs =
    {
      self,
      nixpkgs,
      home-manager,
      ...
    }@inputs:
    let
      system = "x86_64-linux";
      pkgs = import nixpkgs {
        inherit system;
        overlays = [ schroot.overlay ];
      };
    in
    {
      nixosConfigurations = {
        trident = nixpkgs.lib.nixosSystem {
          specialArgs = {
            inherit inputs;
          };
          modules = [
            ./hosts/trident/configuration.nix
            inputs.home-manager.nixosModules.default
          ];
        };
      };

      homeConfigurations = {
        beat = home-manager.lib.homeManagerConfiguration {
          inherit pkgs;
          extraSpecialArgs = {
            inherit inputs;
          };
          modules = [ ./home-manager/home.nix ];
        };
      };

        devShell = pkgs.mkShell {
          buildInputs =
            with pkgs;
            dependencies
            ++ [
              nixd
              nixfmt
            ];
        };
    };
}

and the flake that provides the schroot overlay:

{
  description = "Schroot package flake";

  inputs = {
    nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";
    flake-utils.url = "github:numtide/flake-utils";
  };

  outputs =
    {
      self,
      nixpkgs,
      flake-utils,
    }:
    flake-utils.lib.eachDefaultSystem (
      system:
      let
        pkgs = import nixpkgs { inherit system; };
        version = "1.6.13-3";
        stdenv = pkgs.stdenv;

        dependencies = with pkgs; [
          boost
          groff
          perl538Packages.Po4a
          groff
          libuuid
          gettext
          doxygen
        ];
      in
      {
        # overlay = final: prev: { schroot = prev.pkgs.callPackage ./. { }; };

        packages.default = import ./default.nix {
          inherit
            pkgs
            version
            stdenv
            dependencies
            ;
        };

        devShell = pkgs.mkShell {
          buildInputs =
            with pkgs;
            dependencies
            ++ [
              cmake
              ninja
              nixd
            ];
        };
      }
    );
}

with the derivation defined in default.nix

# TODO:
# - [ ] find out where the schroot package is installing in the build step
# - [ ] investigate all the etc file stuff going on

# NOTE: /etc/ ??

{
  pkgs ? import <nixpkgs> { },
  stdenv,
  version,
  dependencies,
}:
stdenv.mkDerivation {
  name = "schroot";

  src = builtins.fetchGit {
    url = "https://salsa.debian.org/debian/schroot.git";
    ref = "debian/master";
    rev = "59d82cf28a34cc7e91ef86b92333c54266d81789";
  };

  nativeBuildInputs = with pkgs; [
    cmake
    ninja
  ];

  buildInputs = dependencies;

  cmakeFlags = [ "-G Ninja" ];
}

Since we’re at it I would also know if that setup in general is sensible or if there’s a better way for achieving the same thing.

The main issue though is about the schroot flake. It is compiling just fine but I have issues with installing the package to proper locations. Also the installation script (cmake) tries to modify files in the nix store which of course is readonly.

How can I debug this setup in a good manner? I ended up adding echo and ls in the phases but this is very tedious to get a hang of it. I found information about using nix-shell and running the phases manually but how can it be done with flakes (i.e. nix build)?

I would also appreciate help in packaging this since this is my first attempt on packaging in NixOS.

nix develop .#packages.x86_64-linux.default will load up a devshell for your package just like nix-shell.

2 Likes

Btw, you should be using callPackage not import. And don’t pass pkgs or depencies like that. See Packaging existing software with Nix — nix.dev documentation

1 Like

Good point, was not aware of callPackage passing the packages. Thx for the heads up.