Unable to use overlay which has unfree attribute set

Hi,

I am new to NixOS and Home-manager but i’ve managed to get a working system up and running but i am now facing issues getting certain packages installed using the “unstable” branch.

The issue is that nixvim want’s to install terraform which has an unfree license (bsl11):

error: Package ‘terraform-1.9.4’ in /nix/store/sfycwi72zfjsspidinx56ajaiffpyh17-source/pkgs/applications/networking/cluster/terraform/default.nix:52 has an unfree license (‘bsl11’), refusing to evaluate

So i’ve been trying to get nixvim to use the unstable overlay which has the config.allowUnfree = true; option set. But as you can probably see i’m not sure how everything works together, so the end result is that home-manager still complains about terraform and it’s “unfree” license.

I’ve looked at other persons configurations and mainly i’ve been looking at Misterio77/nix-starter-configs. So a lot of my config i’ve just copied and pasted without really understanding how everything works.

But this is my flake.nix file:

{
  description = "Vinylen nixos config";

  inputs = {
    # Nixpkgs
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.05";
    nixpkgs-unstable.url = "github:nixos/nixpkgs/nixos-unstable";
    # Also see the 'unstable-packages' overlay at 'overlays/default.nix'.
    stylix.url = "github:danth/stylix";

    nixvim = {
      url = "github:vinylen/nixvim-config";
      # If you are not running an unstable channel of nixpkgs, select the corresponding branch of nixvim.
      # url = "github:nix-community/nixvim/nixos-24.05";
      inputs.nixpkgs.follows = "nixpkgs-unstable";
    };

    # home-manager, used for managing user configuration
    home-manager = {
      url = "github:nix-community/home-manager/release-24.05";
      # The `follows` keyword in inputs is used for inheritance.
      # Here, `inputs.nixpkgs` of home-manager is kept consistent with
      # the `inputs.nixpkgs` of the current flake,
      # to avoid problems caused by different versions of nixpkgs.
      inputs.nixpkgs.follows = "nixpkgs";
    };
  };

  outputs = {
    self,
    nixpkgs,
    nixpkgs-unstable,
    home-manager,
    stylix,
    ...
  } @ inputs: let
    inherit (self) outputs;
    # Supported systems for your flake packages, shell, etc.
    systems = [
      "x86_64-linux"
    ];
    # This is a function that generates an attribute by calling a function you
    # pass to it, with each system as an argument
    forAllSystems = nixpkgs.lib.genAttrs systems;
  in {
    # Your custom packages
    # Accessible through 'nix build', 'nix shell', etc
    packages = forAllSystems (system: import ./pkgs nixpkgs.legacyPackages.${system});
    # Formatter for your nix files, available through 'nix fmt'
    # Other options beside 'alejandra' include 'nixpkgs-fmt'
    formatter = forAllSystems (system: nixpkgs.legacyPackages.${system}.alejandra);

    # Your custom packages and modifications, exported as overlays
    overlays = import ./overlays {inherit inputs;};
    # Reusable nixos modules you might want to export
    # These are usually stuff you would upstream into nixpkgs
    nixosModules = import ./modules/nixos;
    # Reusable home-manager modules you might want to export
    # These are usually stuff you would upstream into home-manager
    homeManagerModules = import ./modules/home-manager;

    # NixOS configuration entrypoint
    # Available through 'nixos-rebuild --flake .#your-hostname'
    nixosConfigurations = {
      knut = nixpkgs.lib.nixosSystem {
        specialArgs = {
          # pkgs-unstable = import nixpkgs-unstable {
          #   inherit systems;
          #   config.allowUnfree = true;
          # };
          inherit inputs outputs;
        };
        modules = [
          # > Our main nixos configuration file <
          ./nixos/configuration.nix
          stylix.nixosModules.stylix
        ];
      };
    };
    # Standalone home-manager configuration entrypoint
    # Available through 'home-manager --flake .#your-username@your-hostname'
    homeConfigurations = {
      "vicnil@knut" = home-manager.lib.homeManagerConfiguration {
        pkgs = import nixpkgs {
          system = "x86_64-linux";
          config.allowUnfree = true;
        }; # Home-manager requires 'pkgs' instance
        extraSpecialArgs = {
          pkgs-unstable = import nixpkgs-unstable {
            inherit systems;
            config.allowUnfree = true;
          };
          inherit inputs outputs;
        };
        modules = [
          # > Our main home-manager configuration file <
          ./home-manager/home.nix
        ];
      };
    };
  };
}

Then here is my nixos-config/home-manager/home.nix configuration:

