eval nixpkgs on minimal, document nixpkgs config

Fixes https://github.com/Misterio77/nix-starter-configs/issues/3
This commit is contained in:
Gabriel Fontes 2022-09-19 10:45:02 -03:00
parent be00b40c8f
commit 2e4b816bd6
No known key found for this signature in database
GPG key ID: 2E54EA7BFE630916
3 changed files with 48 additions and 9 deletions

View file

@ -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 any questions or issues you face with these templates, so I can add more info
here! 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 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 .` Nix flakes only see files that git is currently tracked, so just `git add .`

View file

@ -17,11 +17,25 @@
# nix-colors.url = "github:misterio77/nix-colors"; # 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 = { nixosConfigurations = {
# FIXME replace with your hostname # FIXME replace with your hostname
your-hostname = nixpkgs.lib.nixosSystem { 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 specialArgs = { inherit inputs; }; # Pass flake inputs to our config
# > Our main nixos configuration file < # > Our main nixos configuration file <
modules = [ ./nixos/configuration.nix ]; modules = [ ./nixos/configuration.nix ];
@ -32,7 +46,7 @@
# FIXME replace with your username@hostname # FIXME replace with your username@hostname
"your-username@your-hostname" = "your-username@your-hostname" =
home-manager.lib.homeManagerConfiguration { home-manager.lib.homeManagerConfiguration {
pkgs = nixpkgs.legacyPackages.x86_64-linux; pkgs = legacyPackages.x86_64-linux;
extraSpecialArgs = { inherit inputs; }; # Pass flake inputs to our config extraSpecialArgs = { inherit inputs; }; # Pass flake inputs to our config
# > Our main home-manager configuration file < # > Our main home-manager configuration file <
modules = [ ./home-manager/home.nix ]; modules = [ ./home-manager/home.nix ];

View file

@ -19,8 +19,7 @@
outputs = { nixpkgs, home-manager, ... }@inputs: outputs = { nixpkgs, home-manager, ... }@inputs:
let let
forAllSystems = nixpkgs.lib.genAttrs systems; forAllSystems = nixpkgs.lib.genAttrs [
systems = [
"aarch64-linux" "aarch64-linux"
"i686-linux" "i686-linux"
"x86_64-linux" "x86_64-linux"
@ -29,7 +28,9 @@
]; ];
in rec { in rec {
# Your custom packages and modifications # 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 # Reusable nixos modules you might want to export
# These are usually stuff you would upstream into nixpkgs # These are usually stuff you would upstream into nixpkgs
@ -44,13 +45,22 @@
default = legacyPackages.${system}.callPackage ./shell.nix { }; default = legacyPackages.${system}.callPackage ./shell.nix { };
}); });
# Reexport nixpkgs with our overlays applied # This instantiates nixpkgs for each system listed above
# Acessible on our configurations, and through nix build, shell, run, etc. # 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: legacyPackages = forAllSystems (system:
import inputs.nixpkgs { import inputs.nixpkgs {
inherit system; inherit system;
# This adds our overlays to pkgs
overlays = builtins.attrValues overlays; 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 = { nixosConfigurations = {
# FIXME replace with your hostname # FIXME replace with your hostname