From 8cbfdf70d916e9c2ed77947ebadb2d70e42b6c43 Mon Sep 17 00:00:00 2001 From: Rodney Lorrimar Date: Tue, 3 Jul 2018 04:01:04 +1000 Subject: [PATCH] [DEVOPS-937] nix: use cleanSourceWith for source filtering --- default.nix | 24 +----------------------- explorer/frontend/default.nix | 29 +++++++++-------------------- lib.nix | 15 ++++++++++++++- 3 files changed, 24 insertions(+), 44 deletions(-) diff --git a/default.nix b/default.nix index 15e2c851b56..de012c35cdb 100644 --- a/default.nix +++ b/default.nix @@ -113,29 +113,7 @@ let # Provide a dummy installPhase for benchmark packages. installPhase = "mkdir -p $out"; }) // optionalAttrs (args ? src) { - src = let - cleanSourceFilter = with pkgs.stdenv; - name: type: let baseName = baseNameOf (toString name); in ! ( - # Filter out .git repo - (type == "directory" && baseName == ".git") || - # Filter out editor backup / swap files. - lib.hasSuffix "~" baseName || - builtins.match "^\\.sw[a-z]$" baseName != null || - builtins.match "^\\..*\\.sw[a-z]$" baseName != null || - - # Filter out locally generated/downloaded things. - baseName == "dist" || - - # Filter out the files which I'm editing often. - lib.hasSuffix ".nix" baseName || - # Filter out nix-build result symlinks - (type == "symlink" && lib.hasPrefix "result" baseName) - ); - - in - if (builtins.typeOf args.src) == "path" - then builtins.filterSource cleanSourceFilter args.src - else args.src or null; + src = localLib.cleanHaskellSource args.src; } // optionalAttrs enableDebugging { # TODO: DEVOPS-355 dontStrip = true; diff --git a/explorer/frontend/default.nix b/explorer/frontend/default.nix index 6deb5a06c89..4ef2bb3cb99 100644 --- a/explorer/frontend/default.nix +++ b/explorer/frontend/default.nix @@ -11,26 +11,14 @@ in with pkgs.lib; let - cleanSourceFilter = with pkgs.stdenv; - name: type: let baseName = baseNameOf (toString name); in ! ( - # Filter out .git repo - (type == "directory" && baseName == ".git") || - # Filter out editor backup / swap files. - lib.hasSuffix "~" baseName || - builtins.match "^\\.sw[a-z]$" baseName != null || - builtins.match "^\\..*\\.sw[a-z]$" baseName != null || - - # Filter out locally generated/downloaded things. - baseName == "bower_components" || - (type == "directory" && (baseName == "node_modules" || baseName == "dist")) || - - # Filter out the files which I'm editing often. - lib.hasSuffix ".nix" baseName || - # Filter out nix-build result symlinks - (type == "symlink" && lib.hasPrefix "result" baseName) - ); - - src = builtins.filterSource cleanSourceFilter ./.; + src = cleanSourceWith { + src = localLib.cleanHaskellSource ./.; + filter = with pkgs.stdenv; + name: type: let baseName = baseNameOf (toString name); in ! ( + # Filter out locally generated/downloaded things. + baseName == "bower_components" || baseName == "node_modules" + ); + }; bowerComponents = pkgs.buildBowerComponents { name = "cardano-sl-explorer-frontend-deps"; @@ -69,6 +57,7 @@ let cardano-sl-explorer purescript ]; + passthru = { inherit bowerComponents; }; postConfigure = '' rm -rf .psci_modules .pulp-cache bower_components output result diff --git a/lib.nix b/lib.nix index f6ae2f91e45..6ab4039f768 100644 --- a/lib.nix +++ b/lib.nix @@ -12,10 +12,23 @@ let then result else default; + cleanHaskellSource = src: + if (builtins.typeOf src) == "path" + then lib.cleanSourceWith { + filter = with pkgs.stdenv; + name: type: let baseName = baseNameOf (toString name); in ! ( + # Filter out cabal build products + baseName == "dist" || + # Filter out files which don't affect cabal build + lib.hasSuffix ".nix" baseName + ); + src = lib.cleanSource src; + } else src; + pkgs = import fetchNixPkgs {}; lib = pkgs.lib; in lib // (rec { - inherit fetchNixPkgs; + inherit fetchNixPkgs cleanHaskellSource; isCardanoSL = lib.hasPrefix "cardano-sl"; isBenchmark = args: !((args.isExecutable or false) || (args.isLibrary or true)); })