set overlays through modules

This changes how the templates use nixpkgs. Before, we instantiated
nixpkgs in the flake and passd it directly to the configs; this was good
for consistency, but silently ignored `nixpkgs.*` options, generating
confusion among users. We now use modules to configure nixpkgs.

This should help avoid cases such as:
https://discourse.nixos.org/t/allowunfree-doesnt-work-with-flake-managed-system/21798/17

The drawback is that we can no longer test overlayed packages like so:
`nix build .#foo`, you can do it like so instead: `nix build
.#nixosConfigurations.your-system.pkgs.foo`.

Personally, I've been avoiding override packages globally in my own
config.
This commit is contained in:
Gabriel Fontes 2022-11-05 14:19:34 -03:00
parent b8e3385f6b
commit 3face7eddd
7 changed files with 64 additions and 78 deletions

View file

@ -2,11 +2,11 @@
"nodes": {
"hardware": {
"locked": {
"lastModified": 1665040200,
"narHash": "sha256-glqL6yj3aUm40y92inzRmowGt9aIrUrpBX7eBAMic4I=",
"lastModified": 1667585378,
"narHash": "sha256-cvOwucrjBaAkaGk3FunG+MQiwiSBeIVTtO5n/YavpC0=",
"owner": "nixos",
"repo": "nixos-hardware",
"rev": "47fd70289491c1f0c0d9a1f44fb5a9e2801120c9",
"rev": "6b35a59c19ddbbeb229fcd1d3dcd422dcc0fa927",
"type": "github"
},
"original": {
@ -23,11 +23,11 @@
"utils": "utils"
},
"locked": {
"lastModified": 1665119273,
"narHash": "sha256-neL/ZRrwk47Ke1nfjk8ltlIm+NRZyA3MBcNbqEGSBeE=",
"lastModified": 1667574732,
"narHash": "sha256-73TVk3uSQOja6Q/5OuNcpcqwo6+SMzJPRtYAjU0rBx4=",
"owner": "nix-community",
"repo": "home-manager",
"rev": "9fcae11ff29ca5f959b05c206f3724486c28ff07",
"rev": "b764068a506c6f70dba998efa0e7fcb99cb4deb2",
"type": "github"
},
"original": {
@ -38,11 +38,11 @@
},
"nixpkgs": {
"locked": {
"lastModified": 1664989420,
"narHash": "sha256-Q8IxomUjjmewsoJgO3htkXLfCckQ7HkDJ/ZhdYVf/fA=",
"lastModified": 1667482890,
"narHash": "sha256-pua0jp87iwN7NBY5/ypx0s9L9CG49Ju/NI4wGwurHc4=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "37bd39839acf99c5b738319f42478296f827f274",
"rev": "a2a777538d971c6b01c6e54af89ddd6567c055e8",
"type": "github"
},
"original": {
@ -61,11 +61,11 @@
},
"utils": {
"locked": {
"lastModified": 1659877975,
"narHash": "sha256-zllb8aq3YO3h8B/U0/J1WBgAL8EX5yWf5pMj3G0NAmc=",
"lastModified": 1667077288,
"narHash": "sha256-bdC8sFNDpT0HK74u9fUkpbf1MEzVYJ+ka7NXCdgBoaA=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "c0e246b9b83f637f4681389ecabcb2681b4f3af0",
"rev": "6ee9ebb6b1ee695d2cacc4faa053a7b9baa76817",
"type": "github"
},
"original": {

View file

@ -4,38 +4,24 @@
inputs = {
# Nixpkgs
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
hardware.url = "github:nixos/nixos-hardware";
# Home manager
home-manager.url = "github:nix-community/home-manager";
home-manager.inputs.nixpkgs.follows = "nixpkgs";
# TODO: Add any other flake you might need
hardware.url = "github:nixos/nixos-hardware";
# Shameless plug: looking for a way to nixify your themes and make
# everything match nicely? Try nix-colors!
# nix-colors.url = "github:misterio77/nix-colors";
};
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;
}
);
outputs = { nixpkgs, home-manager, ... }@inputs: {
nixosConfigurations = {
# FIXME replace with your hostname
your-hostname = nixpkgs.lib.nixosSystem {
pkgs = legacyPackages.x86_64-linux;
pkgs = nixpkgs.legacyPackages.x86_64-linux;
specialArgs = { inherit inputs; }; # Pass flake inputs to our config
# > Our main nixos configuration file <
modules = [ ./nixos/configuration.nix ];
@ -45,7 +31,7 @@
homeConfigurations = {
# FIXME replace with your username@hostname
"your-username@your-hostname" = home-manager.lib.homeManagerConfiguration {
pkgs = legacyPackages.x86_64-linux;
pkgs = nixpkgs.legacyPackages.x86_64-linux;
extraSpecialArgs = { inherit inputs; }; # Pass flake inputs to our config
# > Our main home-manager configuration file <
modules = [ ./home-manager/home.nix ];

View file

@ -52,7 +52,7 @@
# TODO: You can set an initial password for your user.
# If you do, you can skip setting a root password by passing '--no-root-passwd' to nixos-install.
# Be sure to change it (using passwd) after rebooting!
# initialPassword = "correcthorsebatterystaple";
initialPassword = "correcthorsebatterystaple";
isNormalUser = true;
openssh.authorizedKeys.keys = [
# TODO: Add your SSH public key(s) here, if you plan on using SSH to connect

View file

@ -2,11 +2,11 @@
"nodes": {
"hardware": {
"locked": {
"lastModified": 1665040200,
"narHash": "sha256-glqL6yj3aUm40y92inzRmowGt9aIrUrpBX7eBAMic4I=",
"lastModified": 1667585378,
"narHash": "sha256-cvOwucrjBaAkaGk3FunG+MQiwiSBeIVTtO5n/YavpC0=",
"owner": "nixos",
"repo": "nixos-hardware",
"rev": "47fd70289491c1f0c0d9a1f44fb5a9e2801120c9",
"rev": "6b35a59c19ddbbeb229fcd1d3dcd422dcc0fa927",
"type": "github"
},
"original": {
@ -23,11 +23,11 @@
"utils": "utils"
},
"locked": {
"lastModified": 1665119273,
"narHash": "sha256-neL/ZRrwk47Ke1nfjk8ltlIm+NRZyA3MBcNbqEGSBeE=",
"lastModified": 1667574732,
"narHash": "sha256-73TVk3uSQOja6Q/5OuNcpcqwo6+SMzJPRtYAjU0rBx4=",
"owner": "nix-community",
"repo": "home-manager",
"rev": "9fcae11ff29ca5f959b05c206f3724486c28ff07",
"rev": "b764068a506c6f70dba998efa0e7fcb99cb4deb2",
"type": "github"
},
"original": {
@ -38,11 +38,11 @@
},
"nixpkgs": {
"locked": {
"lastModified": 1664989420,
"narHash": "sha256-Q8IxomUjjmewsoJgO3htkXLfCckQ7HkDJ/ZhdYVf/fA=",
"lastModified": 1667482890,
"narHash": "sha256-pua0jp87iwN7NBY5/ypx0s9L9CG49Ju/NI4wGwurHc4=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "37bd39839acf99c5b738319f42478296f827f274",
"rev": "a2a777538d971c6b01c6e54af89ddd6567c055e8",
"type": "github"
},
"original": {
@ -61,11 +61,11 @@
},
"utils": {
"locked": {
"lastModified": 1659877975,
"narHash": "sha256-zllb8aq3YO3h8B/U0/J1WBgAL8EX5yWf5pMj3G0NAmc=",
"lastModified": 1667077288,
"narHash": "sha256-bdC8sFNDpT0HK74u9fUkpbf1MEzVYJ+ka7NXCdgBoaA=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "c0e246b9b83f637f4681389ecabcb2681b4f3af0",
"rev": "6ee9ebb6b1ee695d2cacc4faa053a7b9baa76817",
"type": "github"
},
"original": {

View file

@ -4,13 +4,13 @@
inputs = {
# Nixpkgs
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
hardware.url = "github:nixos/nixos-hardware";
# Home manager
home-manager.url = "github:nix-community/home-manager";
home-manager.inputs.nixpkgs.follows = "nixpkgs";
# TODO: Add any other flake you might need
hardware.url = "github:nixos/nixos-hardware";
# Shameless plug: looking for a way to nixify your themes and make
# everything match nicely? Try nix-colors!
@ -28,11 +28,23 @@
];
in
rec {
# Your custom packages and modifications
overlays = {
default = import ./overlay { inherit inputs; };
};
# Your custom packages
# Acessible through 'nix build', 'nix shell', etc
packages = forAllSystems (system:
let pkgs = nixpkgs.legacyPackages.${system};
in
import ./pkgs { inherit pkgs; }
);
# Devshell for bootstrapping
# Acessible through 'nix develop' or 'nix-shell' (legacy)
devShells = forAllSystems (system:
let pkgs = nixpkgs.legacyPackages.${system};
in
import ./shell.nix { inherit pkgs; }
);
# Your custom packages and modifications, exported as overlays
overlays = import ./overlays;
# Reusable nixos modules you might want to export
# These are usually stuff you would upstream into nixpkgs
nixosModules = import ./modules/nixos;
@ -40,37 +52,15 @@
# These are usually stuff you would upstream into home-manager
homeManagerModules = import ./modules/home-manager;
# Devshell for bootstrapping
# Accessible through 'nix develop' or 'nix-shell' (legacy)
devShells = forAllSystems (system: {
default = nixpkgs.legacyPackages.${system}.callPackage ./shell.nix { };
});
# 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
your-hostname = nixpkgs.lib.nixosSystem {
pkgs = legacyPackages.x86_64-linux;
specialArgs = { inherit inputs; }; # Pass flake inputs to our config
modules = (builtins.attrValues nixosModules) ++ [
# > Our main nixos configuration file <
./nixos/configuration.nix
# Our common nixpkgs config (unfree, overlays, etc)
(import ./nixpkgs-config.nix { inherit overlays; })
];
};
};
@ -78,11 +68,13 @@
homeConfigurations = {
# FIXME replace with your username@hostname
"your-username@your-hostname" = home-manager.lib.homeManagerConfiguration {
pkgs = legacyPackages.x86_64-linux;
pkgs = nixpkgs.legacyPackages.x86_64-linux; # Home-manager requires 'pkgs' instance
extraSpecialArgs = { inherit inputs; }; # Pass flake inputs to our config
modules = (builtins.attrValues homeManagerModules) ++ [
# > Our main home-manager configuration file <
./home-manager/home.nix
# Our common nixpkgs config (unfree, overlays, etc)
(import ./nixpkgs-config.nix { inherit overlays; })
];
};
};

View file

@ -0,0 +1,10 @@
{ overlays, ... }:
{
nixpkgs = {
config = {
allowUnfree = true;
};
# Overlays is an attrset, convert to a list
overlays = builtins.attrValues overlays;
};
}

View file

@ -1,6 +1,5 @@
# This file defines two overlays and composes them
{ inputs, ... }:
let
# This file defines overlays
{
# This one brings our custom packages from the 'pkgs' directory
additions = final: _prev: import ../pkgs { pkgs = final; };
@ -12,5 +11,4 @@ let
# ...
# });
};
in
inputs.nixpkgs.lib.composeManyExtensions [ additions modifications ]
}