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

Fix some nixos-rebuild lints #147449

Merged
merged 3 commits into from
Nov 29, 2021
Merged

Conversation

l0b0
Copy link
Contributor

@l0b0 l0b0 commented Nov 26, 2021

Motivation for this change

Existing issues requesting ShellCheck compliance: #133088, #21166. Request from @Artturin.

Open questions

There's one warning-level issue still reported by ShellCheck:

In pkgs/os-specific/linux/nixos-rebuild/nixos-rebuild.sh line 93:
            mkdir -p -m 0755 "$(dirname "$profile")"
                     ^-- SC2174: When used with -p, -m only applies to the deepest directory.

The simplest "solution" would be to remove the -p, but I'm not sure whether I can assume that /nix/var/nix/profiles/system-profiles will always exist when running nixos-rebuild. The less simple solution would be to mkdir each of the ancestor directories in turn, but I'm not sure whether all of them should have mode 0755.

I'll take care of SSHOPTS in a separate PR, since it's a more risky change.

Things done
  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandbox = true set in nix.conf? (See Nix manual)
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • 21.11 Release Notes (or backporting 21.05 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
    • (Release notes changes) Ran nixos/doc/manual/md-to-db.sh to update generated release notes
  • Fits CONTRIBUTING.md.

@Artturin ^

@github-actions github-actions bot added the 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS label Nov 26, 2021
Copy link
Member

@SuperSandro2000 SuperSandro2000 left a comment

Choose a reason for hiding this comment

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

I am not sure if it is worth switching all [ to [[. Also I personally would drop all the optional quotes inside the [[ and would also chain multiple up.

Maybe we should add a style guide entry before changing those to make sure we are all on the same track.

@@ -89,7 +90,7 @@ while [ "$#" -gt 0 ]; do
fi
if [ "$1" != system ]; then
profile="/nix/var/nix/profiles/system-profiles/$1"
mkdir -p -m 0755 "$(dirname "$profile")"
mkdir -m 0755 "$(dirname "$profile")"
Copy link
Member

Choose a reason for hiding this comment

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

I am not sure if this path could be taken twice because if the directory would exist right now the command would error. Or is that the weird case in mkdir where -p is implied?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry, I didn't mean to push that change. I got rid of this locally but forgot to force push.

You're right, -p also doesn't fail if the directory already exists. We could easily fix that case, but I guess the original question of the intention re. ancestor directories still stands.

if [[ -z $flake ]]; then
pathToConfig="$(nixBuild '<nixpkgs/nixos>' --no-out-link -A system "${extraBuildFlags[@]}")"
else
pathToConfig="$(nixFlakeBuild "$flake#$flakeAttr.config.system.build.toplevel" "${extraBuildFlags[@]}" "${lockFlags[@]}")"
fi
copyToTarget "$pathToConfig"
targetHostCmd nix-env -p "$profile" --set "$pathToConfig"
elif [ "$action" = test -o "$action" = build -o "$action" = dry-build -o "$action" = dry-activate ]; then
elif [[ "$action" = test ]] || [[ "$action" = build ]] || [[ "$action" = dry-build ]] || [[ "$action" = dry-activate ]]; then
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
elif [[ "$action" = test ]] || [[ "$action" = build ]] || [[ "$action" = dry-build ]] || [[ "$action" = dry-activate ]]; then
elif [[ "$action" = test || "$action" = build || "$action" = dry-build || "$action" = dry-activate ]]; then

I think we should at least remove the optional ]] [[ in between. It makes the code shorter and for me personally way easier to understand. I would also be fine with keeping the -o to reduce the diff.

@ofborg ofborg bot added 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin 10.rebuild-linux: 1-10 labels Nov 26, 2021
@l0b0 l0b0 force-pushed the fix-nixos-rebuild-lints branch 2 times, most recently from 6bdb8c3 to d2c5732 Compare November 26, 2021 02:58
@ofborg ofborg bot added the ofborg-internal-error Ofborg encountered an error label Nov 26, 2021
@l0b0 l0b0 requested a review from SuperSandro2000 November 26, 2021 04:32
@Artturin
Copy link
Member

@ofborg eval

Copy link
Member

@Artturin Artturin left a comment

Choose a reason for hiding this comment

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

tested by checking out my system revision and applying this as a patch
git apply - <<< $(curl https://patch-diff.githubusercontent.com/raw/NixOS/nixpkgs/pull/147449.patch)

and rebuilding nix build ".#nixos-rebuild" && sudo ./result/bin/nixos-rebuild switch -I nixpkgs=$(pwd)

@Artturin
Copy link
Member

doesn't need to target staging

l0b0 added 3 commits November 29, 2021 10:56
The script already uses non-POSIX features like `[[` and `local`, so I
assume it's safe to assume it shouldn't be treated as POSIX `sh`.
@l0b0
Copy link
Contributor Author

l0b0 commented Nov 29, 2021

Is the auto-request for reviews intentional or caused by the momentary massive diff between this branch and the target branch when switching from NixOS:staging to NixOS:master? If so, I'm sorry. And is it even possible to change the target branch without causing a notification storm? I tried changing the target branch a couple of seconds after pushing the rebased branch, and I don't expect there's any way to atomically change the target branch while pushing.

@Artturin
Copy link
Member

Artturin commented Nov 29, 2021

reverse master and staging in this to go from staging to master

# finding the common merge base will avoid pinging all CODEOWNERs
common=$(git merge-base origin/master origin/staging)
git rebase --onto=$common HEAD~1 # or however many commits you want to pull
git push --force

then change the base branch in the github PR from master -> staging

instructions made by jonringer

@Artturin Artturin merged commit 82b9b42 into NixOS:master Nov 29, 2021
@cole-h cole-h removed the ofborg-internal-error Ofborg encountered an error label Nov 29, 2021
@l0b0 l0b0 deleted the fix-nixos-rebuild-lints branch November 29, 2021 20:27
@l0b0
Copy link
Contributor Author

l0b0 commented Nov 29, 2021

[…] instructions made by jonringer

Is this somewhere front and centre in the contribution docs? Seems really important.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin 10.rebuild-linux: 1-10
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants