To create a Nix flake that combines software from different versions of Nixpkgs, you can use multiple inputs in your flake: one for the unstable channel to get the latest version of VSCode, and another for an older Nixpkgs revision where gcc8 was the default compiler to obtain gcc8 and wxWidgets. Here's how you can do it:
First, identify the commit hash or Nixpkgs channel revision where gcc8 was the default compiler. For demonstration purposes, let’s assume the commit hash is example-commit-hash. You'll need to find the actual commit that corresponds to what you need.
Create a flake.nix file with the following content:
{
description = "Development environment with latest VSCode, gcc8, and wxWidgets";
inputs = {
nixpkgs-unstable.url = "nixpkgs/nixos-unstable";
nixpkgs-gcc8.url = "github:NixOS/nixpkgs/example-commit-hash"; # Replace with actual hash
flake-utils.url = "github:numtide/flake-utils";
};
outputs = { self, nixpkgs-unstable, nixpkgs-gcc8, flake-utils, ... }:
flake-utils.lib.eachDefaultSystem (system:
let
# Latest nixpkgs for unstable VSCode
pkgs-unstable = import nixpkgs-unstable {
inherit system;
};
# Older nixpkgs where gcc8 was the default compiler
pkgs-gcc8 = import nixpkgs-gcc8 {
inherit system;
};
in {
devShell = pkgs-gcc8.mkShell {
buildInputs = [
pkgs-unstable.vscode
pkgs-gcc8.gcc8
pkgs-gcc8.wxGTK30-gtk3 # Replace with the wxWidgets package name if different
];
shellHook = ''
export CC=${pkgs-gcc8.gcc8}/bin/gcc
export CXX=${pkgs-gcc8.gcc8}/bin/g++
'';
};
}
);
}
Here is what each part of the flake.nix does:
nixpkgs-unstable: The latest Nixpkgs from the nixos-unstable branch to get the fresh version of VSCode.
nixpkgs-gcc8: The Nixpkgs snapshot when gcc8 was the default, used for gcc8 and wxWidgets.
flake-utils: A utility flake used to simplify writing flakes that support multiple systems.
In this flake, I specify two different Nixpkgs snapshots as inputs. The development shell is created from the older Nixpkgs snapshot to ensure that the environment remains consistent with the use of gcc8. VSCode is then added from the unstable Nixpkgs in order to have a fresh version.
Please remember to replace example-commit-hash with the real commit hash from the Nixpkgs repository corresponding to the time when gcc8 was the default compiler. You might need to search through the Nixpkgs repository history to find the accurate hash.
To use this flake, do the following:
- Save the provided flake template into a
flake.nix file within your project directory.
- Use
nix develop to enter the development environment.
Keep in mind that mixing packages from different Nixpkgs revisions could lead to compatibility issues since libraries and other dependencies may have differing versions. Always review and test your environment thoroughly to ensure everything works as expected.