Skip to content
This repository has been archived by the owner on Aug 18, 2020. It is now read-only.

Commit

Permalink
[DEVOPS-937] nix: use cleanSourceWith for source filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
rvl committed Jul 3, 2018
1 parent 2dfc205 commit 8cbfdf7
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 44 deletions.
24 changes: 1 addition & 23 deletions default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
29 changes: 9 additions & 20 deletions explorer/frontend/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -69,6 +57,7 @@ let
cardano-sl-explorer
purescript
];
passthru = { inherit bowerComponents; };
postConfigure = ''
rm -rf .psci_modules .pulp-cache bower_components output result
Expand Down
15 changes: 14 additions & 1 deletion lib.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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));
})

0 comments on commit 8cbfdf7

Please sign in to comment.