Skip to content

Commit

Permalink
nix: check /etc/nix/nix.custom.conf hash
Browse files Browse the repository at this point in the history
  • Loading branch information
emilazy committed Jan 15, 2025
1 parent ba9b317 commit d09ca21
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

# Written by https://github.com/DeterminateSystems/nix-installer.
# The contents below are based on options specified at installation time.

35 changes: 34 additions & 1 deletion modules/nix/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -823,8 +823,41 @@ in
]);
users.knownGroups = mkIf cfg.configureBuildUsers [ "nixbld" ];

# The Determinate Systems installer puts user‐specified settings in
# `/etc/nix/nix.custom.conf` since vX.YY.Z. Supplement the
# `/etc/nix/nix.conf` hash check so that we don’t accidentally
# clobber user configuration.
#
# TODO: Maybe this could use a more general file placement mechanism
# to express that we want it deleted and know only one hash?
system.activationScripts.etcChecks.text = mkAfter ''
nixCustomConfEmptySha256Hash=6787fade1cf934f82db554e78e1fc788705c2c5257fddf9b59bdd963ca6fec63
if [[ -e /etc/nix/nix.custom.conf ]]; then
nixCustomConfSha256Output=$(shasum -a 256 /etc/nix/nix.custom.conf)
nixCustomConfSha256Hash=''${nixCustomConfSha256Output%% *}
if [[ $nixCustomConfSha256Hash != "$nixCustomConfEmptySha256Hash" ]]; then
printf >&2 '\e[1;31merror: custom settings in /etc/nix/nix.custom.conf, aborting activation\e[0m\n'
# shellcheck disable=SC2016
printf >&2 'You will need to migrate these to nix-darwin `nix.*` settings if you\n'
printf >&2 'wish to keep them. Check the manual for the appropriate settings and\n'
printf >&2 'add them to your system configuration, then run:\n'
printf >&2 '\n'
printf >&2 ' $ sudo mv /etc/nix/nix.custom.conf{,.before-nix-darwin}\n'
printf >&2 '\n'
printf >&2 'and activate your system again.\n'
exit 2
fi
fi
'';

# Unrelated to use in NixOS module
system.activationScripts.nix-daemon.text = mkIf cfg.useDaemon ''
system.activationScripts.nix-daemon.text = ''
# Follow up on the `/etc/nix/nix.custom.conf` check.
# TODO: Use a more generalized file placement mechanism for this.
if [[ -e /etc/nix/nix.custom.conf ]]; then
mv /etc/nix/nix.custom.conf{,.before-nix-darwin}
fi
'' + optionalString cfg.useDaemon ''
if ! diff /etc/nix/nix.conf /run/current-system/etc/nix/nix.conf &> /dev/null || ! diff /etc/nix/machines /run/current-system/etc/nix/machines &> /dev/null; then
echo "reloading nix-daemon..." >&2
launchctl kill HUP system/org.nixos.nix-daemon
Expand Down

0 comments on commit d09ca21

Please sign in to comment.