{
  pkgs,
  inputs,
  outputs,
  ...
}: {
  imports = [
    ./devops.nix
    ./zsh.nix
  ];

  nixpkgs = {
    config.allowUnfree = true;
    overlays = [
      outputs.overlays.unstable-packages
    ];
  };
  home.username = "vicnil";
  home.homeDirectory = "/home/vicnil";

  # link the configuration file in current directory to the specified location in home directory
  # home.file.".config/i3/wallpaper.jpg".source = ./wallpaper.jpg;

  # link all files in `./scripts` to `~/.config/i3/scripts`
  home.file.".local/bin" = {
    source = ./scripts;
    recursive = true; # link recursively
    executable = true; # make all files executable
  };

  # Packages that should be installed to the user profile.
  home.packages = with pkgs; [
    # here is some command line tools I use frequently
    # feel free to add your own or remove some of them
    # Nixvim related
    inputs.nixvim.packages.${system}.default
    ansible-lint
    tflint

    # archives
    zip
    xz
    unzip
    p7zip

    # utils
    bat
    ripgrep # recursively searches directories for a regex pattern
    jq # A lightweight and flexible command-line JSON processor
    yq-go # yaml processor https://github.com/mikefarah/yq
    eza # A modern replacement for ‘ls’
    fzf # A command-line fuzzy finder
    vault

    # networking tools
    mtr # A network diagnostic tool
    iperf3
    dnsutils # `dig` + `nslookup`
    doggo
    ldns # replacement of `dig`, it provide the command `drill`
    socat # replacement of openbsd-netcat
    nmap # A utility for network discovery and security auditing
    openssl

    # misc
    file
    gawk
    gnupg
    gnused
    gnutar
    ncdu
    pandoc
    rbw
    tig
    tmux-xpanes
    tree
    which
    zstd

    # nix related
    #
    # it provides the command `nom` works just like `nix`
    # with more details log output
    nix-output-monitor
    nurl

    # productivity
    atop
    btop # replacement of htop/nmon
    htop # Classic htop
    iotop # io monitoring
    iftop # network monitoring

    # system call monitoring
    strace # system call monitoring
    ltrace # library call monitoring
    lsof # list open files

    # system tools
    sysstat
    lm_sensors # for `sensors` command
    ethtool
    pciutils # lspci
    usbutils # lsusb
    powertop
  ];
  home.stateVersion = "24.05";

  # Let home Manager install and manage itself.
  programs.home-manager.enable = true;
}

Here is my nixos-config/overlays/default.nix:

# This file defines overlays
{inputs, ...}: {
  # This one brings our custom packages from the 'pkgs' directory
  additions = final: _prev: import ../pkgs final.pkgs;

  # This one contains whatever you want to overlay
  # You can change versions, add patches, set compilation flags, anything really.
  # https://nixos.wiki/wiki/Overlays
  modifications = final: prev: {
    lastpass-cli = prev.callPackage ../pkgs/lastpass-cli/default.nix {};
  };

  # When applied, the unstable nixpkgs set (declared in the flake inputs) will
  # be accessible through 'pkgs.unstable'
  unstable-packages = final: _prev: {
    unstable = import inputs.nixpkgs-unstable {
      system = final.system;
      config.allowUnfree = true;
    };
  };
}

Can anyone give some pointers as to what i am doing wrong, or perhaps share their config on how they would do it?

Much appreciated,
Thanks!

Yeah maybe don’t do either of those things. I would recommend starting with Nixpkgs Reference Manual.

This is exactly the type of thing misterio writes, which is why I don’t recommend copying misterio. Passing outputs is unnecessary, use inputs.self

I don’t really know what you’re doing here, but final.pkgs is better expressed as just… final.
And always prefer final over prev, so use final.callPackage in the second overlay.

Also, try to keep the number of overlays down, the more you add the longer things take.

Anyway, if you need help, please post the full config, and the exact command you used to build your config, not just a couple files at a time.
A link to a git repo would be easiest to work with.

Hey, thank you for your assistance! I’ve been looking at Nixpkgs reference manual and it doesn’t seem as bad as everyone claims it to be. So i’ll definetly give that a look, thanks!

This is exactly the type of thing misterio writes, which is why I don’t recommend copying misterio. Passing outputs is unnecessary, use inputs.self

Ah i see, i don’t quite get what you mean by “inputs.self” though. I tried setting it to inherit inputs.self; but that just produced a bunch of errors, so i might have been thinking about that one wrong?

I don’t really know what you’re doing here, but final.pkgs is better expressed as just… final.
And always prefer final over prev, so use final.callPackage in the second overlay.

Good catch, i implemented the changes you suggested :slight_smile:

So i created a new git repo with my nixos-config with some “secret” stuff removed, it would be very kind if you would give it a glance and see why allowUnfree = true; doesn’t work for me. Here is the repo :slight_smile:

Thanks!

You have specialArgs = { inherit inputs; }, which means you can use inputs.self.whatever instead of outputs.whatever wherever you needed an output from the current flake.

nixvim-config/flake.nix at 49049df0bdc92cb68dd113b74e47e118892696ea · vinylen/nixvim-config · GitHub is one of the offending lines. You’re using a nixpkgs instance that is different from the nixpkgs instance you configured in your NixOS and HM config.

GitHub - vinylen/nixvim-config: 🗒️ An easy-setup configuration for NixVim, focused on straightforward customization. should expose an overlay that you use, or at least a function that allows you to supply your own pkgs.

Btw, you have some overlays repeated in your config, that might be unnecessarily slowing your eval down.