copying claude's settings.json instead of symlinking

This commit is contained in:
Miguel Palhas
2026-03-25 15:14:32 +00:00
parent 9af55f9e16
commit be52931cbe
4 changed files with 95 additions and 2 deletions
+1 -1
View File
@@ -100,7 +100,7 @@
./home/${name}
];
extraSpecialArgs = {
inherit inputs outputs;
inherit inputs outputs self;
};
};
in
+90
View File
@@ -0,0 +1,90 @@
{
config,
lib,
pkgs,
self,
...
}:
let
cfg = config.home.mutableFiles;
repoPath = config.home.mutableFilesRepoPath;
flakePrefix = self.outPath;
fileEntries = lib.attrsToList cfg;
toRepoPath = storePath: repoPath + lib.removePrefix flakePrefix (toString storePath);
checkScript = lib.concatMapStringsSep "\n" (
{ name, value }:
let
target = "${config.home.homeDirectory}/${name}";
storePath = value.source;
originalPath = toRepoPath value.source;
in
''
if [ -f "${target}" ] && ! ${lib.getExe' pkgs.diffutils "diff"} -q "${storePath}" "${target}" > /dev/null 2>&1; then
echo ""
echo "!! mutable file changed: ${name}"
echo " To bring changes upstream:"
echo " cp ${target} ${originalPath}"
echo ""
${lib.getExe' pkgs.diffutils "diff"} -u "${storePath}" "${target}" || true
_mutable_changed=1
fi
''
) fileEntries;
copyScript = lib.concatMapStringsSep "\n" (
{ name, value }:
let
target = "${config.home.homeDirectory}/${name}";
source = value.source;
dirName = builtins.dirOf target;
in
''
mkdir -p "${dirName}"
cp -f "${source}" "${target}"
chmod ${if value.executable then "755" else "644"} "${target}"
''
) fileEntries;
in
{
options.home.mutableFilesRepoPath = lib.mkOption {
type = lib.types.str;
description = "Absolute path to the nixos-config repo on disk.";
};
options.home.mutableFiles = lib.mkOption {
type = lib.types.attrsOf (
lib.types.submodule {
options = {
source = lib.mkOption {
type = lib.types.path;
description = "Path to the source file.";
};
executable = lib.mkOption {
type = lib.types.bool;
default = false;
description = "Whether the file should be executable.";
};
};
}
);
default = { };
description = "Files to copy (not symlink) into the home directory, with change detection.";
};
config = lib.mkIf (cfg != { }) {
home.activation.mutableFiles = lib.hm.dag.entryAfter [ "writeBoundary" ] ''
_mutable_changed=0
${checkScript}
if [ "$_mutable_changed" -eq 1 ]; then
echo ""
echo "!! Aborting: mutable files have been modified outside of nix."
echo " Bring the changes upstream first, then re-run."
exit 1
fi
${copyScript}
'';
};
}
+1 -1
View File
@@ -54,6 +54,6 @@
source = ./statusline.sh;
executable = true;
};
home.file.".claude/settings.json".source = ./settings.json;
home.mutableFiles.".claude/settings.json".source = ./settings.json;
home.file.".claude/CLAUDE.md".source = ./CLAUDE.md;
}
+3
View File
@@ -6,6 +6,7 @@
}:
{
imports = [
../features/mutable-file.nix
./zsh.nix
./neovim
./rust.nix
@@ -23,6 +24,8 @@
./ssh.nix
];
home.mutableFilesRepoPath = "/home/naps62/projects/nixos-config";
programs = {
home-manager.enable = true;
};