home-manager icon indicating copy to clipboard operation
home-manager copied to clipboard

bug: Flake config cannot use unfree packages despite nixpkgs.config.allowUnfree = true

Open schuelermine opened this issue 2 years ago • 11 comments

Is there an existing issue for this?

  • [x] I have searched the existing issues

Issue description

I have a flake config (source) and as of nixpkgs c777cdf5c564015d5f63b09cc93bef4178b19b01 and home-manager 538343be863cb0b9e9f1471e6dc09e0e140c7b3d unfree packages refuse to evaluate despite a nixpkgs.config.allowUnfree = true; in my config.

Maintainer CC

No response

System information

- system: `"x86_64-linux"`
 - host os: `Linux 5.17.5, NixOS, 22.05 (Quokka), 22.05.20220503.cbe587c`
 - multi-user?: `yes`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.9.0pre20220428_4bb111c`
 - channels(root): `"nixos, nixpkgs"`
 - channels(anselmschueler): `""`
 - nixpkgs: `/nix/var/nix/profiles/per-user/root/channels/nixos`

schuelermine avatar May 06 '22 07:05 schuelermine

Try adding --impure.

SuperSandro2000 avatar May 06 '22 12:05 SuperSandro2000

please test if the commit before https://github.com/NixOS/nixpkgs/commit/1c49b81263858c69b932da05ae63a7767b308e74 works

assuming it does then something needs to be changed in https://github.com/nix-community/home-manager/blob/master/modules/misc/nixpkgs.nix

nixos nixpkgs.nix for reference https://github.com/NixOS/nixpkgs/blob/master/nixos/modules/misc/nixpkgs.nix

Artturin avatar May 06 '22 13:05 Artturin

@Artturin NixOS/nixpkgs@a585b1c70900a1ecf0a782eb0f6f09d405e5e6e3 doesn’t work either.

schuelermine avatar May 06 '22 13:05 schuelermine

For someone encountering this same issue, a workaround is to add this your nixpkgs config: nixpkgs.config.allowUnfreePredicate = (pkg: true);

This will allow any unfree package to be installed until this issue is resolved.

Pablo1107 avatar May 06 '22 15:05 Pablo1107

please provide a reproducer flake

Artturin avatar May 18 '22 17:05 Artturin

@Artturin this fails when you do home-manager build --flake .#test:

{
  inputs.home-manager = {
    url = "github:nix-community/home-manager";
    inputs.nixpkgs.follows = "nixpkgs";
  };

  outputs = { self, nixpkgs, home-manager }: let
    system = "x86_64-linux";
    allowUnfree = { nixpkgs.config.allowUnfree = true; };
  in {
    nixosConfigurations.test = nixpkgs.lib.nixosSystem {
      inherit system;
      modules = [
        {
          fileSystems."/" = { device = "/dev/disk/by-uuid/b906a306-ee7f-4603-b7b4-f20a46face83"; };
          boot.loader.systemd-boot.enable = true;
        }

        allowUnfree

        ({ pkgs, ... }: {
          environment.systemPackages = [ pkgs.unrar ];
        })
      ];
    };

    homeConfigurations.test = home-manager.lib.homeManagerConfiguration {
      inherit system;
      username = "test";
      homeDirectory = "/home/test";
      configuration.imports = [
        allowUnfree

        ({ pkgs, ... }: {
          home.packages = [ pkgs.unrar ];
        })
      ];
    };
  };
}

cmm avatar May 18 '22 18:05 cmm

please provide a reproducer flake

Example: github:schuelermine/home-manager-configuration/39aa0d5726a3309c287961b19f7aae75319fff08

schuelermine avatar May 18 '22 18:05 schuelermine

This issue has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/nixpkgs-unfree-configs-not-respected/20546/9

nixos-discourse avatar Jul 25 '22 15:07 nixos-discourse

If I am reading the code correctly:

  1. home-manager will pass the pkgs argument given to lib.homeManagerConfiguration straight to modules.nix.
  2. Then an inline module modules.nix will set the value as a default for _module.args.pkgs (the pkgs argument passed to modules).
  3. Also nixpkgs.nix module will set the same argument with a higher priority (obviously, mkDefault has higher number=lower priority than mkOverride defaultPriority)
  • The value will be a newly instantiated Nixpkgs based on the path of the original pkgs attribute. It needs to be re-instantiated so that the value of nixpkgs.config home-manager option can be passed to it.

It looks like this changed since https://github.com/schuelermine/home-manager-configuration/commit/39aa0d5726a3309c287961b19f7aae75319fff08 (the lib.homeManagerConfiguration did not previously require pkgs argument). Is this still an issue, @schuelermine?

jtojnar avatar Sep 16 '22 12:09 jtojnar

Yes, this is still an issue. In this state: https://github.com/schuelermine/home-manager-configuration/tree/9dd9765757f1870f55ed988e058199b9644dc331 my home-manager configuration does not work.

schuelermine avatar Sep 16 '22 13:09 schuelermine

Hmm, you are right, I managed to reproduce it with Michael’s config from above, updated to the new format as well:

{
  inputs.home-manager = {
    url = "github:nix-community/home-manager";
    inputs.nixpkgs.follows = "nixpkgs";
  };

  outputs = { self, nixpkgs, home-manager }: let
    system = "x86_64-linux";
    allowUnfree = { nixpkgs.config.allowUnfree = true; };
  in {
    nixosConfigurations.test = nixpkgs.lib.nixosSystem {
      inherit system;
      modules = [
        {
          fileSystems."/" = { device = "/dev/disk/by-uuid/b906a306-ee7f-4603-b7b4-f20a46face83"; };
          boot.loader.systemd-boot.enable = true;
        }

        allowUnfree

        ({ pkgs, ... }: {
          environment.systemPackages = [ pkgs.unrar ];
        })
      ];
    };

    homeConfigurations.test = home-manager.lib.homeManagerConfiguration {
      pkgs = nixpkgs.legacyPackages.${system};
      modules = [
        {
          home = {
            username = "test";
            homeDirectory = "/home/test";
            stateVersion = "22.11";
          };
        }

        allowUnfree

        ({ pkgs, ... }: {
          home.packages = [ pkgs.unrar ];
        })
      ];
    };
  };
}

jtojnar avatar Sep 16 '22 13:09 jtojnar

Thank you for your contribution! I marked this issue as stale due to inactivity. Please be considerate of people watching this issue and receiving notifications before commenting 'I have this issue too'. We welcome additional information that will help resolve this issue. Please read the relevant sections below before commenting.

If you are the original author of the issue

  • If this is resolved, please consider closing it so that the maintainers know not to focus on this.
  • If this might still be an issue, but you are not interested in promoting its resolution, please consider closing it while encouraging others to take over and reopen an issue if they care enough.
  • If you know how to solve the issue, please consider submitting a Pull Request that addresses this issue.
If you are not the original author of the issue

  • If you are also experiencing this issue, please add details of your situation to help with the debugging process.
  • If you know how to solve the issue, please consider submitting a Pull Request that addresses this issue.
Memorandum on closing issues

Don't be afraid to manually close an issue, even if it holds valuable information. Closed issues stay in the system for people to search, read, cross-reference, or even reopen – nothing is lost! Closing obsolete issues is an important way to help maintainers focus their time and effort.

stale[bot] avatar Dec 15 '22 20:12 stale[bot]

I remove my allowUnfreePredicate and leave only the allowUnfree and tried installing zoom-us via my flake dotfiles and the issue seemed to be resolved, no error appeared.

Pablo1107 avatar Dec 28 '22 17:12 Pablo1107

Same here, appears to be resolved.

lunik1 avatar Jan 01 '23 15:01 lunik1

I remove my allowUnfreePredicate and leave only the allowUnfree and tried installing zoom-us via my flake dotfiles and the issue seemed to be resolved, no error appeared.

Nevermind, I was testing on a macOS system. Now I just tried the same on a Linux system but the issues persists.

Anyone else can test?

Pablo1107 avatar Jan 10 '23 23:01 Pablo1107

I removed it on my Linux system and had no issue

lunik1 avatar Jan 11 '23 00:01 lunik1

This should work:

homeConfigurations.test = home-manager.lib.homeManagerConfiguration {
  pkgs = import nixpkgs {
    inherit system;
    config.allowUnfree = true;
  };
  modules = [ ... ];
};

homeManagerConfiguration uses the provided pkgs's config to build its own pkgs, so nixpkgs.config should not be used in that situation. The fact that allowUnfreePredicate works is an accident: the default pkgs.config does not include allowUnfreePredicate because it is not defined in the nixpkgs config module, so the value you specify via nixpkgs.config will not get overridden by pkgs.config.

Ideally we should allow homeManagerConfiguration to not take a pkgs argument, in which case nixpkgs configuration would be configured modularly with nixpkgs.config, just like nixpkgs.lib.nixosSystem.

Note that there's a similar-but-different issue with NixOS: https://github.com/NixOS/nixpkgs/issues/118115

ncfavier avatar Jan 11 '23 11:01 ncfavier

Thank you for your contribution! I marked this issue as stale due to inactivity. Please be considerate of people watching this issue and receiving notifications before commenting 'I have this issue too'. We welcome additional information that will help resolve this issue. Please read the relevant sections below before commenting.

If you are the original author of the issue

  • If this is resolved, please consider closing it so that the maintainers know not to focus on this.
  • If this might still be an issue, but you are not interested in promoting its resolution, please consider closing it while encouraging others to take over and reopen an issue if they care enough.
  • If you know how to solve the issue, please consider submitting a Pull Request that addresses this issue.
If you are not the original author of the issue

  • If you are also experiencing this issue, please add details of your situation to help with the debugging process.
  • If you know how to solve the issue, please consider submitting a Pull Request that addresses this issue.
Memorandum on closing issues

Don't be afraid to manually close an issue, even if it holds valuable information. Closed issues stay in the system for people to search, read, cross-reference, or even reopen – nothing is lost! Closing obsolete issues is an important way to help maintainers focus their time and effort.

stale[bot] avatar Apr 11 '23 21:04 stale[bot]

I don't believe this is resolved as of cc6745b35fefe48624ebf573382e1e0e4a6fe85e. Repro:

cd "$(mktemp -d)"
nix flake init --template github:nix-community/home-manager
curl -sSL -O 'https://gist.githubusercontent.com/kamalmarhubi/5f35b5227ece3644982105ac6eeadb29/raw/7b417610fa160d64df41d1cc3a8723d82e9a4a06/home.nix' > home.nix
nix build .#homeConfigurations.jdoe.activationPackage
Output
error: Package ‘1password-cli-2.18.0’ in /nix/store/ain1lgmwvhc90yhw1rki6c7xhb0jp2hj-source/pkgs/applications/misc/1password/default.nix:67 has an unfree license (‘unfree’), refusing to evaluate.

       a) To temporarily allow unfree packages, you can use an environment variable
          for a single invocation of the nix tools.

            $ export NIXPKGS_ALLOW_UNFREE=1

        Note: For `nix shell`, `nix build`, `nix develop` or any other Nix 2.4+
        (Flake) command, `--impure` must be passed in order to read this
        environment variable.

       b) For `nixos-rebuild` you can set
         { nixpkgs.config.allowUnfree = true; }
       in configuration.nix to override this.

       Alternatively you can configure a predicate to allow specific packages:
         { nixpkgs.config.allowUnfreePredicate = pkg: builtins.elem (lib.getName pkg) [
             "1password-cli"
           ];
         }

       c) For `nix-env`, `nix-build`, `nix-shell` or any other Nix command you can add
         { allowUnfree = true; }
       to ~/.config/nixpkgs/config.nix.
(use '--show-trace' to show detailed location information)
$ nix flake metadata
Resolved URL:  path:/private/var/folders/6f/g2lg4n1x7pzcq9zck4hdgspc0000gn/T/tmp.M1bCBfhq
Locked URL:    path:/private/var/folders/6f/g2lg4n1x7pzcq9zck4hdgspc0000gn/T/tmp.M1bCBfhq?lastModified=1686181065&narHash=sha256-P8j3hVbmPOfUUhkwQKYgsS%2fVlnd2m4E8Ydf19LDhm5Y=
Description:   Home Manager configuration of Jane Doe
Path:          /nix/store/lw8ixb349nym7gzcwkl7f4qw5mfm9h4m-source
Last modified: 2023-06-07 19:37:45
Inputs:
├───home-manager: github:nix-community/home-manager/cc6745b35fefe48624ebf573382e1e0e4a6fe85e
│   └───nixpkgs follows input 'nixpkgs'
└───nixpkgs: github:nixos/nixpkgs/4729ffac6fd12e26e5a8de002781ffc49b0e94b7

The allowUnfreePredicate workaround works though:

$ sed -i.bak 's/allowUnfree = true/allowUnfreePredicate = (pkg: true)/' home.nix
$ nix build .#homeConfigurations.jdoe.activationPackage
[0/44 built, 1/115/167 copied (224.4/667.8 MiB), 48.5/152.2 MiB DL] fetching gcc-12.3.0 from https://cache.nixos.org

kamalmarhubi avatar Jun 07 '23 23:06 kamalmarhubi

This issue has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/whats-the-use-case-for-allowunfreepredicate-and-friends/30468/5

nixos-discourse avatar Jul 16 '23 19:07 nixos-discourse

I came to linux ecosystem (and later nixos specifically) wanting to move away from proprietary madness forcing me to look for ways to bypass unnecessary limitations. Just to see a stupid flag like this, making me jump hoops for hours because some guy wanted people to use free software, I will use whatever software I want and forcing such stupid flag is just causing problems.

atropos112 avatar Nov 25 '23 14:11 atropos112

I am sorry for being unclear. My anger is not towards creators/maintainers of home-manager I am still finding out how this works but am repeatedly fascinated about what it is allowing me to do. My anger is towards whomever created this idiotic flag. It feels like a rug-pull, you set up your stuff, devote time to it and then choose to use software someone didn't give their blessing to so now you have to spend hours figuring out how to bypass their flag.

atropos112 avatar Nov 25 '23 14:11 atropos112

I am sorry for being unclear. My anger is not towards creators/maintainers of home-manager I am still finding out how this works but am repeatedly fascinated about what it is allowing me to do. My anger is towards whomever created this idiotic flag. It feels like a rug-pull, you set up your stuff, devote time to it and then choose to use software someone didn't give their blessing to so now you have to spend hours figuring out how to bypass their flag.

Huh? How is having the choice to use unfree software bad?

GetPsyched avatar Nov 25 '23 14:11 GetPsyched

Github issues are not your personal blog, if you want to complain just to complain this is the wrong place for it.

eclairevoyant avatar Nov 25 '23 14:11 eclairevoyant

https://github.com/nix-community/home-manager/issues/2942#issuecomment-1826348273 Having such flag is not bad, having it set to false by default is bad, especially when it becomes problematic as to how to actually make it consistent across the configuration.

https://github.com/nix-community/home-manager/issues/2942#issuecomment-1826348422 you are correct, ill stop now sorry.

atropos112 avatar Nov 25 '23 14:11 atropos112

To be more straightforward. This is bug tracker, not a conversation forum. I find that a lot of new people to software dev do not understand the distinction. This is not for your feelings but for logical conversation to present issues, logs, output, and ideas on how to resolve issues, or make a product better.

sedlund avatar Nov 25 '23 14:11 sedlund

I created this StackOverflow question to help everyone figure this out for the various different scenarios of using Nix:

Since GitHub issue comments are structured more like a forum of endless posts sorted by time instead of a proper question & answer site.

nhooey avatar Dec 01 '23 12:12 nhooey