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

allowUnfree with flake-parts #521

Open
lizelive opened this issue Apr 5, 2023 · 6 comments
Open

allowUnfree with flake-parts #521

lizelive opened this issue Apr 5, 2023 · 6 comments
Labels
bug Something isn't working

Comments

@lizelive
Copy link

lizelive commented Apr 5, 2023

#383 adds allowUnfree
but new env
nix flake init --template github:cachix/devenv#flake-parts

says (inside perSystem) devenv.allowUnfree = true; # wrong

@lizelive lizelive added the bug Something isn't working label Apr 5, 2023
@lizelive lizelive changed the title how to use allowUnfree with flake-parts allowUnfree with flake-parts Apr 5, 2023
@eth3lbert
Copy link

eth3lbert commented Jul 14, 2023

You could try to add following into your flake.nix

#support unfree
_module.args.pkgs = import inputs.nixpkgs {
  inherit system;
  config.allowUnfree = true;
};

something like following:

{
  description = "Description for the project";

  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
    devenv.url = "github:cachix/devenv";
    nix2container.url = "github:nlewo/nix2container";
    nix2container.inputs.nixpkgs.follows = "nixpkgs";
    mk-shell-bin.url = "github:rrbutani/nix-mk-shell-bin";
  };

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

      perSystem = { config, self', inputs', pkgs, system, ... }: {
        # Per-system attributes can be defined here. The self' and inputs'
        # module parameters provide easy access to attributes of the same
        # system.

        # support unfree
        _module.args.pkgs = import inputs.nixpkgs {
          inherit system;
          config.allowUnfree = true;
        };

        # Equivalent to  inputs'.nixpkgs.legacyPackages.hello;
        packages.default = pkgs.hello;

        devenv.shells.default = {
          name = "my-project";

          imports = [
            # This is just like the imports in devenv.nix.
            # See https:devenv.sh/guides/using-with-flake-parts/#import-a-devenv-module
            # ./devenv-foo.nix
          ];

          # https:devenv.sh/reference/options/
          packages = [ config.packages.default ];

          enterShell = ''
            hello
          '';
        };

      };
      flake = {
        # The usual flake attributes can be defined here, including system-
        # agnostic ones like nixosModule and system-enumerating ones, although
        # those are more easily expressed in perSystem.

      };
    };
}

@felschr
Copy link

felschr commented Jul 26, 2023

I've tried the _module.args.pkgs approach with permittedInsecurePackages but I still get errors for my insecure package.

@eth3lbert
Copy link

Could you post your flake.nix?

@felschr
Copy link

felschr commented Jul 26, 2023

{
  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
    flake-parts.url = "github:hercules-ci/flake-parts";
    flake-parts.inputs.nixpkgs-lib.follows = "nixpkgs";
    devenv.url = "github:cachix/devenv";
    treefmt-nix.url = "github:numtide/treefmt-nix";
    treefmt-nix.inputs.nixpkgs.follows = "nixpkgs";
  };

  outputs = inputs@{ nixpkgs, flake-parts, ... }:
    flake-parts.lib.mkFlake { inherit inputs; } {
      imports = [ inputs.devenv.flakeModule ./treefmt.nix ];
      systems = [ "x86_64-linux" "x86_64-darwin" ];
      perSystem = { system, config, pkgs, ... }: {
        _module.args.pkgs = import nixpkgs {
          inherit system;
          config.allowUnfree = true;
          config.permittedInsecurePackages = [ "nodejs-16.20.1" ];
        };

        devenv.shells.default = {
          languages.javascript.enable = true;
          languages.javascript.package = pkgs.nodejs-16_x;
        };
      };
    };
}

@eth3lbert
Copy link

Could you also post the error? It works on my machine though.

@felschr
Copy link

felschr commented Jul 26, 2023

Interesting, it seems that it's working for me now, too, after restarting my shell.
Not sure what happened, I did run direnv reload before to make sure the environment is up-to-date.
I will make sure to send an update if I encounter the issue again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants