1

I am building a project using the nixOs package system. I have a remote git repo containing different config files. I want to access those files using nix, with out editing the remote repo.

The project would access the remote repo with a specific commit hash. Could anyone help me, thanks.

1 Answer 1

2

Here's a short derivation that reads a file from a remote git repo that contains no Nix configuration:

with (import <nixpkgs> { }); let repo = fetchFromGitHub { owner = "nix-community"; repo = "awesome-nix"; rev = "c4adba38dc2ec33aa0f692cc5fcb9677b123087c"; sha256 = "cF9sh3vrDwTh64ZkgyEuJKmmA4UhbnXw8x4cnBMeGHk="; }; in stdenv.mkDerivation { name = "count-repo-lines"; src = repo; buildPhase = '' mkdir $out wc -l ./README.md > linecount ''; installPhase = '' cp linecount $out/linecount ''; system = builtins.currentSystem; } 

If it were saved to a file named count-remote-lines.nix, then the nix-build command would put the output into a local folder named result:

$ nix-build ./count-remote-lines.nix ...various log messages... $ cat ./result/linecount 154 ./README.md 

Alternatively, to better troubleshoot the derivation's build process by stepping through it in an interactive shell, try:

$ nix-shell ./count-repo-lines.nix --pure $ unpackPhase unpacking source archive /nix/store/xaff1yqipbpazhp9jz22rjp7izbglzr5-source source root is source $ cd source $ ls CONTRIBUTING.md LICENSE README.md 

The remaining build commands are documented in man nix-shell, under Examples. Also in wiki pages such as this one.

1
  • 1
    Thank you it's working ! Commented Jan 20, 2021 at 0:23

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.