All Projects → siers → Nix Gitignore

siers / Nix Gitignore

Licence: unlicense
superseded / unmaintained

Labels

Projects that are alternatives of or similar to Nix Gitignore

Nix Flakes Installer
A temporary place to host Nix Flakes releases, until the NixOS project publishes official releases.
Stars: ✭ 34 (-39.29%)
Mutual labels:  nix
Base16 Zathura
base16 colors for zathura
Stars: ✭ 44 (-21.43%)
Mutual labels:  nix
Idempotent Desktop
🛸 NixOS, Xmonad, Neovim
Stars: ✭ 51 (-8.93%)
Mutual labels:  nix
Nix Query Tree Viewer
GTK viewer for the output of `nix-store --query --tree`
Stars: ✭ 36 (-35.71%)
Mutual labels:  nix
Dotfiles
💻 Public repo for my personal dotfiles
Stars: ✭ 43 (-23.21%)
Mutual labels:  nix
Rust Overlay
Pure and reproducible nix overlay for binary distributed rust toolchains
Stars: ✭ 46 (-17.86%)
Mutual labels:  nix
Nix Examples
Showcase of Nix usage for various technologies
Stars: ✭ 31 (-44.64%)
Mutual labels:  nix
Snabblab Nixos
NixOS configuration for the Snabb Lab
Stars: ✭ 53 (-5.36%)
Mutual labels:  nix
Rust Nightly Nix
A Nix expression for nightly Rust versions
Stars: ✭ 43 (-23.21%)
Mutual labels:  nix
Backerei
Automated reward payment & account management for Tezos bakers.
Stars: ✭ 51 (-8.93%)
Mutual labels:  nix
Nix Home
Nix home environment
Stars: ✭ 38 (-32.14%)
Mutual labels:  nix
Nix Rehash
Nix development utils that will blow up your mind
Stars: ✭ 41 (-26.79%)
Mutual labels:  nix
Workshops
Stars: ✭ 47 (-16.07%)
Mutual labels:  nix
Nixdroid
building aosp roms (e.g. LineageOS) with nix. because why not?
Stars: ✭ 34 (-39.29%)
Mutual labels:  nix
Microgram
ABANDONED
Stars: ✭ 52 (-7.14%)
Mutual labels:  nix
Nixlisp
Stars: ✭ 33 (-41.07%)
Mutual labels:  nix
Nixery
Container registry which transparently builds images using the Nix package manager
Stars: ✭ 1,023 (+1726.79%)
Mutual labels:  nix
Nix Hs Hello Windows
Cross compiling Hello World (haskell) to Windows using nix.
Stars: ✭ 55 (-1.79%)
Mutual labels:  nix
Neutron
🌠 Purely functional Apache Pulsar client for Scala built on top of Fs2
Stars: ✭ 53 (-5.36%)
Mutual labels:  nix
Nix Dotfiles
My personal nix and nixos configuration
Stars: ✭ 48 (-14.29%)
Mutual labels:  nix

head over to hercules-ci/gitignore

↑↑↑


nix-gitignore

(for nix 2.0 or higher)

This implements primitive a gitignore filter for builtins.filterSource via translation to regexes.

Motivation

If you want to deploy your code from the development directory, it would make sense to clean out the development/tmp/cache files before copying your project's source to the nix store. The set of development files you'll want to clean is likely the same one your gitignore patterns match, so this is why this is useful.

Example

This project has been included in nixpkgs since 2019.02.18. and it should land in the 19.03 release, so you can start using it like this:

with (import <nixpkgs> {});

let
  additionalIgnores = ''
    /this
    /that/**.html
  '';

  source = nix-gitignore.gitignoreSource additionalIgnores ./source;
in
  "use ${source} here"
Here's the `fetchFromGitHub` nix example if it's ever needed.

fetchFromGitHub example

Replace the rev and sha256 lines with the output of this command:

nix-prefetch-git https://github.com/siers/nix-gitignore 2> /dev/null | jq -r '"rev = \"\(.rev)\";\nsha256 = \"\(.sha256)\";"'

in this snippet:

with (import <nixpkgs> {});

let
  gitignore = callPackage (pkgs.fetchFromGitHub {
    owner = "siers";
    repo = "nix-gitignore";
    rev = "…";
    sha256 = "…";
  }) {};
in
  with gitignore;

let
  additionalIgnores = ''
    /this
    /that/**.html
  '';

  source = gitignoreSource additionalIgnores ./source;
in
  "use ${source} here"

Usage

The default.nix exports (among other things) four functions. Three of these are:

gitignoreSource [] ./source
    # Simplest version

gitignoreSource "supplemental-ignores\n" ./source
    # This one reads the ./source/.gitignore and concats the auxiliary ignores

gitignoreSourcePure "ignore-this\nignore-that\n" ./source
    # Use this string as gitignore, don't read ./source/.gitignore.

gitignoreSourcePure ["ignore-this\nignore-that\n" ~/.gitignore] ./source
    # It also accepts a list (of strings and paths) that will be concatenated
    # once the paths are turned to strings via readFile.

They're all derived from the Filter functions with the first filter argument hardcoded as (_: _: true):

gitignoreSourcePure = gitignoreFilterSourcePure (_: _: true);
gitignoreSource = gitignoreFilterSource (_: _: true);

The filter accepts the same arguments the filterSource function would pass to its filters. Thus fn: gitignoreFilterSourcePure fn "" is extensionally equivalent to filterSource. The file is blacklisted iff it's blacklisted by either your filter or the gitignoreFilter.

If you want to make your own filter from scratch, you may use

gitignoreFilter = ign: root: filterPattern (gitignoreToPatterns ign) root;

.gitignore files in subdirectories

If you wish to use a filter that would search for .gitignore files in subdirectories, just like git does by default, use this function.

gitignoreFilterRecursiveSource = filter: patterns: root:
gitignoreRecursiveSource = gitignoreFilterRecursiveSource (_: _: true);

Testing

I highly recommend taking a look at the test files test.nix and test.sh which show how closely the actual git implementation's being mimicked. If you find any deviances, please file an issue. Even though it probably works 99% of the time, the pattern [^b/]har-class-pathalogic is the only one found that doesn't work like in git.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].