All Projects → hercules-ci → gitignore.nix

hercules-ci / gitignore.nix

Licence: Unlicense license
Nix functions for filtering local git sources

Programming Languages

Nix
1067 projects

Projects that are alternatives of or similar to gitignore.nix

nix bsd mac inventory
Collect Inventory data from *Nix, BSD and mac OS and upload to Device42
Stars: ✭ 17 (-90.29%)
Mutual labels:  nix
nix-install-vendor-gl
Ensure that a system-compatible OpenGL driver is available for `nix-shell`-encapsulated programs.
Stars: ✭ 22 (-87.43%)
Mutual labels:  nix
nix-articles
Some articles about getting started with Nix programming & configuration
Stars: ✭ 134 (-23.43%)
Mutual labels:  nix
Git-for-bio-scientists
Presentation about digital lab journalling with Git
Stars: ✭ 30 (-82.86%)
Mutual labels:  gitignore
buildkit-nix
Nix derivations as Dockerfiles (`docker build -f default.nix .`)
Stars: ✭ 99 (-43.43%)
Mutual labels:  nix
todomvc-nix
Example on how to nixify a project [maintainer=@Rizary]
Stars: ✭ 138 (-21.14%)
Mutual labels:  nix
yarn-plugin-nixify
Yarn v3 plugin to help with Nix packaging
Stars: ✭ 41 (-76.57%)
Mutual labels:  nix
GIG
[Unmaintained] A cli 💻 tool to generate gitignore files for your projects. Written in python 🐍
Stars: ✭ 16 (-90.86%)
Mutual labels:  gitignore
nixpkgs-pytools
Tools for removing the tedious nature of creating nixpkgs derivations [maintainer=@costrouc]
Stars: ✭ 36 (-79.43%)
Mutual labels:  nix
dotfiles-nix
Configuration files for my NixOS machine, declared by home-manager
Stars: ✭ 137 (-21.71%)
Mutual labels:  nix
release-services
Mozilla Release Engineering Services
Stars: ✭ 49 (-72%)
Mutual labels:  nix
crane
A Nix library for building cargo projects. Never build twice thanks to incremental artifact caching.
Stars: ✭ 348 (+98.86%)
Mutual labels:  nix
markkarpov.com
My personal web site
Stars: ✭ 16 (-90.86%)
Mutual labels:  nix
nixos-configuration
A repo for my nixos configuration files
Stars: ✭ 20 (-88.57%)
Mutual labels:  nix
rnix-parser
A Nix parser written in Rust [maintainer=@oberblastmeister]
Stars: ✭ 246 (+40.57%)
Mutual labels:  nix
persway
Small Sway IPC Daemon
Stars: ✭ 51 (-70.86%)
Mutual labels:  nix
nixvim
Configure Neovim with Nix!
Stars: ✭ 120 (-31.43%)
Mutual labels:  nix
purenix
Nix backend for PureScript. Transpile PureScript code to Nix.
Stars: ✭ 227 (+29.71%)
Mutual labels:  nix
presentations
Presentations at the Tokyo Nixos Meetup
Stars: ✭ 57 (-67.43%)
Mutual labels:  nix
nix-home
A nix home development environment
Stars: ✭ 16 (-90.86%)
Mutual labels:  nix

Make Nix precisely emulate gitignore

This goal of this project lets you include local sources in your Nix projects, while taking gitignore files into account.

Note that although this project does a good job at emulating git's behavior, it is not the same implementation!

Installation

Recommended with Niv

nix-env -iA niv -f https://github.com/nmattia/niv/tarball/master
niv init
niv add hercules-ci/gitignore.nix

With Flakes

Although Flakes usually process sources within the flake using the git fetcher, which takes care of ignoring in its own peculiar way, you can use gitignore.nix to filter sources outside of a flake. You can load flake-based expressions via builtins.getFlake (toString ./.) for example or via flake-compat.

# // flake.nix
{
  inputs.gitignore = {
    url = "github:hercules-ci/gitignore.nix";
    # Use the same nixpkgs
    inputs.nixpkgs.follows = "nixpkgs";
  };
  outputs = { self, /* other, inputs, */ gitignore }:
  let
    inherit (gitignore.lib) gitignoreSource;
  in {
    packages.x86_64.hello = mkDerivation {
      name = "hello";
      src = gitignoreSource ./vendored/hello;
    };
  };
}

