Skip to content

switch-to-configuration-ng: /etc/os-release should not be required - #543312

Merged
jmbaur merged 1 commit into
NixOS:masterfrom
nh2:switch-to-configuration-ng-fixed-os-release
Jul 25, 2026
Merged

jmbaur merged 1 commit into
NixOS:masterfrom
nh2:switch-to-configuration-ng-fixed-os-release

Conversation

@nh2

@nh2 nh2 commented Jul 18, 2026 •

Copy link
Copy Markdown
Contributor

The comment

// This is a NixOS installation if it has /etc/NIXOS or a proper /etc/os-release.

said OR but the code implemented AND because it errored out if /etc/os-release did not exist.

This was a regression from the Perl-to-Rust rewrite.

See #308801 (review)

Things done

The comment

    // This is a NixOS installation if it has /etc/NIXOS or a proper /etc/os-release.

said OR but the code implemented AND because it errored out
if `/etc/os-release` did not exist.

This was a regression from the Perl-to-Rust rewrite.

See NixOS#308801 (review)

Assisted-by: Claude Opus 4.8 in Zoo Code, human comment cleanup
@nh2
nh2 requested a review from jmbaur July 18, 2026 20:22
@nh2 nh2 self-assigned this Jul 18, 2026
@nixpkgs-ci nixpkgs-ci Bot added 2.status: merge-bot eligible This PR can be merged by commenting "@NixOS/nixpkgs-merge-bot merge". 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux. 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. llm-assisted Contributions that include code generation with LLMs 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS labels Jul 18, 2026
@nh2

nh2 commented Jul 19, 2026

Copy link
Copy Markdown
Contributor Author

switch-to-configuration-ng.tests passes for me.

@jmbaur

jmbaur commented Jul 19, 2026

Copy link
Copy Markdown
Contributor

This doesn't appear to change the logic from AND to OR

@nh2

nh2 commented Jul 19, 2026

Copy link
Copy Markdown
Contributor Author

This doesn't appear to change the logic from AND to OR

It does. The code until now does

    let os_release = parse_os_release().context("Failed to parse os-release")?;

    // This is a NixOS installation if it has /etc/NIXOS or a proper /etc/os-release.
    if !Path::new("/etc/NIXOS").is_file()
        && !os_release
            .get("ID")
            .map(|id| distro_id_re.is_match(id))
            .unwrap_or_default()
    {
        eprintln!("This is not a NixOS installation!");
        die();
    }

    // continue here

The code parse_os_release()....? early-returned when /etc/os-release doesn't exist.

It implemented AND, not OR, because // continue here could only be reached when both /etc/NIXOS and /etc/os-release exist.

My PR changes that because with it, parse_os_release()....? no longer early-returns when /etc/os-release doesn't exist; as the added comment describes, it returns Ok(emptyMap) instead.


Thus, when /etc/NIXOS exists and /etc/os-release doesn't, the code becomes:

    let os_release = emptyMap;

    // This is a NixOS installation if it has /etc/NIXOS or a proper /etc/os-release.
    if false && whatever {
        die();
    }

    // continue here

thus // continue here is executed, implementing OR semantics (one of them existing is sufficient).

@jmbaur jmbaur closed this Jul 19, 2026
@jmbaur jmbaur reopened this Jul 19, 2026
@jmbaur

jmbaur commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

This doesn't appear to change the logic from AND to OR

It does. The code until now does

    let os_release = parse_os_release().context("Failed to parse os-release")?;

    // This is a NixOS installation if it has /etc/NIXOS or a proper /etc/os-release.
    if !Path::new("/etc/NIXOS").is_file()
        && !os_release
            .get("ID")
            .map(|id| distro_id_re.is_match(id))
            .unwrap_or_default()
    {
        eprintln!("This is not a NixOS installation!");
        die();
    }

    // continue here

The code parse_os_release()....? early-returned when /etc/os-release doesn't exist.

It implemented AND, not OR, because // continue here could only be reached when both /etc/NIXOS and /etc/os-release exist.

My PR changes that because with it, parse_os_release()....? no longer early-returns when /etc/os-release doesn't exist; as the added comment describes, it returns Ok(emptyMap) instead.

Thus, when /etc/NIXOS exists and /etc/os-release doesn't, the code becomes:

    let os_release = emptyMap;

    // This is a NixOS installation if it has /etc/NIXOS or a proper /etc/os-release.
    if false && whatever {
        die();
    }

    // continue here

thus // continue here is executed, implementing OR semantics (one of them existing is sufficient).

Gotcha, thanks! It appears this isn't about the boolean logic, just whether or not the error handling is tolerant of /etc/os-release being missing or not.

@jmbaur

jmbaur commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

nixpkgs-review result

Generated using nixpkgs-review.

Command: nixpkgs-review pr 543312
Commit: e022b86ee842b06284a8052be28fb99f434e201e


x86_64-linux

⏩ 1 package blacklisted:
  • tests.nixos-functions.nixos-test
✅ 1 package built:
  • switch-to-configuration-ng

@jmbaur
jmbaur enabled auto-merge July 20, 2026 00:39
@jmbaur jmbaur added the backport release-26.05 Backport PR automatically label Jul 20, 2026
@nixpkgs-ci nixpkgs-ci Bot added 10.rebuild-darwin: 1-10 This PR causes between 1 and 10 packages to rebuild on Darwin. 10.rebuild-darwin: 1 This PR causes 1 package to rebuild on Darwin. 12.approvals: 1 This PR was reviewed and approved by one person. 12.approved-by: package-maintainer This PR was reviewed and approved by a maintainer listed in any of the changed packages. and removed 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. labels Jul 20, 2026
@jmbaur
jmbaur added this pull request to the merge queue Jul 25, 2026
Merged via the queue into NixOS:master with commit ea4c601 Jul 25, 2026
77 of 79 checks passed
@nixpkgs-ci

nixpkgs-ci Bot commented Jul 25, 2026

Copy link
Copy Markdown
Contributor

Successfully created backport PR for release-26.05:

@github-actions github-actions Bot added the 8.has: port to stable This PR already has a backport to the stable release. label Jul 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

2.status: merge-bot eligible This PR can be merged by commenting "@NixOS/nixpkgs-merge-bot merge". 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 8.has: port to stable This PR already has a backport to the stable release. 10.rebuild-darwin: 1-10 This PR causes between 1 and 10 packages to rebuild on Darwin. 10.rebuild-darwin: 1 This PR causes 1 package to rebuild on Darwin. 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux. 12.approvals: 1 This PR was reviewed and approved by one person. 12.approved-by: package-maintainer This PR was reviewed and approved by a maintainer listed in any of the changed packages. backport release-26.05 Backport PR automatically llm-assisted Contributions that include code generation with LLMs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants