diff --git a/README.md b/README.md index da9f9a4..670462a 100644 --- a/README.md +++ b/README.md @@ -228,6 +228,21 @@ Please [let me know](https://github.com/Misterio77/nix-starter-config/issues) any questions or issues you face with these templates, so I can add more info here! +## I'm trying to set nixpkgs.config options (e.g. allowUnfree), but they won't work! + +We instantiate nixpkgs and pass it to NixOS, to make the flake a bit simpler +and ensure both configs have the same nixpkgs instance, this has the drawback +of breaking nixpkgs configuration through in your NixOS config files. + +This is a design choice I made based on the `homeManagerConfiguration` +interface, that requires a `pkgs` instance anyway. If you prefer to set them +modularly, you'll have to remove the `pkgs` argument. If you use overlays, +you'll have to pass them into your configuration (through specialArgs) or set +`nixpkgs.overlays` right on the flake; in this case, you might prefer to use +[home-manager as a NixOS +module](https://nix-community.github.io/home-manager/index.html#sec-flakes-nixos-module) +and set `home-manager.useGlobalPkgs = true`. + ## Nix says my repo files don't exist, even though they do! Nix flakes only see files that git is currently tracked, so just `git add .` diff --git a/minimal/flake.nix b/minimal/flake.nix index 6d98fc9..3f34bec 100644 --- a/minimal/flake.nix +++ b/minimal/flake.nix @@ -17,11 +17,25 @@ # nix-colors.url = "github:misterio77/nix-colors"; }; - outputs = { nixpkgs, home-manager, ... }@inputs: { + outputs = { nixpkgs, home-manager, ... }@inputs: rec { + # This instantiates nixpkgs for each system listed + # Allowing you to configure it (e.g. allowUnfree) + # Our configurations will use these instances + legacyPackages = nixpkgs.lib.genAttrs [ "x86_64-linux" "x86_64-darwin" ] (system: + import inputs.nixpkgs { + inherit system; + # NOTE: Using `nixpkgs.config` in your NixOS config won't work + # Instead, you should set nixpkgs configs here + # (https://nixos.org/manual/nixpkgs/stable/#idm140737322551056) + + # config.allowUnfree = true; + } + ); + nixosConfigurations = { # FIXME replace with your hostname your-hostname = nixpkgs.lib.nixosSystem { - pkgs = nixpkgs.legacyPackages.x86_64-linux; + pkgs = legacyPackages.x86_64-linux; specialArgs = { inherit inputs; }; # Pass flake inputs to our config # > Our main nixos configuration file < modules = [ ./nixos/configuration.nix ]; @@ -32,7 +46,7 @@ # FIXME replace with your username@hostname "your-username@your-hostname" = home-manager.lib.homeManagerConfiguration { - pkgs = nixpkgs.legacyPackages.x86_64-linux; + pkgs = legacyPackages.x86_64-linux; extraSpecialArgs = { inherit inputs; }; # Pass flake inputs to our config # > Our main home-manager configuration file < modules = [ ./home-manager/home.nix ]; diff --git a/standard/flake.nix b/standard/flake.nix index cdace3a..6d015f3 100644 --- a/standard/flake.nix +++ b/standard/flake.nix @@ -19,8 +19,7 @@ outputs = { nixpkgs, home-manager, ... }@inputs: let - forAllSystems = nixpkgs.lib.genAttrs systems; - systems = [ + forAllSystems = nixpkgs.lib.genAttrs [ "aarch64-linux" "i686-linux" "x86_64-linux" @@ -29,7 +28,9 @@ ]; in rec { # Your custom packages and modifications - overlays = { default = import ./overlay { inherit inputs; }; }; + overlays = { + default = import ./overlay { inherit inputs; }; + }; # Reusable nixos modules you might want to export # These are usually stuff you would upstream into nixpkgs @@ -44,13 +45,22 @@ default = legacyPackages.${system}.callPackage ./shell.nix { }; }); - # Reexport nixpkgs with our overlays applied - # Acessible on our configurations, and through nix build, shell, run, etc. + # This instantiates nixpkgs for each system listed above + # Allowing you to add overlays and configure it (e.g. allowUnfree) + # Our configurations will use these instances + # Your flake will also let you access your package set through nix build, shell, run, etc. legacyPackages = forAllSystems (system: import inputs.nixpkgs { inherit system; + # This adds our overlays to pkgs overlays = builtins.attrValues overlays; - }); + # NOTE: Using `nixpkgs.config` in your NixOS config won't work + # Instead, you should set nixpkgs configs here + # (https://nixos.org/manual/nixpkgs/stable/#idm140737322551056) + + # config.allowUnfree = true; + } + ); nixosConfigurations = { # FIXME replace with your hostname