Plain Nix way

let
  gitignoreSrc = pkgs.fetchFromGitHub { 
    owner = "hercules-ci";
    repo = "gitignore.nix";
    # put the latest commit sha of gitignore Nix library here:
    rev = "";
    # use what nix suggests in the mismatch message here:
    sha256 = "sha256:0000000000000000000000000000000000000000000000000000";
  };
  inherit (import gitignoreSrc { inherit (pkgs) lib; }) gitignoreSource;
in
  <your nix expression>

Or using only nixpkgs/lib and only evaluation-time fetching:

import (builtins.fetchTarball "https://github.com/hercules-ci/gitignore.nix/archive/000000000000000000000000000000000000000000000000000".tar.gz") {
  lib = import (builtins.fetchTarball "https://github.com/NixOS/nixpkgs/archive/000000000000000000000000000000000000000000000000000".tar.gz" + "/lib");
}

Usage

mkDerivation {
  name = "hello";
  src = gitignoreSource ./vendored/hello;
}
gitignoreSource :: path -> path

Returns result of cleanSourceWith, usable as a path but also composable.

gitignoreFilter :: path -> (path -> type -> bool)

f = gitignoreFilter path

Parentheses in the type emphasize that a partial application memoizes the git metadata. You can use Nixpkgs' cleanSourceWith to compose with other filters (by logical and) or to set a name.

path: a path being the root or a subdirectory of a local git repository

f: a function that returns false for files that should be ignored according to gitignore rules, but only for paths at or below path.

See gitignoreFilter for an example.

Features

  • Reads parent gitignores even if only pointed at a subdirectory
  • Source hashes only change when output changes
  • Not impacted by large or inaccessible ignored directories
  • Composes with cleanSourceWith
  • Reads user git configuration; no need to bother your team with your tool config.
  • Also works with restrict-eval enabled (if avoiding fetchFromGitHub)
  • No import from derivation ("IFD")
  • Name and hash are not sensitive to checkout location

Comparison

Feature \ Implementation cleanSource fetchGit/fetchTree siers siers recursive icetan Profpatsch numtide this project
Reproducible ✔️ ! ✔️ ✔️ ✔️ ✔️ ✔️ ✔️
Includes added but ignored files ✔️ ✔️
Uses user tooling rules from dotfiles ? ✔️
Ignores .git ✔️ ✔️ ✔️ ✔️ ✔️ ✔️ ✔️ ✔️
No special Nix configuration ✔️ ✔️ ✔️ ✔️ ✔️ ✔️ ✔️
No import from derivation ✔️ ! ✔️ ✔️ ✔️ ✔️ ✔️
Uses subdirectory gitignores ✔️ ✔️ ✔️ ✔️
Uses parent gitignores ✔️ ✔️ ? ✔️
Uses user gitignores ✔️ ? ✔️ ✔️
Has a test suite ✔️ ? ✔️ ✔️ ✔️ ? ✔️
Works with restrict-eval / Hydra ✔️ ? ✔️ ✔️ ✔️ ✔️
Descends into submodule correctly ✔️ ? ? ? ? ✔️ ? ? #8
Included in nixpkgs ✔️ ✔️ ✔️ ✔️
No traversal of ignored dirs
(perf on large repos)
- ✔️ ✔️ ? ✔️ ✔️ ? ✔️ ? ✔️ ?
Legend
✔️ Supported
✔️ ? Probably supported
Not supported
? Probably not supported
- Not applicable or depends
! Caveats

Caveats:

  • fetchGit is not reproducible. It has at least one serious reproducibility problem that requires a breaking change to fix. Unlike fixed-output derivations, a built-in fetcher does not have a pinned implementation!
  • fetchGit blocks the evaluator, just like import from derivation

Please open a PR if you've found another feature, determined any of the '?' or found an inaccuracy!

Security

Files not matched by gitignore rules will end up in the Nix store, which is readable by any process.

gitignore.nix does not yet understand git-crypt's metadata, so don't call gitignoreSource on directories containing such secrets or their parent directories. This applies to any Nix function that uses the builtins.path or builtins.filterSource functions.

Contributing

This project isn't perfect (yet) so please submit test cases and fixes as pull requests. Before doing anything drastic, it's a good idea to open an issue first to discuss and optimize the approach.

Thanks

A great shoutout to @siers for writing the intial test suite and rule translation code!

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].