I wanted to install a stable package on an unstable system

I wanted to install the stable package but got an error:


{
  description = "";

  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
    stable.url = "github:NixOS/nixpkgs/nixos-24.05";
    alejandra.url = "github:kamadorueda/alejandra/3.0.0";
    hyprland.url = "github:hyprwm/Hyprland";
    hypr-contrib.url = "github:hyprwm/contrib";
    hyprpicker.url = "github:hyprwm/hyprpicker";
    hyprmag.url = "github:SIMULATAN/hyprmag";

    home-manager = {
      url = "github:nix-community/home-manager";
      inputs.nixpkgs.follows = "nixpkgs";
    };

    spicetify-nix = {
      url = "github:gerg-l/spicetify-nix";
      inputs.nixpkgs.follows = "nixpkgs";
    };
  };

  outputs = {
    self,
    stable,
    nixpkgs,
    home-manager,
    ...
  } @ inputs: let
    user = "q";
    host = "NixOS";
    system = "x86_64-linux";
    pkgs = nixpkgs.legacyPackages.${system};
    stable = stable.legacyPackages.${system};
  in {
    nixosConfigurations.${host} = nixpkgs.lib.nixosSystem {
      system = system;
      modules = [
        ./hardware-configuration.nix
        ({
          config,
          pkgs,
          lib,
          ...
        }: {
*configuration.nix*
        })
        home-manager.nixosModules.home-manager
        {
          home-manager = {
            useGlobalPkgs = true;
            useUserPackages = true;
            users.${user} = {
              stable,
              config,
              pkgs,
              lib,
              ...
            }: {
              imports = [
                inputs.spicetify-nix.homeManagerModules.default
                inputs.hyprland.homeManagerModules.default
              ];
              home = {
                username = "${user}";
                homeDirectory = "/home/${user}";
                stateVersion = "24.05";
                sessionVariables = {
                  MOZ_ENABLE_WAYLAND = 1;
                  QT_QPA_PLATFORM = "wayland";
                };
                packages = with pkgs;
                  [
                    inputs.alejandra.defaultPackage.${system}
                    inputs.hypr-contrib.packages.${pkgs.system}.grimblast
                    (pkgs.lutris.override {
                      extraPkgs = pkgs: [
                        pkgs.wineWowPackages.stable
                        pkgs.winetricks
                      ];
                    })
                    #(pkgs.discord.override {
                    #  withOpenASAR = true;
                    #  withTTS = true;
                    #  withVencord = true;
                    #})
                    telegram-desktop
                    #kotatogram-desktop
                    pavucontrol
                    okular
                    vlc
                    pipes-rs
                    ani-cli
                    gtt
                    imv
                    ncdu
                    nitch
                    toipe
                    ttyper
                    unzip
                    cbonsai
                    cmatrix
                    sl
                    tty-clock
                    libreoffice
                    hexdump
                    eza
                    nix-tree
                    go
                    #viber
                    pulsemixer
                    vesktop
                    gitkraken
                    killall
                    libnotify
                    w3m
                    tiv
                    fbida
                    tor-browser
                    xorg.xev
                    fastfetch
                    neofetch
                    aichat
                    #inxi
                    rofi-wayland
                    tree
                    wpsoffice
                    zram-generator
                    nvtopPackages.nvidia
                    fd
                    xfce.thunar
                  ]
                  ++ (with stable; [
                    inxi
                  ]);
              };
            };
          };
        }
      ];
    };
  };
}
1 Like

you might need

   home-manager = {
      extraSpecialArgs = { inherit stable; };
      ...
   }

I added this:

        })
        home-manager.nixosModules.home-manager
        {
          home-manager = {
            extraSpecialArgs = {inherit stable;};
            useGlobalPkgs = true;
            useUserPackages = true;

and the error changed

yeah you cant have stable = stable.something, name it something else for e.g. stable = nixpkgs-stable.xxx and rename the flake name above as well to nixpkgs-stable and send the nixpkgs-stable in the arguments for outputs.

   nixpkgs-stable.url = "github:NixOS/nixpkgs/nixos-24.05";
   ...
   outputs = { self, nixpkgs-stable, ...}
   ...
   let
      stable = nixpkgs-stable.legacyPackages.${system};

Also you have one more issue, a misuse of with

you need to do (with pkgs; [ ]) like you did with stable below. So that pkgs scope is limited only to that array, as of now it extends to the ++ (with stable ..) part as well.

2 Likes

thank you so much!!!

and one more thing, the stable branch does not accept unfree packages, do you know how to fix it?

This instead of legacyPackages

      stable = import nixpkgs-stable {
        inherit system;
        config = {
          allowUnfree = true;
        };
      };
1 Like