Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use unfree software declaratively with nixos module? #463

Closed
MichaelBergquistSuarez opened this issue Nov 28, 2018 · 7 comments
Closed

Comments

@MichaelBergquistSuarez
Copy link

MichaelBergquistSuarez commented Nov 28, 2018

I'm trying to describe my entire OS, including the user environments through my configuration file. So I don't want to use nix-env or home-manager switch to create my user environment.

So I have the following configuration:

{ config, pkgs, ... }:

{
  home-manager.users.some-user.programs.vscode.enable = true;
}

Running nixos-rebuild test, it fails with:

Package ‘vscode-1.28.2’ in /nix/store/v9zg9mc9zmgghm016dw3db37qfjhil60-nixos-18.09.1228.a4c4cbb613c/nixos/pkgs/applications/editors/vscode/default.nix:94 has an unfree license (‘unfree’), refusing to evaluate.

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

b) For `nix-env`, `nix-build`, `nix-shell` or any other Nix command you can add
  { allowUnfree = true; }
to ~/.config/nixpkgs/config.nix.

Since I already have nixpkgs.config.allowUnfree = true; in my nixos configuration, I throught I'd create ~/.config/nixpkgs/config.nix for the user.

{ config, pkgs, ... }:

{
  # `./nixpkgs-config.nix` contains `allowUnfree = true;`
  home-manager.users.some-user.home.file.".config/nixpkgs/config.nix".source = ./nixpkgs-config.nix;
  home-manager.users.some-user.programs.vscode.enable = true;
}

No luck. Then I added allowUnfree = true for the root user (since nixos-rebuild require sudo):

{ config, pkgs, ... }:

{
  # `./nixpkgs-config.nix` contains `allowUnfree = true;`
  home-manager.users.some-user.home.file.".config/nixpkgs/config.nix".source = ./nixpkgs-config.nix;
  home-manager.users.some-user.programs.vscode.enable = true;

  home-manager.users.root.home.file.".config/nixpkgs/config.nix".source = ./nixpkgs-config.nix;
}

Still no luck. Same error message. But then I uncommented vscode so that the ~/.config/nixpkgs/config.nix files could be created. And then I ran the code above again.

It worked! But needing to rebuild the OS twice feels wrong. So how could I allowUnfree = true; so that home-manager understands directly?

@rycee
Copy link
Member

rycee commented Nov 28, 2018

Try also adding

nixpkgs.config = import ./nixpkgs-config.nix;

to your configuration. That will supply the configuration into Home Manager.

@MichaelBergquistSuarez
Copy link
Author

MichaelBergquistSuarez commented Nov 28, 2018

Thank you for the quick response! Weird, unfortunately I can't get it to work.
nixos-option nixpkgs.config results in:

Value:
{ allowUnfree = true; }

That was also how it was before. Could there be some config I'm missing or entering the wrong way?

# Inside `nix repl '<nixpkgs/nixos>'
config.nixpkgs.config.allowUnfree
# Result:
# true

(import config.home-manager.users.some-user.home.file.".config/nixpkgs/config.nix".source).allowUnfree
# Result:
# true

(import config.home-manager.users.root.home.file.".config/nixpkgs/config.nix".source).allowUnfree
# Result:
# true

@rycee
Copy link
Member

rycee commented Nov 28, 2018

Sorry, I wasn't paying close enough attention! The nixpkgs.config = import ./nixpkgs-config.nix will only affect the system configuration. Try adding

home-manager.users.some-user.nixpkgs.config = import ./nixpkgs-config.nix;

which hopefully will give the right result.

@MichaelBergquistSuarez
Copy link
Author

MichaelBergquistSuarez commented Nov 29, 2018

OMGYES, it worked! Thanks a lot

It seems that I don't even need the home-manager.users.?.home.file.".config/nixpkgs/config.nix".source = ./nixpkgs-config.nix; files, which of course is awesome.

@rycee
Copy link
Member

rycee commented Nov 29, 2018

Glad it worked for you 🙂

Note, you still need the home.file line if you want to perform nix-shell, nix-env, etc. commands using the nixpkgs-config.nix configuration. This is because the

home-manager.users.some-user.nixpkgs.config = import ./nixpkgs-config.nix;

setting will only apply to packages installed, accessed through the declarative Home Manager configuration.

@srid
Copy link

srid commented Apr 3, 2019

For those wondering this is now:

nixpkgs.config.allowUnfree = true;

@RitickMadaan
Copy link

Had to add this as well to make it work thanks to Today I learned:

nixpkgs.config.allowUnfreePredicate = (_: true);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants