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

{ids,checks}: update for new builder UID/GID values #1069

Merged
merged 6 commits into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 26 additions & 13 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,21 @@ on:
push:

env:
CURRENT_STABLE_CHANNEL: nixpkgs-23.11-darwin
CURRENT_STABLE_CHANNEL: nixpkgs-24.05-darwin
Copy link
Collaborator

Choose a reason for hiding this comment

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

The manual should be updated to 24.05 as well

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It already was, I think.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ah, I thought you meant the README. I can handle this but would prefer to do it in a separate PR given the urgency of this one.


jobs:
test-stable:
runs-on: macos-12
timeout-minutes: 30
steps:
- uses: actions/checkout@v3
# We use the Determinate Systems installer for 2.18 because the
# Sequoia UID/GID changes have not yet been backported to the
# official installer for that version.
- name: Install nix corresponding to latest stable channel
uses: cachix/install-nix-action@v23
uses: DeterminateSystems/nix-installer-action@main
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
uses: DeterminateSystems/nix-installer-action@main
uses: DeterminateSystems/nix-installer-action@v14

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

They recommend deploying the action directly from main in their documentation. I can adjust this if you think it's important, though I expect we're only talking a matter of days before a fixed 2.18 installer we can use is released and I'm not at a computer right now so it'll have to wait until tomorrow.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

FWIW the action downloads an unversioned installer anyway so there's no meaningful pinning to be done here.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm fine with these changes being put in another PR, I think we will be able to pin both the nix-installer binary used and the Nix version installed using source-url and nix-package-url, the goal for me is that we have both installers being tested in the CI eventually

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The upstream installer only supports installing one version of Nix, AFAIK. Again this is just a temporary hack for a few days to ensure that we can test 2.18 at all. If we tried to use the upstream installer we could not activate the system. This was the only way I could make the tests not go red because of this PR.

with:
install_url: https://releases.nixos.org/nix/nix-2.13.6/install
nix-package-url: https://releases.nixos.org/nix/nix-2.18.5/nix-2.18.5-x86_64-darwin.tar.xz
Comment on lines 18 to +21
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think it would be better to have a job for each installer rather than replacing the installer in this job

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We have no choice until the Nix team release a 2.18 with the fix, per the comment. This is just a hack taking advantage of the fact that the DetSys installer already deployed the fix and can install multiple Nix versions.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Currently we're still running the tests on macOS 12, so adding a second job seems fine to me, even if the Nix installer doesn't support the Sequoia UID migration yet

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The test will fail because this PR means it will print the message informing that the migration script has to be run and error out. Which is the correct behaviour to ensure that users are prepared for the Sequoia update, but doesn't test what we want.

Note that the upgrade breaks Nix entirely if no migration was done and the user will not even be able to activate nix-darwin to see the message. That's why it's urgent that people are informed and run the migration script before upgrading to Sequoia.

Copy link
Collaborator

Choose a reason for hiding this comment

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

How about in a different job running the official Nix installer then the migration script in CI and then try to do installation again? If this is too much extra work, we can leave it out

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That could work, but it seemed more fiddly than just changing a few lines until the patched installer was out. If you'd prefer that I can try to implement it tomorrow, but I'll be busy for most of the day and I'm worried about how many users we'll be able to get this change in front of before Sequoia drops. I lean towards iterating on non-essential things after merge.

- run: nix-build ./release.nix -I nixpkgs=channel:${{ env.CURRENT_STABLE_CHANNEL }} -I darwin=. -A tests
- run: nix-build ./release.nix -I nixpkgs=channel:${{ env.CURRENT_STABLE_CHANNEL }} -I darwin=. -A manpages
- run: nix-build ./release.nix -I nixpkgs=channel:${{ env.CURRENT_STABLE_CHANNEL }} -I darwin=. -A examples.simple
Expand All @@ -26,7 +29,9 @@ jobs:
steps:
- uses: actions/checkout@v3
- name: Install nix from current unstable channel
uses: cachix/install-nix-action@v23
uses: cachix/install-nix-action@v27
with:
install_url: https://releases.nixos.org/nix/nix-2.24.6/install
- run: nix-build ./release.nix -I nixpkgs=channel:nixpkgs-unstable -I darwin=. -A tests
- run: nix-build ./release.nix -I nixpkgs=channel:nixpkgs-unstable -I darwin=. -A manpages
- run: nix-build ./release.nix -I nixpkgs=channel:nixpkgs-unstable -I darwin=. -A examples.simple
Expand All @@ -36,18 +41,20 @@ jobs:
timeout-minutes: 30
steps:
- uses: actions/checkout@v3
# We use the Determinate Systems installer for 2.18 because the
# Sequoia UID/GID changes have not yet been backported to the
# official installer for that version.
- name: Install nix corresponding to latest stable channel
uses: cachix/install-nix-action@v23
uses: DeterminateSystems/nix-installer-action@main
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
uses: DeterminateSystems/nix-installer-action@main
uses: DeterminateSystems/nix-installer-action@v14

with:
install_url: https://releases.nixos.org/nix/nix-2.13.6/install
nix_path: nixpkgs=channel:${{ env.CURRENT_STABLE_CHANNEL }}
nix-package-url: https://releases.nixos.org/nix/nix-2.18.5/nix-2.18.5-x86_64-darwin.tar.xz
- name: Install ${{ env.CURRENT_STABLE_CHANNEL }} channel
run: |
nix-channel --add https://nixos.org/channels/${{ env.CURRENT_STABLE_CHANNEL }} nixpkgs
nix-channel --update
- name: Install nix-darwin and test
run: |
export NIX_PATH=$HOME/.nix-defexpr/channels
export NIX_PATH=nixpkgs=channel:${{ env.CURRENT_STABLE_CHANNEL }}

# We run nix-darwin twice to test that it can create darwin-configuration correctly for us
# but we expect it to fail setting up /etc/nix/nix.conf
Expand Down Expand Up @@ -82,8 +89,9 @@ jobs:
steps:
- uses: actions/checkout@v3
- name: Install nix from current unstable channel
uses: cachix/install-nix-action@v23
uses: cachix/install-nix-action@v27
with:
install_url: https://releases.nixos.org/nix/nix-2.24.6/install
nix_path: nixpkgs=channel:nixpkgs-unstable
- name: Install nixpkgs-unstable channel
run: |
Expand Down Expand Up @@ -125,10 +133,13 @@ jobs:
timeout-minutes: 30
steps:
- uses: actions/checkout@v3
- name: Install nix version corresponding to latest stable channel
uses: cachix/install-nix-action@v23
# We use the Determinate Systems installer for 2.18 because the
# Sequoia UID/GID changes have not yet been backported to the
# official installer for that version.
- name: Install nix corresponding to latest stable channel
uses: DeterminateSystems/nix-installer-action@main
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
uses: DeterminateSystems/nix-installer-action@main
uses: DeterminateSystems/nix-installer-action@v14

with:
install_url: https://releases.nixos.org/nix/nix-2.13.6/install
nix-package-url: https://releases.nixos.org/nix/nix-2.18.5/nix-2.18.5-x86_64-darwin.tar.xz
- name: Install nix-darwin
run: |
mkdir -p ~/.config/nix-darwin
Expand Down Expand Up @@ -209,7 +220,9 @@ jobs:
steps:
- uses: actions/checkout@v3
- name: Install nix from current unstable channel
uses: cachix/install-nix-action@v23
uses: cachix/install-nix-action@v27
with:
install_url: https://releases.nixos.org/nix/nix-2.24.6/install
- name: Install nix-darwin
run: |
mkdir -p ~/.config/nix-darwin
Expand Down
14 changes: 14 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
2024-09-10
- The default Nix build user group ID is now set to 350 when
`system.stateVersion` ≥ 5, to reflect the default for new Nix
installations. This only affects installations that enable
`nix.configureBuildUsers`, and any divergence will be detected on
system activation. To use `nix.configureBuildUsers` with a higher
`system.stateVersion` on installations using the old group ID, set:

ids.gids.nixbld = 30000;

We do not recommend trying to change the group ID with macOS user
management tools without a complete uninstallation and reinstallation
of Nix.

2024-06-15
- SECURITY NOTICE: The previous implementation of the
`users.users.<name>.openssh.authorizedKeys.*` options would not delete
Expand Down
2 changes: 1 addition & 1 deletion modules/examples/flake/flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

# Used for backwards compatibility, please read the changelog before changing.
# $ darwin-rebuild changelog
system.stateVersion = 4;
system.stateVersion = 5;

# The platform the configuration will be used on.
nixpkgs.hostPlatform = "x86_64-darwin";
Expand Down
2 changes: 1 addition & 1 deletion modules/examples/ofborg.nix
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ with lib;

# Used for backwards compatibility, please read the changelog before changing.
# $ darwin-rebuild changelog
system.stateVersion = 4;
system.stateVersion = 5;
}
2 changes: 1 addition & 1 deletion modules/examples/simple.nix
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@

# Used for backwards compatibility, please read the changelog before changing.
# $ darwin-rebuild changelog
system.stateVersion = 4;
system.stateVersion = 5;
}
7 changes: 3 additions & 4 deletions modules/misc/ids.nix
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# to change uids/gids on service start, in example a service with a lot of
# files.

{ lib, ... }:
{ lib, config, ... }:

let
inherit (lib) types;
Expand All @@ -34,15 +34,14 @@ in

};


config = {

ids.uids = {
nixbld = 300;
nixbld = lib.mkDefault 350;
};

ids.gids = {
nixbld = 30000;
nixbld = lib.mkDefault (if config.system.stateVersion < 5 then 30000 else 350);
};

};
Expand Down
77 changes: 73 additions & 4 deletions modules/system/checks.nix
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,52 @@ let

oldBuildUsers = ''
if dscl . -list /Users | grep -q '^nixbld'; then
echo "warning: Detected old style nixbld users" >&2
echo "error: Detected old style nixbld users, aborting activation" >&2
echo "These can cause migration problems when upgrading to certain macOS versions" >&2
echo "You can enable the following option to migrate to new style nixbld users" >&2
echo >&2
echo " nix.configureBuildUsers = true;" >&2
echo >&2
echo "or disable this check with" >&2
echo >&2
echo " system.checks.verifyBuildUsers = false;" >&2
echo >&2
exit 2
fi
'';

preSequoiaBuildUsers = ''
${lib.optionalString config.nix.configureBuildUsers ''
# Don’t complain when we’re about to migrate old‐style build users…
if ! dscl . -list /Users | grep -q '^nixbld'; then
''}
firstBuildUserID=$(dscl . -read /Users/_nixbld1 UniqueID | awk '{print $2}')
if [[ $firstBuildUserID != ${toString (config.ids.uids.nixbld + 1)} ]]; then
printf >&2 '\e[1;31merror: Build users have unexpected UIDs, aborting activation\e[0m\n'
printf >&2 'The default Nix build user ID range has been adjusted for\n'
printf >&2 'compatibility with macOS Sequoia 15. Your _nixbld1 user currently has\n'
printf >&2 'UID %d rather than the new default of 351.\n' "$firstBuildUserID"
printf >&2 '\n'
printf >&2 'You can automatically migrate your users using the following script\n'
printf >&2 'from the Nix repository:\n'
printf >&2 '\n'
printf >&2 ' https://github.com/NixOS/nix/raw/master/scripts/sequoia-nixbld-user-migration.sh\n'
printf >&2 '\n'
printf >&2 'This should work even if you installed Nix with the Determinate\n'
printf >&2 'Systems installer or are using Lix. If you are comfortable using the\n'
printf >&2 'script without review, you can run:\n'
printf >&2 '\n'
printf >&2 " curl --proto '=https' --tlsv1.2 -sSf -L https://github.com/NixOS/nix/raw/master/scripts/sequoia-nixbld-user-migration.sh | bash -\n"
printf >&2 '\n'
printf >&2 'If you have no intention of upgrading to macOS Sequoia 15, or already\n'
printf >&2 'have a custom UID range that you know is compatible with Sequoia, you\n'
printf >&2 'can disable this check by setting:\n'
printf >&2 '\n'
printf >&2 ' ids.uids.nixbld = %d;\n' "$((firstBuildUserID - 1))"
printf >&2 '\n'
exit 2
fi
${lib.optionalString config.nix.configureBuildUsers "fi"}
'';

buildUsers = ''
Expand All @@ -70,6 +109,32 @@ let
fi
'';

buildGroupID = ''
buildGroupID=$(dscl . -read /Groups/nixbld PrimaryGroupID | awk '{print $2}')
expectedBuildGroupID=${toString config.ids.gids.nixbld}
if [[ $buildGroupID != $expectedBuildGroupID ]]; then
printf >&2 '\e[1;31merror: Build user group has mismatching GID, aborting activation\e[0m\n'
printf >&2 'The default Nix build user group ID was changed from 30000 to 350.\n'
printf >&2 'You are currently managing Nix build users with nix-darwin, but your\n'
printf >&2 'nixbld group has GID %d, whereas we expected %d.\n' \
"$buildGroupID" "$expectedBuildGroupID"
printf >&2 '\n'
printf >&2 'Possible causes include setting up a new Nix installation with an\n'
printf >&2 'existing nix-darwin configuration, setting up a new nix-darwin\n'
printf >&2 'installation with an existing Nix installation, or manually increasing\n'
printf >&2 'your `system.stateVersion` setting.\n'
printf >&2 '\n'
printf >&2 'You can set the configured group ID to match the actual value:\n'
printf >&2 '\n'
printf >&2 ' ids.gids.nixbld = %d;\n' "$buildGroupID"
printf >&2 '\n'
printf >&2 'We do not recommend trying to change the group ID with macOS user\n'
printf >&2 'management tools without a complete uninstallation and reinstallation\n'
printf >&2 'of Nix.\n'
exit 2
fi
'';

singleUser = ''
if grep -q 'build-users-group =' /etc/nix/nix.conf; then
echo "error: The daemon is not enabled but this is a multi-user install, aborting activation" >&2
Expand Down Expand Up @@ -242,7 +307,9 @@ in

system.checks.verifyBuildUsers = mkOption {
type = types.bool;
default = !(config.nix.settings.auto-allocate-uids or false);
default =
(config.nix.useDaemon && !(config.nix.settings.auto-allocate-uids or false))
|| config.nix.configureBuildUsers;
description = "Whether to run the Nix build users validation checks.";
};

Expand All @@ -258,8 +325,10 @@ in
system.checks.text = mkMerge [
darwinChanges
runLink
oldBuildUsers
(mkIf (config.nix.useDaemon && cfg.verifyBuildUsers) buildUsers)
(mkIf (cfg.verifyBuildUsers && !config.nix.configureBuildUsers) oldBuildUsers)
(mkIf cfg.verifyBuildUsers buildUsers)
(mkIf cfg.verifyBuildUsers preSequoiaBuildUsers)
(mkIf config.nix.configureBuildUsers buildGroupID)
(mkIf (!config.nix.useDaemon) singleUser)
nixStore
(mkIf (config.nix.gc.automatic && config.nix.gc.user == null) nixGarbageCollector)
Expand Down
2 changes: 1 addition & 1 deletion modules/system/version.nix
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ in
options = {
system.stateVersion = mkOption {
type = types.int;
default = 4;
default = 5;
description = ''
Every once in a while, a new NixOS release may change
configuration defaults in a way incompatible with stateful
Expand Down
Loading