Skip to content

Small tutorial on how to add remote nix projects to nix system, declaratively.

Notifications You must be signed in to change notification settings

jeslie0/nix-cow

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

nix-cow

This is a simple nix project to test declarative pulling from GitHub.

Adding a remote nix project to your system

To add this to your nix configuration, we first need to get the hash of the project. Run the following in a bash shell:

nix-prefetch-git --url https://github.com/jeslie0/nix-cow.git

You should get something similar to the following, but with different information.

| {               |                                                      |
| url             | https://github.com/jeslie0/nix-cow.git               |
| rev             | 8babdf1a33a34de5cd18c90e252eaca80c620bdd             |
| date            | 2021-12-03T14:16:55-05:00                            |
| path            | /nix/store/7whr8vaghjdmblz50rd1bxdfhc45dsdc-nix-cow  |
| sha256          | 0c5dgy3abmirpkzqnbpa9bxxy0gx40n0vxr2i2wkpf1nhkxc24b0 |
| fetchLFS        | false,                                               |
| fetchSubmodules | false,                                               |
| deepClone       | false,                                               |
| leaveDotGit     | false                                                |
| }               |                                                      |

We can read off the hash from the sha256 line. In you nix configuration file (or homemanager file) add the following to your installed programs list:

(import (fetchFromGitHub {
  owner = "jeslie0";
  repo = "nix-cow";
  rev = "8babdf1a33a34de5cd18c90e252eaca80c620bdd";
  sha256 = "0c5dgy3abmirpkzqnbpa9bxxy0gx40n0vxr2i2wkpf1nhkxc24b0";
}))

Then, reloading your configuration should add the repo to your system. You can test this by running the following:

cow

This project is just a shell script with cowsay as a runtime dependency. Note that Nix won’t install cowsay on your system, even though it is a dependency.

Adding a different commit

We don’t have to use the most recent commit of a remote project. We can specify the revision we would like for nix-prefetch-git to find out the correct sha256 hash. For example, we can take the initial commit of this project: (note that the rev can be found by clicking on the “rewind clock” button on GitHub)

nix-prefetch-git --url https://github.com/jeslie0/nix-cow.git --rev de73a93328bdcc7dc46c7051d6bf2f59c48e2bf9

This gives us the desired hash and we can use this in our configuration.

(import (fetchFromGitHub {
  owner = "jeslie0";
  repo = "nix-cow";
  rev = "de73a93328bdcc7dc46c7051d6bf2f59c48e2bf9";
  sha256 = "1qiw2xaajb8yw2rhdhddxx6pymf21mf5hbwclh7a0gi1wdf16ri3";
}))

Flakes

This project is also a nix flake! This makes it very easy to use. You can run the program without even downloading this repository!

nix run github:jeslie0/nix-cow

To add it to a nix flake system, add this flake to your inputs:

inputs.nix-cow.url = "github:jeslie0/nix-cow";

You can then include it in your configuration as:

environment.systemPackages = with pkgs;
  [ ...
    self.inputs.nix-cow.defaultPackage.${system}
    ...
  ];

About

Small tutorial on how to add remote nix projects to nix system, declaratively.

Topics

Resources

Stars

Watchers

Forks