Skip to content

nixos/etc: Replace make-etc.sh with nix and bash#131102

Merged
Mic92 merged 1 commit intoNixOS:masterfrom
helsinki-systems:feat/rework-etc-2
Jul 31, 2021
Merged

nixos/etc: Replace make-etc.sh with nix and bash#131102
Mic92 merged 1 commit intoNixOS:masterfrom
helsinki-systems:feat/rework-etc-2

Conversation

@dasJ
Copy link
Member

@dasJ dasJ commented Jul 22, 2021

Motivation for this change

Alternative implementation for #131035.

This change changes the data format from 5 arrays to generated bash code.
Also, strings in the code are properly quoted now.

Closes #130935
Closes #131035
Closes #108779
Closes #41241
Closes #41276

Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS linux)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests) → simple.nix
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • 21.11 Release Notes (or backporting 21.05 Relase 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
  • Fits CONTRIBUTING.md.

@dasJ dasJ mentioned this pull request Jul 22, 2021
11 tasks
@github-actions github-actions bot added 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 8.has: module (update) This PR changes an existing module in `nixos/` labels Jul 22, 2021
@dasJ dasJ requested review from ctheune and infinisil July 22, 2021 15:41
@dasJ dasJ force-pushed the feat/rework-etc-2 branch from 9a9abcb to d824b9c Compare July 22, 2021 15:43
@ofborg ofborg bot added 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux. labels Jul 22, 2021
Copy link
Member

Choose a reason for hiding this comment

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

target=${lib.escapeShellArg target}

@dasJ dasJ force-pushed the feat/rework-etc-2 branch 2 times, most recently from aceb8b0 to 87d2792 Compare July 22, 2021 19:57
Copy link
Contributor

@ctheune ctheune left a comment

Choose a reason for hiding this comment

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

So bash isn't my lingua france but I poked around a couple of edge cases I could think of and it seems fine. I saw the jq-based version talk about performance but I think this should be safe. Not sure whether escapeShellArgs is specifically problematic.

If you want I can try to come up with a test case for this to avoid future regression.

Copy link
Contributor

Choose a reason for hiding this comment

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

I had to think twice whether this is safe regarding whitespace/newlines in the src as well but it seems so:

$ mkdir asdfsda$'\n'asdf
$ mkdir asdfsda$'\n'asdf2
$ for x in asdfsda*; do echo ".$x"; done
.asdfsda
asdf
.asdfsda
asdf2

Copy link
Contributor

Choose a reason for hiding this comment

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

Just curious: do you have an editor with working fenced syntax highlighting for Nix?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, vim-nix with the PR that hasn't been merged yet

@andir
Copy link
Member

andir commented Jul 29, 2021

Excuse my question but from the commit message I can't quite follow:

The commit message says that you replace a shell script with Nix and a sh but how is that any different and why do we want this? Perhaps you can expand on that in the commit message documenting how this improves anything?

The main goal of this commit is to replace the rather fragile passing of
multiple arrays which could break in cases like NixOS#130935.
While I could have just added proper shell escaping to the variables
being passed, I opted for the more painful approach of replacing the
fragile and somewhat strange construct with the 5 bash lists. While
there are currently no more problems present with the current approach
(at least none that I know of), the new approach seems more solid and
might get around problems that could arise in the future stemming from
either the multiple-lists situation or from the absence of proper shell
quoting all over the script.
@dasJ
Copy link
Member Author

dasJ commented Jul 30, 2021

@andir like this?

@dasJ dasJ force-pushed the feat/rework-etc-2 branch from 87d2792 to eb7120d Compare July 30, 2021 19:37
@andir
Copy link
Member

andir commented Jul 30, 2021

@andir like this?

Yes, now it all makes sense without doing a multi-level history dive :)

@Mic92
Copy link
Member

Mic92 commented Jul 31, 2021

I tested this on some of my machines.

mkdir -p "$out/etc"
${concatMapStringsSep "\n" (etcEntry: escapeShellArgs [
"makeEtcEntry"
etcEntry.source
Copy link
Member

Choose a reason for hiding this comment

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

I just came across a case where this broke something.

Imagine source being a path such as ./my-local-file then this function will call toString on it leading to /home/andi/somewhere/my-local-file in the eval. This breaks setups that put version managed files into the store.

This manifests in the perl script that sets up our /etc/ to "warn" during runtime. Example hydra job: https://hydra.nixos.org/build/151772282/nixlog/20

Copy link
Member

Choose a reason for hiding this comment

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

This was fixed in #136474

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 8.has: module (update) This PR changes an existing module in `nixos/` 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Wrong characters in etc."xyz".source causes system crash / unbootable system Whitespace in environment.etc target crashes nixos

5 participants