For a system I am setting up, we need to download and extract some ZIPs to a user’s home directory. I have the following <username>.nix
file that supposedly does that:
{lib, pkgs, ...}:
let
toolsVersion = "2.5.16";
zipFiles = [
{
name = "tool1-${toolsVersion}.zip";
sha256 = "...";
extractTo = "tools/tool1-${toolsVersion}";
}
{
name = "tool2-${toolsVersion}.zip";
sha256 = "...";
extractTo = "tools/tool2-${toolsVersion}";
}
];
generateFiles = zip: {
"Downloads/${zip.name}".source = builtins.fetchurl {
url = "https://github.com/.../download/v${toolsVersion}/${zip.name}";
sha256 = zip.sha256;
};
};
filesList = map generateFiles zipFiles;
files = lib.mkMerge filesList;
extractZip = zip: ''
mkdir -p ~/${zip.extractTo}
${pkgs.unzip}/bin/unzip -o ~/Downloads/${zip.name} -d ${zip.extractTo}
'';
in {
home.username = "<username>";
home.homeDirectory = "/home/<username>";
home.stateVersion = "23.11";
programs.home-manager.enable = true;
home.file = files;
home.packages = with pkgs; [
unzip
];
home.activation.extractZips = lib.hm.dag.entryAfter ["writeBoundary"] ''
${lib.concatStringsSep "\n" (map extractZip zipFiles)}
'';
}
However, this fails as, during startup, the home-manager service crashes with the error saying unzip cannot find the files.
I have ran the configuration without the step of unzipping the files, and then the download succeeds and the files appear in the correct folders. Now, however, my downloads folder is empty.
Am I missing something? How do I go about deploying ZIP files in a home directory?