As a new user to nixos(stable), i am trying to build my system slowly step by step(with the help of playlist). At a point i wanted to try nh
(nix helper) which is unstable. So i tried to follow as per one of the video which says how to make use of both stable and unstable releases together.
while adding unstable release to the flakes.nix, i faced some variable error and somehow rectified those. But later landed on the flake does not provide attribute
error.
Here goes my flake.nix
{
description = "Initial Flake";
inputs = {
nixpkgs.url = "nixpkgs/nixos-23.11";
nixpkgs-unstable.url = "github:nixos/nixpkgs/nixos-unstable";
home-manager.url = "github:nix-community/home-manager/release-23.11";
home-manager.inputs.nixpkgs.follows = "nixpkgs";
};
outputs = { self, nixpkgs, nixpkgs-unstable, home-manager, ... }:
let
systemSettings = {
system = "x86_64-linux";
hostname = "nixos";
};
userSettings = {
username = "mainuser";
dotfilesDir = "~/.dotfiles";
};
system = systemSettings.system;
lib = nixpkgs.lib;
pkgs = nixpkgs.legacyPackages.${systemSettings.system};
pkgs-unstable = nixpkgs-unstable.legacyPackages.${systemSettings.system};
in {
nixosConfigurations = {
system = lib.nixosSystem {
system = systemSettings.system;
modules = [ ./configuration.nix ];
specialArgs = {
inherit systemSettings;
inherit userSettings;
inherit pkgs-unstable;
};
};
};
homeConfigurations = {
userSettings.username = home-manager.lib.homeManagerConfiguration {
inherit pkgs;
modules = [ ./home.nix ];
extraSpecialArgs = {
inherit systemSettings;
inherit userSettings;
inherit pkgs-unstable;
};
};
};
};
}
before adding unstable releases to the flakes, my nixosConfigurations
looked like this
nixosConfigurations = {
systemSettings.hostname = lib.nixosSystem {
inherit system
...
but this was throwing error at the lib
variable, so i blindly copied what his repo had, i.e, i had to add system
variable as his, removed inherit system
and add like so
system = systemSettings.system;
in {
nixosConfigurations = {
system = lib.nixosSystem {
system = systemSettings.system;
...
and continue with nix flake update
. No error till here. when i try to sudo nixos-rebuild switch --flake .
im getting
error: flake 'path:/home/mainuser/.dotfiles' does not provide attribute 'packages.x86_64-linux.nixosConfigurations."nixos".config.system.build.nixos-rebuild', 'legacyPackages.x86_64-linux.nixosConfigurations."nixos".config.system.build.nixos-rebuild' or 'nixosConfigurations."nixos".config.system.build.nixos-rebuild'
From the error and tries by reverting, i understood, i have introduced specialArgs
and extraSpecialArgs
along with the nixosConfigurations
in a wrong way. Can anyone please help me in fixing this.
my nix flake show .
output is
path:/home/mainuser/.dotfiles?lastModified=1715199342&narHash=sha256-nl4HQrlgYowfVtLR%2BqvQjq2bsWIpKOP93sKPob1Wr/o%3D
├───homeConfigurations: unknown
└───nixosConfigurations
└───system: NixOS configuration
Just for the context, this is my configuration.nix (i have removed unnecessary parts of the config and included which ever part i have changed w.r.t adding arguments, unstable releases and its packages.
{ config, pkgs, pkgs-unstable, systemSettings, userSettings, ... }:
{
imports =
[ ./hardware-configuration.nix ];
# Bootloader.
boot.loader.systemd-boot.enable = true;
boot.loader.efi.canTouchEfiVariables = true;
# Session Variables <===== introduced this for the sake of nh
environment.sessionVariables = {
FLAKE = "/home/${userSettings.username}/.dotfiles";
};
networking.hostName = systemSettings.hostname; <===== earlier i was using username directly
# Flakes
nix.settings.experimental-features = [ "nix-command" "flakes" ];
# Define a user account. Don't forget to set a password with ‘passwd’.
users.users.${userSettings.username} = {
isNormalUser = true;
description = userSettings.username;
extraGroups = [ "networkmanager" "wheel" ];
packages = with pkgs; [
firefox
kate
];
};
nixpkgs.config.allowUnfree = true;
environment.systemPackages =
(with pkgs; [
# list of unstable packages
vim # Do not forget to add an editor to edit configuration.nix! The Nano editor is also installed by default.
wget
git
neofetch
libreoffice
unzip
unrar
curl
gittyup
jre_minimal
# nix helpers
nix-output-monitor
nvd
# Media
vlc
gimp
gaphor
])
++
(with pkgs-unstable; [
# list of unstable packages
# nix helpers
nh
]);
fonts.packages = with pkgs; [
nerdfonts
];
system.stateVersion = "23.05"; # Did you read the comment?
}