Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make our Nix installation immune to macOS upgrades #672

Merged
merged 17 commits into from
Oct 16, 2023

Conversation

grahamc
Copy link
Member

@grahamc grahamc commented Oct 11, 2023

Description

This PR adds a global launch daemon on macOS which restores the shell hook after system upgrades, fixing the problem of Nix being "uninstalled" after each upgrade.

This is a rough pass to be improved. I haven't tested this exact implementation yet, but I tested the idea and it works. I'll be testing the implementation shortly.

Checklist
  • Formatted with cargo fmt
  • Built with nix build
  • Ran flake checks with nix flake check
  • Added or updated relevant tests (leave unchecked if not applicable)
  • Added or updated relevant documentation (leave unchecked if not applicable)
  • Linked to related issues (leave unchecked if not applicable)
Validating with install.determinate.systems

If a maintainer has added the upload to s3 label to this PR, it will become available for installation via install.determinate.systems:

curl --proto '=https' --tlsv1.2 -sSf -L https://install.determinate.systems/nix/pr/$PR_NUMBER | sh -s -- install

@grahamc grahamc changed the title Graham/ds 1293 make nix immune to macos upgrades Make our Nix installation immune to macOS upgrades Oct 11, 2023
@grahamc grahamc added the upload to s3 The labeled PR is allowed to upload its artifacts to S3 for easy testing label Oct 11, 2023
This reverts commit cccb8bc.

It starts too early, fails, and then aborts. When it fails,
launchd says the service failed to initialize and that the system
is read-only.
@pingiun
Copy link

pingiun commented Oct 12, 2023

I installed nix with this version of the installer, upgraded macOS to 14.0 and nix still works in my fish shell and also in my bash shell.

use clap::{ArgAction, Parser};

/**
Update the macOS startup files to make Nix usable after system upgrades.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm under the impression this can be used on non-Macs too? (I don't see it cfg'd off by target) If it works on Linux I'd like to make it available for every body! =D

default_value = "false",
global = true
)]
pub explain: bool,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see explain implemented below, can we remove it?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My thinking is we'd somehow smush this stuff here into the nice output / runner mechanism we see in uninstall. I didn't know how to do that -- or if it was reasonable. I left these in as a reminder to ask -- is that a reasonable / straightforward thing to do?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahhh like the plan display? We could do that!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This turns out to be a bit hard since the associated functions are on Plan which requires things like a planner which aren't relevant

@grahamc
Copy link
Member Author

grahamc commented Oct 16, 2023

I looked at what happens if we're in a hard loop of failing. It isn't so bad, but it isn't great. The default ThrottleInterval limits starting a service to once every ten seconds:

2023-10-16 11:43:55.745639 <Notice> service inactive: crash-test
2023-10-16 11:43:55.745645 <Notice> service state: not running
2023-10-16 11:43:55.745653 <Notice> Service only ran for 1 seconds. Pushing respawn out by 9 seconds.
2023-10-16 11:43:55.745735 <Notice> internal event: WILL_SPAWN, code = 0
2023-10-16 11:43:55.745740 <Notice> service state: spawn scheduled
2023-10-16 11:43:55.745743 <Notice> service throttled by 9 seconds

I don't see any way to limit the number of attempts.

@Hoverbear
Copy link
Contributor

Oh this needs to handle --no-modify-profile 🤔

src/planner/macos.rs Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
upload to s3 The labeled PR is allowed to upload its artifacts to S3 for easy testing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants