From 9f7db9e7db7c475821e6bd3a81cc66a41430b35a Mon Sep 17 00:00:00 2001 From: Antonio Nuno Monteiro Date: Sun, 8 Dec 2024 00:11:17 -0800 Subject: [PATCH] refactor(nix): use `lib.fileset` instead of nix-filter (#1247) --- flake.lock | 16 ---------------- flake.nix | 6 +----- nix/default.nix | 36 ++++++++++++++++++------------------ nix/melange-playground.nix | 33 ++++++++++++++++++--------------- nix/overlay.nix | 6 +++--- 5 files changed, 40 insertions(+), 57 deletions(-) diff --git a/flake.lock b/flake.lock index 9f44c669f..f6e9744b2 100644 --- a/flake.lock +++ b/flake.lock @@ -20,21 +20,6 @@ "type": "github" } }, - "nix-filter": { - "locked": { - "lastModified": 1731533336, - "narHash": "sha256-oRam5PS1vcrr5UPgALW0eo1m/5/pls27Z/pabHNy2Ms=", - "owner": "numtide", - "repo": "nix-filter", - "rev": "f7653272fd234696ae94229839a99b73c9ab7de0", - "type": "github" - }, - "original": { - "owner": "numtide", - "repo": "nix-filter", - "type": "github" - } - }, "nixpkgs": { "inputs": { "nixpkgs": "nixpkgs_2" @@ -72,7 +57,6 @@ "root": { "inputs": { "melange-compiler-libs": "melange-compiler-libs", - "nix-filter": "nix-filter", "nixpkgs": "nixpkgs" } } diff --git a/flake.nix b/flake.nix index facc1ac9c..e19de32ca 100644 --- a/flake.nix +++ b/flake.nix @@ -2,7 +2,6 @@ description = "Melange Nix Flake"; inputs = { - nix-filter.url = "github:numtide/nix-filter"; nixpkgs.url = "github:nix-ocaml/nix-overlays"; melange-compiler-libs = { # this changes rarely, and it's better than having to rely on nix's poor @@ -12,7 +11,7 @@ }; }; - outputs = { self, nixpkgs, nix-filter, melange-compiler-libs }: + outputs = { self, nixpkgs, melange-compiler-libs }: let forAllSystems = f: nixpkgs.lib.genAttrs nixpkgs.lib.systems.flakeExposed (system: let @@ -24,14 +23,12 @@ in { overlays.default = import ./nix/overlay.nix { - nix-filter = nix-filter.lib; melange-compiler-libs-vendor-dir = melange-compiler-libs; }; packages = forAllSystems (pkgs: let melange = pkgs.callPackage ./nix { - nix-filter = nix-filter.lib; melange-compiler-libs-vendor-dir = melange-compiler-libs; }; in @@ -40,7 +37,6 @@ default = melange; melange-playground = pkgs.ocamlPackages.callPackage ./nix/melange-playground.nix { inherit melange; - nix-filter = nix-filter.lib; melange-compiler-libs-vendor-dir = melange-compiler-libs; }; } diff --git a/nix/default.nix b/nix/default.nix index eefa5ab5e..c8ad21583 100644 --- a/nix/default.nix +++ b/nix/default.nix @@ -5,7 +5,6 @@ , git , tree , makeWrapper -, nix-filter , nodejs , melange-compiler-libs-vendor-dir , doCheck ? true @@ -18,23 +17,24 @@ buildDunePackage { version = "dev"; duneVersion = "3"; - src = with nix-filter; filter { - root = ./..; - include = [ - "belt" - "bin" - "dune-project" - "dune" - "jscomp" - "lib" - "melange.opam" - "ppx" - "scripts" - "test" - "vendor" - ]; - exclude = [ "jscomp/test" ]; - }; + src = + let fs = lib.fileset; in + fs.toSource { + root = ./..; + fileset = fs.unions [ + ../belt + ../bin + ../dune-project + ../dune + (fs.difference ../jscomp ../jscomp/test) + ../melange.opam + ../ppx + ../scripts + ../test + ../vendor + ]; + }; + postPatch = '' rm -rf vendor/melange-compiler-libs mkdir -p ./vendor diff --git a/nix/melange-playground.nix b/nix/melange-playground.nix index c5afe3b10..4bea648a4 100644 --- a/nix/melange-playground.nix +++ b/nix/melange-playground.nix @@ -1,6 +1,6 @@ { melange +, lib , buildDunePackage -, nix-filter , cppo , menhir , nodejs @@ -16,20 +16,23 @@ buildDunePackage { version = "dev"; duneVersion = "3"; - src = with nix-filter; filter { - root = ./..; - include = [ - "belt" - "bin" - "dune-project" - "dune" - "jscomp" - "melange-playground.opam" - "playground" - "test/blackbox-tests/melange-playground" - "vendor" - ]; - }; + src = + let fs = lib.fileset; in + fs.toSource { + root = ./..; + fileset = fs.unions [ + ../belt + ../bin + ../dune-project + ../dune + (fs.difference ../jscomp ../jscomp/test) + ../melange-playground.opam + ../playground + ../test/blackbox-tests/melange-playground + ../vendor + ]; + }; + postPatch = '' rm -rf vendor/melange-compiler-libs mkdir -p ./vendor diff --git a/nix/overlay.nix b/nix/overlay.nix index 5ca08bd77..5c55bbe58 100644 --- a/nix/overlay.nix +++ b/nix/overlay.nix @@ -1,4 +1,4 @@ -{ nix-filter, melange-compiler-libs-vendor-dir }: +{ melange-compiler-libs-vendor-dir }: final: prev: @@ -9,11 +9,11 @@ final: prev: { melange = prev.callPackage ./. { - inherit nix-filter melange-compiler-libs-vendor-dir; + inherit melange-compiler-libs-vendor-dir; doCheck = false; }; melange-playground = prev.lib.callPackageWith oself ./melange-playground.nix { - inherit nix-filter melange-compiler-libs-vendor-dir; + inherit melange-compiler-libs-vendor-dir; inherit (prev) nodejs; }; }