Help using overlays with flake-parts

Hi all, I’ve spent about 8 hours on this and I can’t get my overlays to work. When I use nix repl I can see that the overlays are not applied - by querying outputs.nixosConfigurations.host1.pkgs.ffmpeg-full.configureFlags - I see "--disable-libfdk-aac", whereas it should be enabled. And the haskell unordered-containers tests still run for i686, which I have found to take at least 24 hours (I have never let it run long enough to complete, and aborted it in frustration after that long).

My overlays do work with my pre-flake-parts config.

Here’s the relevant section from my flake.nix:

...
  outputs = inputs @ {flake-parts, ...}:
    flake-parts.lib.mkFlake {inherit inputs;} {
      debug = true;
      systems = [
        # "aarch64-linux"
        # "i686-linux"
        "x86_64-linux"
        # "aarch64-darwin"
        # "x86_64-darwin"
      ];

      imports = [
        ./hosts
      ];

      perSystem = {system, ...}: {
        _module.args.pkgs = import inputs.nixpkgs {
          inherit system;
          overlays = [
            (import ./overlays {inherit inputs;})
          ];
        };
      };
    };

And in /overlays/default.nix:

{
  inputs,
  ...
}: (self: super: {
  # Local (to this repo) packages
  packages = import ./pkgs {pkgs = super;};

  # Overrides
  nixpkgs = import inputs.nixpkgs {
    inherit system;
    config.allowUnfree = true;
    overlays = [
      (final: prev: {
        # disable tests for haskell for i686 arch
        haskell =
          prev.pkgsi686Linux.haskell
          // {
            packageOverrides = hfinal: hprev:
              prev.haskell.packageOverrides hfinal hprev
              // {
                unordered-containers = final.haskell.lib.compose.dontCheck hprev.unordered-containers;
              };
          };

        ffmpeg-full = prev.ffmpeg.override {
          withFdkAac = true;
          withUnfree = true;
        };

        sops-nix = inputs.sops-nix.nixosModules.sops;
        asynq = inputs.asynq.packages.${system}.default; # TODO:
      })
    ];
  };
})

And in my hosts/default.nix, I generate the configurations like this:

{inputs, ...}: {
  flake = let
    inherit (inputs.nixpkgs) lib;
    mkNixossystem = host:
      lib.nixosSystem {
        specialArgs = {
          inherit inputs;
        };
        modules = [
          inputs.home-manager.nixosModules.home-manager
          inputs.sops-nix.nixosModules.sops
          ./${host}
          ../modules/nixos
        ];
      };
  in {
    nixosConfigurations = {
      "host1" = mkNixossystem "host1";
      "host2" = mkNixossystem "host2";
    };
  };
}

having problems with unordered-containers-tests too, it seems to freeze and utilize 100% of a single core, on x86_64

1 Like

If your config is causing haskell to be rebuilt rather than using the pre-built version then a variation of my overlay above should work to skip the tests.

Would be great if someone could diagnose the root cause as to why the unordered-containers tests are hanging.

Created an issue here Build failure: haskellPackages.unordered-containers checks are freezing · Issue #349053 · NixOS/nixpkgs · GitHub

1 Like

Also if you have obs-vkcapture installed then that’s why you had this issue. If you rebuild your system with latest master/nixos-unstable-small it should work :slight_smile:

I am not expert (still a newbie in NixOS and flake-parts (1 week usage only)), but I think the pkgs overlay defined in perSystem ( that thing in _module.args.pkgs) was not consumed by nixosConfigurations. I cannot see you have any settings in hosts/default.nix to use those overlays.

By the way, I think the overlays should also be defined in flake block in flake-parts (I mean the flake among “system” “flake” “perSystem” “imports” in flake-parts, don’t know how to call it.), since you are mainly doing an outputs.nixosConfiurations, but not outputs.packages. Maybe you can define it the overlay in modules =[ ]; like normal configuration.nix syntax, I did it that way (because I did that before I switch the nixos to flake), but maybe there are other ways to do it.

Below just noob opinions, correct me if I am wrong. I think you mixed up the flake writing for outputs.nixosConfiurations(use “flake” in flake-parts) and flake writing for outputs.packages(use “perSystem” in flake-parts).

And I see you have an overlay in an overlay, I don’t know how it works.

1 Like

Thank you very much for taking the time to read my post and review my config. After a lot of stumbling in the dark I ended up with something that works, although I would be grateful for any suggestions to improve it.

flake.nix

  outputs = inputs @ { self, flake-parts, ... }:
    flake-parts.lib.mkFlake {inherit inputs;} ({withSystem, ...}: {
      debug = true;
      systems = [
        "x86_64-linux"
      ];
      flake = let
        system = "x86_64-linux";
        inherit (inputs.nixpkgs) lib;
        pkgs = import inputs.nixpkgs {
          inherit system;
          config.allowUnfree = true;
          config.permittedInsecurePackages = ["electron-27.3.11"];
          overlays = [(import ./overlays {inherit inputs system;})];
        };
        mkNixossystem = { host, system ? "x86_64-linux", ... }:
          withSystem system ({system, ...}:
            lib.nixosSystem {
              inherit system;
              specialArgs = {
                inherit inputs pkgs;
              };
              modules = [
                inputs.home-manager.nixosModules.home-manager
                inputs.sops-nix.nixosModules.sops
                ./hosts/${host}
                ./modules/nixos
              ];
            });
      in {
        nixosConfigurations = {
          "host1" = mkNixossystem {host = "host1";};
          "host2" = mkNixossystem {host = "host2";};
        };
      };
    });
  #
}

overlays/default.nix

{
  inputs,
  system,
  ...
}: (final: prev: {
  # disable tests for haskell for i686 arch
  # haskell =
  #   prev.pkgsi686Linux.haskell
  #   // {
  #     packageOverrides = hfinal: hprev:
  #       prev.haskell.packageOverrides hfinal hprev
  #       // {
  #         unordered-containers = final.haskell.lib.compose.dontCheck hprev.unordered-containers;
  #       };
  #   };

  ffmpeg-full = prev.ffmpeg.override {
    withFdkAac = true;
    withUnfree = true;
  };

  sops-nix = inputs.sops-nix.nixosModules.sops;
})