[M7] lockfile: pin top-level nixpkgs_rev + flake_utils_rev

This commit is contained in:
2026-05-16 00:20:11 +00:00
parent 7c10ea2382
commit 43a7d1f09d
9 changed files with 101 additions and 34 deletions

View File

@@ -75,7 +75,7 @@ TEST_CASE("cmd_build generates files for a no-deps binary project",
auto flake_text = read_file(root / "build" / "flake.nix");
REQUIRE(flake_text.find("description = \"hello\";") != std::string::npos);
REQUIRE(flake_text.find("github:NixOS/nixpkgs/nixos-unstable") != std::string::npos);
REQUIRE(flake_text.find("github:NixOS/nixpkgs/") != std::string::npos);
}
TEST_CASE("cmd_build generates files for a library project", "[cli][build]") {

View File

@@ -77,7 +77,7 @@ TEST_CASE("flake_nix adds pkgs.pkg-config to nativeBuildInputs only when needed"
"[codegen][flake]") {
Manifest m{pkg("app"), {dep("sqlite", "*")}, {}};
DiscoveredLayout layout{};
Lockfile lock{1, {root_pkg("app", "0.1.0")}};
Lockfile lock{.version = 1, .packages = {root_pkg("app", "0.1.0")}};
std::vector<Recipe> recipes = {Recipe{
.nixpkgs_attr = "sqlite",
.find_package = "PkgConfig REQUIRED",
@@ -96,7 +96,7 @@ TEST_CASE("flake_nix omits pkgs.pkg-config when no recipe needs it",
"[codegen][flake]") {
Manifest m{pkg("hello"), {dep("fmt", "*")}, {}};
DiscoveredLayout layout{};
Lockfile lock{1, {root_pkg("hello", "0.1.0")}};
Lockfile lock{.version = 1, .packages = {root_pkg("hello", "0.1.0")}};
std::vector<Recipe> recipes = {recipe("fmt_10")};
GenerateInputs in{m, layout, lock, recipes, {}, "/tmp/hello"};
@@ -108,7 +108,7 @@ TEST_CASE("flake_nix always emits the shared nixos-unstable nixpkgs input",
"[codegen][flake]") {
Manifest m{pkg("hello"), {}, {}};
DiscoveredLayout layout{};
Lockfile lock{1, {root_pkg("hello", "0.1.0")}};
Lockfile lock{.version = 1, .packages = {root_pkg("hello", "0.1.0")}};
GenerateInputs in{m, layout, lock, {}, {}, "/tmp/hello"};
auto out = flake_nix(in);
@@ -122,7 +122,7 @@ TEST_CASE("flake_nix always emits the shared nixos-unstable nixpkgs input",
TEST_CASE("flake_nix emits a per-pinned-dep nixpkgs input", "[codegen][flake]") {
Manifest m{pkg("app"), {dep("fmt", "10.2.1")}, {}};
DiscoveredLayout layout{};
Lockfile lock{1, {
Lockfile lock{.version = 1, .packages = {
root_pkg("app", "0.1.0"),
dep_pkg("fmt", "10.2.1", "abc123def456"),
}};
@@ -146,7 +146,7 @@ TEST_CASE("flake_nix uses shared `pkgs` for unpinned deps",
"[codegen][flake]") {
Manifest m{pkg("app"), {dep("fmt", "*")}, {}};
DiscoveredLayout layout{};
Lockfile lock{1, {root_pkg("app", "0.1.0"), dep_pkg("fmt", "*", std::nullopt)}};
Lockfile lock{.version = 1, .packages = {root_pkg("app", "0.1.0"), dep_pkg("fmt", "*", std::nullopt)}};
std::vector<Recipe> recipes = {recipe("fmt_10")};
GenerateInputs in{m, layout, lock, recipes, {}, "/tmp/app"};
@@ -158,7 +158,7 @@ TEST_CASE("flake_nix uses shared `pkgs` for unpinned deps",
TEST_CASE("flake_nix mixes pinned and unpinned deps", "[codegen][flake]") {
Manifest m{pkg("app"), {dep("fmt", "10.2.1"), dep("zlib", "*")}, {}};
DiscoveredLayout layout{};
Lockfile lock{1, {
Lockfile lock{.version = 1, .packages = {
root_pkg("app", "0.1.0"),
dep_pkg("fmt", "10.2.1", "abc"),
dep_pkg("zlib", "*", std::nullopt),
@@ -175,7 +175,7 @@ TEST_CASE("flake_nix emits an empty buildInputs list when there are no deps",
"[codegen][flake]") {
Manifest m{pkg("hello"), {}, {}};
DiscoveredLayout layout{};
Lockfile lock{1, {root_pkg("hello", "0.1.0")}};
Lockfile lock{.version = 1, .packages = {root_pkg("hello", "0.1.0")}};
GenerateInputs in{m, layout, lock, {}, {}, "/tmp/hello"};
auto out = flake_nix(in);
@@ -188,7 +188,7 @@ TEST_CASE("flake_nix dedupes deps that share input + attr",
{dep("boost", "1.84.0"), dep("boost", "1.84.0")},
{}};
DiscoveredLayout layout{};
Lockfile lock{1, {
Lockfile lock{.version = 1, .packages = {
root_pkg("app", "0.1.0"),
dep_pkg("boost", "1.84.0", "rev42"),
}};
@@ -205,7 +205,7 @@ TEST_CASE("flake_nix dedupes deps that share input + attr",
TEST_CASE("flake_nix produces deterministic output", "[codegen][flake]") {
Manifest m{pkg("app"), {dep("fmt", "10.2.1"), dep("spdlog", "*")}, {}};
DiscoveredLayout layout{};
Lockfile lock{1, {
Lockfile lock{.version = 1, .packages = {
root_pkg("app", "0.1.0"),
dep_pkg("fmt", "10.2.1", "abc"),
dep_pkg("spdlog", "*", std::nullopt),
@@ -219,7 +219,7 @@ TEST_CASE("flake_nix produces deterministic output", "[codegen][flake]") {
TEST_CASE("flake_nix output ends with a newline", "[codegen][flake]") {
Manifest m{pkg("hello"), {}, {}};
DiscoveredLayout layout{};
Lockfile lock{1, {root_pkg("hello", "0.1.0")}};
Lockfile lock{.version = 1, .packages = {root_pkg("hello", "0.1.0")}};
GenerateInputs in{m, layout, lock, {}, {}, "/tmp/hello"};
auto out = flake_nix(in);
@@ -231,7 +231,7 @@ TEST_CASE("flake_nix sanitizes hyphens and dots in dep names",
"[codegen][flake]") {
Manifest m{pkg("app"), {dep("range-v3", "0.12.0")}, {}};
DiscoveredLayout layout{};
Lockfile lock{1, {
Lockfile lock{.version = 1, .packages = {
root_pkg("app", "0.1.0"),
dep_pkg("range-v3", "0.12.0", "rev123"),
}};

View File

@@ -54,14 +54,14 @@ auto round_trip(const Lockfile& l) -> Lockfile {
} // namespace
TEST_CASE("write round-trips a minimal lockfile", "[lockfile]") {
Lockfile l{1, {root_pkg("my-project", "0.1.0")}};
Lockfile l{.version = 1, .packages = {root_pkg("my-project", "0.1.0")}};
REQUIRE(round_trip(l) == l);
}
TEST_CASE("write round-trips a lockfile with deps", "[lockfile]") {
Lockfile l{
1,
{
.version = 1,
.packages = {
root_pkg("my-project", "0.1.0", {"fmt 10.2.1", "spdlog 1.13.0"}),
dep_pkg("fmt", "10.2.1", "fmt_10", "8a3f...c2d1"),
dep_pkg("spdlog", "1.13.0", "spdlog", "8a3f...c2d1"),
@@ -72,8 +72,8 @@ TEST_CASE("write round-trips a lockfile with deps", "[lockfile]") {
TEST_CASE("write round-trips lockfile recipe fields", "[lockfile]") {
Lockfile l{
1,
{
.version = 1,
.packages = {
LockfilePackage{
.name = "fmt",
.version = "10.2.1",
@@ -120,8 +120,8 @@ TEST_CASE("write round-trips lockfile recipe fields", "[lockfile]") {
TEST_CASE("Lockfile::nixpkgs_rev returns the shared rev", "[lockfile]") {
Lockfile l{
1,
{
.version = 1,
.packages = {
root_pkg("p", "0.1.0", {"fmt 10.2.1"}),
dep_pkg("fmt", "10.2.1", "fmt_10", "abc123"),
},
@@ -129,8 +129,19 @@ TEST_CASE("Lockfile::nixpkgs_rev returns the shared rev", "[lockfile]") {
REQUIRE(l.nixpkgs_rev() == "abc123");
}
TEST_CASE("write round-trips top-level nixpkgs_rev + flake_utils_rev pins",
"[lockfile]") {
Lockfile l{
.version = 1,
.nixpkgs_rev_pin = "549bd84d6279f9852cae6225e372cc67fb91a4c1",
.flake_utils_rev_pin = "11707dc2f618dd54ca8739b309ec4fc024de578b",
.packages = {root_pkg("p", "0.1.0")},
};
REQUIRE(round_trip(l) == l);
}
TEST_CASE("Lockfile::nixpkgs_rev is nullopt when no deps", "[lockfile]") {
Lockfile l{1, {root_pkg("p", "0.1.0")}};
Lockfile l{.version = 1, .packages = {root_pkg("p", "0.1.0")}};
REQUIRE_FALSE(l.nixpkgs_rev().has_value());
}