Skip to content

Commit

Permalink
write-text: remove support for copy
Browse files Browse the repository at this point in the history
This is a huge anti‐declarative footgun; `copy` files cannot
distinguish if a previous version is managed by nix-darwin, so they
can’t check the hash, so they’re prone to destroying data, and
copied files are not deleted when they’re removed from the system
configuration, which led to a security bug. Nothing else in‐tree
was using this functionality, so let’s make sure it doesn’t
cause any more bugs.
  • Loading branch information
emilazy committed Jun 15, 2024
1 parent b833d4a commit 36a15e8
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 22 deletions.
8 changes: 0 additions & 8 deletions modules/lib/write-text.nix
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,6 @@ in
'';
};

copy = mkOption {
type = types.bool;
default = false;
description = ''
Whether this file should be copied instead of symlinking.
'';
};

knownSha256Hashes = mkOption {
internal = true;
type = types.listOf types.str;
Expand Down
19 changes: 5 additions & 14 deletions modules/system/etc.nix
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ let
};

etc = filter (f: f.enable) (attrValues config.environment.etc);
etcCopy = filter (f: f.copy) (attrValues config.environment.etc);

in

Expand All @@ -34,9 +33,10 @@ in
''
mkdir -p $out/etc
cd $out/etc
${concatMapStringsSep "\n" (attr: "mkdir -p $(dirname '${attr.target}')") etc}
${concatMapStringsSep "\n" (attr: "ln -s '${attr.source}' '${attr.target}'") etc}
${concatMapStringsSep "\n" (attr: "touch '${attr.target}'.copy") etcCopy}
${concatMapStringsSep "\n" (attr: ''
mkdir -p "$(dirname ${escapeShellArg attr.target})"
ln -s ${escapeShellArgs [ attr.source attr.target ]}
'') etc}
'';

system.activationScripts.etcChecks.text = ''
Expand All @@ -55,10 +55,6 @@ in
etcStaticFile=/etc/static/$subPath
etcFile=/etc/$subPath
if [[ -e $configFile.copy ]]; then
continue
fi
# We need to check files that exist and aren't already links to
# $etcStaticFile for known hashes.
if [[
Expand Down Expand Up @@ -109,11 +105,6 @@ in
mkdir -p "$etcDir"
fi
if [[ -e $etcStaticFile.copy ]]; then
cp "$etcStaticFile" "$etcFile"
continue
fi
if [[ -e $etcFile ]]; then
if [[ $(readlink -- "$etcFile") == "$etcStaticFile" ]]; then
continue
Expand All @@ -130,7 +121,7 @@ in
# Delete stale links into /etc/static.
if [[
$(readlink "$etcFile") == "$etcStaticFile"
$(readlink -- "$etcFile") == "$etcStaticFile"
&& ! -e $etcStaticFile
]]; then
rm "$etcFile"
Expand Down

0 comments on commit 36a15e8

Please sign in to comment.