If I re-initiate git, the nix build fails

Hi, I have met Nix yesterday so I am very new of Nix.

I would like to fork a Github repository which uses Nix: GitHub - hmemcpy/milewski-ctfp-pdf: Bartosz Milewski's 'Category Theory for Programmers' unofficial PDF and LaTeX source

The steps that I did:

  1. Clone the repository.
    $ git clone https://github.com/hmemcpy/milewski-ctfp-pdf.git
    $ cd milewski-ctfp-pdf/
    
  2. Run nixos/nix:latest docker with volume mapping of cloned repository:
    $ docker run -it --rm -v ./:/workspace nixos/nix:latest
    
  3. Build following README.md of the repository
    $ nix --experimental-features 'nix-command flakes' flake show
    $ nix --experimental-features 'nix-command flakes' build .#ctfp-scala
    warning: Git tree '/workspace' is dirty
    warning: Ignoring setting 'auto-allocate-uids' because experimental feature 'auto-allocate-uids' is not enabled
    warning: Ignoring setting 'impure-env' because experimental feature 'configurable-impure-env' is not enabled
    
    Then it works fine.
  4. For forking the repository, I remove .git directory and re-initiate for my private git repository.
    # Out of the docker container, because the docker does not have git command 
    $ rm -rf .git
    $ git init
    $ git add .
    $ git commit -m "Ready to improve the document."
    
  5. Then I’ve tried to build it fails.
    $ nix --experimental-features 'nix-command flakes' build .#ctfp-scala
    
    The error logs are as following:
    warning: Ignoring setting 'auto-allocate-uids' because experimental feature 'auto-allocate-uids' is not enabled
    warning: Ignoring setting 'impure-env' because experimental feature 'configurable-impure-env' is not enabled
    error: builder for '/nix/store/5fvh085zdfkgq5b9zkx9b5pf1r43i4yc-ctfp-print-scala.drv' failed with exit code 12;
       last 10 log lines:
       > Latexmk: Missing input file 'fig/icons/cc.pdf' (or dependence on it) from following:
       >   LaTeX Warning: File `fig/icons/cc.pdf' not found on input line 48.
       > Latexmk: Log file says output to 'ctfp.xdv'
       > Latexmk: Errors, so I did not complete making targets
       > Collected error summary (may duplicate other messages):
       >   xelatex: Command for 'xelatex' gave return code 1
       >       Refer to 'ctfp.log' and/or above output for details
       >
       > Latexmk: If appropriate, the -f option can be used to get latexmk
       >   to try to force complete processing.
       For full logs, run 'nix log /nix/store/5fvh085zdfkgq5b9zkx9b5pf1r43i4yc-ctfp-print-scala.drv'.
    
  6. If I remove the .git folder, then it works fine.
    $ rm -rf .git
    $ nix --experimental-features 'nix-command flakes' build .#ctfp-scala
    warning: Git tree '/workspace' is dirty
    warning: Ignoring setting 'auto-allocate-uids' because experimental feature 'auto-allocate-uids' is not enabled
    warning: Ignoring setting 'impure-env' because experimental feature 'configurable-impure-env' is not enabled
    

I did the above steps on Mac Pro M2.

Would anybody show me the workaround?

Thank you.

Welcome to the nix world! So basically nix flake tries to maximize purity and reproducibility. So if you have a git repository, nix flake will only consider files in the git repository: this way, if it works locally, it will work once you push the folder online.

Here you can see that it complains Missing input file 'fig/icons/cc.pdf': this means that this file is not in the git repository. This makes sense since *.pdf is present in the .gitignore.

Solution: git add -f fig/icons/cc.pdf (and similarly for all files you want to keep with you) If you just cloned the repo and want to include all files, I guess you can just do git add -f ..

It works! Thank you!