From f8c014f72ee025d8d9458b2d6ac0b4500284efe6 Mon Sep 17 00:00:00 2001 From: Doron Behar Date: Thu, 30 Sep 2021 08:59:52 +0300 Subject: [PATCH] Add a flake.nix --- README.md | 24 ++++++++++++++++++++++++ flake.lock | 25 +++++++++++++++++++++++++ flake.nix | 9 +++++++++ 3 files changed, 58 insertions(+) create mode 100644 flake.lock create mode 100644 flake.nix diff --git a/README.md b/README.md index 502e381..ee8130e 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,30 @@ 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`](https://github.com/edolstra/flake-compat). + +```nix +# // 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 ```nix diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..de9f824 --- /dev/null +++ b/flake.lock @@ -0,0 +1,25 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1632846328, + "narHash": "sha256-sFi6YtlGK30TBB9o6CW7LG9mYHkgtKeWbSLAjjrNTX0=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "2b71ddd869ad592510553d09fe89c9709fa26b2b", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "type": "indirect" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..702b3fb --- /dev/null +++ b/flake.nix @@ -0,0 +1,9 @@ +{ + description = "Nix functions for filtering local git sources"; + + outputs = { self, nixpkgs }: { + lib = import ./default.nix { + inherit (nixpkgs) lib; + }; + }; +}