From 1cdb8abf301f5c5ac99849d3754d1477b5d2b3e5 Mon Sep 17 00:00:00 2001 From: Robert Helgesson Date: Sun, 3 Feb 2019 23:54:29 +0100 Subject: [PATCH] git: add basic support for LFS Fixes #542 --- modules/programs/git.nix | 33 ++++++++++++++++++++++++ tests/modules/programs/git-expected.conf | 6 +++++ tests/modules/programs/git.nix | 1 + 3 files changed, 40 insertions(+) diff --git a/modules/programs/git.nix b/modules/programs/git.nix index 001d02b2..1abf5628 100644 --- a/modules/programs/git.nix +++ b/modules/programs/git.nix @@ -133,6 +133,20 @@ in ''; description = "List of configuration files to include."; }; + + lfs = { + enable = mkEnableOption "Git Large File Storage"; + + skipSmudge = mkOption { + type = types.bool; + default = false; + description = '' + Skip automatic downloading of objects on clone or pull. + This requires a manual git lfs pull + every time a new commit is checked out on your repository. + ''; + }; + }; }; }; @@ -204,6 +218,25 @@ in '') cfg.includes); }) + + (mkIf cfg.lfs.enable { + home.packages = [ pkgs.git-lfs ]; + + programs.git.iniContent."filter \"lfs\"" = + let + skipArg = optional cfg.lfs.skipSmudge "--skip"; + in + { + clean = "git-lfs clean -- %f"; + process = concatStringsSep " " ( + [ "git-lfs" "filter-process" ] ++ skipArg + ); + required = true; + smudge = concatStringsSep " " ( + [ "git-lfs" "smudge" ] ++ skipArg ++ [ "--" "%f" ] + ); + }; + }) ] ); } diff --git a/tests/modules/programs/git-expected.conf b/tests/modules/programs/git-expected.conf index 2b0f3caf..020fa8f0 100644 --- a/tests/modules/programs/git-expected.conf +++ b/tests/modules/programs/git-expected.conf @@ -10,6 +10,12 @@ boolean=true integer=38 name=value +[filter "lfs"] +clean=git-lfs clean -- %f +process=git-lfs filter-process +required=true +smudge=git-lfs smudge -- %f + [gpg] program=path-to-gpg diff --git a/tests/modules/programs/git.nix b/tests/modules/programs/git.nix index f642bede..be393d47 100644 --- a/tests/modules/programs/git.nix +++ b/tests/modules/programs/git.nix @@ -31,6 +31,7 @@ with lib; }; userEmail = "user@example.org"; userName = "John Doe"; + lfs.enable = true; } {