2023-01-18 セキュリティアップデートのためにgit 2.39.1をインストールしたい
#2023-01-18 #作業記録
背景
gitにCVEがでた
https://github.blog/2023-01-17-git-security-vulnerabilities-announced-2/
nixpkgsの反映を待つと時間がかかるためパッチをあててインストールしたい
nixpkgsへのPull Request
https://github.com/NixOS/nixpkgs/pull/211281
pkgs/applications/version-management/git/default.nix へのversionとハッシュ値を変更しているだけである
code: git.nix
let
version = "2.39.1";
svn = subversionClient.override { perlBindings = perlSupport; };
gitwebPerlLibs = with perlPackages; CGI HTMLParser CGIFast FCGI FCGIProcManager HTMLTagCloud ;
in
stdenv.mkDerivation (finalAttrs: {
pname = "git"
+ lib.optionalString svnSupport "-with-svn"
+ lib.optionalString (!svnSupport && !guiSupport && !sendEmailSupport && !withManual && !pythonSupport && !withpcre2) "-minimal";
inherit version;
src = fetchurl {
url = "https://www.kernel.org/pub/software/scm/git/git-${version}.tar.xz";
sha256 = "sha256-QKOKCEezDDcbNYc7OvzxI4hd1B6j7Lv1EO+pfzzlwWE=";
};
versionは外から受け付けずに pnameとsrcに付与される。この対応が少し手間になりそう。
srcとnameとpnameを変えてあげることができれば良さそう
対応案
git のderivationのversionとハッシュ値を変える
derivationの確認をする
code: キーの確認
builtins.attrNames (import <nixpkgs> {}).git
"NIX_HARDENING_ENABLE" "NIX_LDFLAGS" "__darwinAllowLocalNetworking" "__ignoreNulls" "__impureHostDeps" "__propagatedImpureHostDeps" "__propagatedSandboxProfile" "__sandboxProfile" "all" "args" "buildInputs" "builder" "cmakeFlags" "configureFlags" "depsBuildBuild" "depsBuildBuildPropagated" "depsBuildTarget" "depsBuildTargetPropagated" "depsHostHost" "depsHostHostPropagated" "depsTargetTarget" "depsTargetTargetPropagated" "disallowedReferences" "doCheck" "doInstallCheck" "doc" "drvAttrs" "drvPath" "enableParallelBuilding" "enableParallelChecking" "hardeningDisable" "inputDerivation" "installCheckFlags" "installCheckTarget" "installFlags" "makeFlags" "mesonFlags" "meta" "name" "nativeBuildInputs" "out" "outPath" "outputName" "outputs" "override" "overrideAttrs" "overrideDerivation" "passthru" "patches" "pname" "postBuild" "postInstall" "postPatch" "preBuild" "preInstall" "preInstallCheck" "propagatedBuildInputs" "propagatedNativeBuildInputs" "separateDebugInfo" "sha256" "shellPath" "src" "stdenv" "strictDeps" "stripDebugList" "system" "tests" "type" "userHook" "version"
{ inherit ((import <nixpkgs> {}).git) name pname version src;}
{ name = "git-2.39.0"; pname = "git"; version = "2.39.0"; src = «derivation /nix/store/l2bq34wb96pmfxhr59kgwpp5l7qw891j-git-2.39.0.tar.xz.drv»; version = "2.39.0"; } }
srcがdevrivationになっている
code: git-2.39.0.tar.xz.drvの確認
builtins.attrNames (import <nixpkgs> {}).git.src
"SSL_CERT_FILE" "__darwinAllowLocalNetworking" "__ignoreNulls" "__impureHostDeps" "__propagatedImpureHostDeps" "__propagatedSandboxProfile" "__sandboxProfile" "__structuredAttrs" "all" "args" "buildInputs" "builder" "cmakeFlags" "configureFlags" "curlOpts" "curlOptsList" "depsBuildBuild" "depsBuildBuildPropagated" "depsBuildTarget" "depsBuildTargetPropagated" "depsHostHost" "depsHostHostPropagated" "depsTargetTarget" "depsTargetTargetPropagated" "doCheck" "doInstallCheck" "downloadToTemp" "drvAttrs" "drvPath" "executable" "impureEnvVars" "inputDerivation" "mesonFlags" "meta" "mirrorsFile" "name" "nativeBuildInputs" "nixpkgsVersion" "out" "outPath" "outputHash" "outputHashAlgo" "outputHashMode" "outputName" "outputs" "overrideAttrs" "passthru" "patches" "postFetch" "postHook" "preferHashedMirrors" "preferLocalBuild" "propagatedBuildInputs" "propagatedNativeBuildInputs" "showURLs" "stdenv" "strictDeps" "system" "type" "url" "urls" "userHook"
(import <nixpkgs> {}).git.src.urls
[ "https://www.kernel.org/pub/software/scm/git/git-2.39.0.tar.xz" ]
fetchUrlを使ってderivationを作ってあげれば良さそうではある
必要な値を差し替えてみる
code: override.nix
{
packageOverrides = pkgs:
with pkgs;
let git_version = "2.39.1";
git_2_39_1 = git // {
version = git_version;
name = "git-${git_version}";
src = fetchurl {
url = "https://www.kernel.org/pub/software/scm/git/git-${git_version}.tar.xz";
sha256 = "sha256-QKOKCEezDDcbNYc7OvzxI4hd1B6j7Lv1EO+pfzzlwWE=";
};
};
in {
git = git_2_39_1;
};
}
code: repl.nix
let git = (import <nixpkgs> {}).git;
in { inherit (git) name pname version; urls = builtins.elemAt git.src.urls 0;}
{ name = "git-2.39.1"; pname = "git"; urls = "https://www.kernel.org/pub/software/scm/git/git-2.39.1.tar.xz"; version = "2.39.1"; }
期待した感じになっていそう。しかし、他のderivationのgitと競合してしまう。
overrideDerivationしてみるとどうなるだろう
code: config.nix
{
packageOverrides = pkgs:
with pkgs;
let git_2_39_1 = git.overrideDerivation (drv:
let version = "2.39.1";
in {
inherit version;
name = "git-${version}";
src = fetchurl {
url = "https://www.kernel.org/pub/software/scm/git/git-${version}.tar.xz";
sha256 = "sha256-QKOKCEezDDcbNYc7OvzxI4hd1B6j7Lv1EO+pfzzlwWE=";
};
});
in {
git = git_2_39_1;
};
}
だめだった。
code: error
error: files '/nix/store/j438mfagnyshw5l596l3lv106cid1ivq-git-2.39.1/bin/git-receive-pack' and '/nix/store/6bpk3d4vlhc5pjdxcifd49db0jc8rxql-home-manager-path/bin/git-receive-pack' have the same priority 5; use 'nix-env --set-flag priority NUMBER INSTALLED_PKGNAME' or type 'nix profile install --help' if using 'nix profile' to find out howto change the priority of one of the conflicting packages (0 being the highest priority)
home-manager-pathが原因なので消してみる nix-env --uninstall home-manager-path
nix-env -iA nixpkgs.git でインストールすることができた
code: shell
$ git -v
git version 2.39.1
関連
builtins.attrNames
builtins.elemAt
Inheriting attributes
builtins.fetchurl
nixpkgs.lib.makeOverridable