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

[DEVOPS-810] Fix nix-shell env #3174

Merged
merged 3 commits into from
Jul 5, 2018
Merged

[DEVOPS-810] Fix nix-shell env #3174

merged 3 commits into from
Jul 5, 2018

Conversation

rvl
Copy link
Contributor

@rvl rvl commented Jul 2, 2018

Description

The change to justStaticExecutablesGitRev broke the .env attribute of haskell derivations.

Also there is a new nixpkgs lib function for filtering sources.

Linked issue

https://iohk.myjetbrains.com/youtrack/issue/DEVOPS-810
https://iohk.myjetbrains.com/youtrack/issue/DEVOPS-937

Type of change

  • Build scripts/dev environment bug fix
  • Build scripts refactor

QA Steps

nix-shell default.nix -A cardano-sl-wallet-new.env
nix-build -A all-cardano-sl

@rvl rvl requested review from k0001 and a team July 2, 2018 18:08
@rvl rvl requested a review from iohk-devops as a code owner July 2, 2018 18:08
lib.nix Outdated
@@ -12,10 +12,23 @@ let
then result
else default;

filterSource = src:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a builtin. by the same name. Using a different name, like filterSrc, may reduce confusion/mistakes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, will rename to localLib.cleanHaskellSource.

default.nix Outdated
if (builtins.typeOf args.src) == "path"
then builtins.filterSource cleanSourceFilter args.src
else args.src or null;
src = localLib.filterSource args.src;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As filterSource is implemented I think some filters are getting dropped, like:

  • # Filter out .git repo
  • # Filter out editor backup / swap files.
  • # Filter out nix-build result symlinks

Is that what we want?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The good thing about pkgs.lib.cleanSourceWith (as opposed to builtins.filterSource) is that it's chainable. In localLib.filterSource it calls the "default" pkgs.lib.cleanSource function which provides the above filters. I verify this by running nix-build and checking that a cached build is used.

@rvl rvl force-pushed the devops-810-fix-gitrev-env branch 2 times, most recently from 8cbfdf7 to 8ec88de Compare July 3, 2018 02:40
lib.nix Outdated
# Filter out cabal build products
baseName == "dist" ||
# Filter out files which don't affect cabal build
lib.hasSuffix ".nix" baseName
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not convinced that having a *.nix file exclusion inside a function called cleanHaskellSource is a good idea.

Granted, it's probably OK for the cardano-sl codebase because we don't arrange Haskell packages this way, but generally is quite common to have the Nix package definition for a Haskell package inside the package's source directory. But even if it weren't common, cleanHaskellSource is probably the wrong name for a filter that excludes *.nix files.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the review. The goal of these source filters is to avoid nix-build rebuilds of cabal packages when only "irrelevant" files have been changed. For example, the common case of when I edit a .nix file within the package's source directory. Try this:

nix-build -A cardano-sl-wallet-new  # should download from hydra cache
touch wallet-new/hello
nix-build -A cardano-sl-wallet-new  # now it wants to rebuild everything

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, the purpose is clear. It's just that one wouldn't normally expect a function named “clean haskell source” to pay attention to .nix files.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, now it's called localLib.cleanSourceTree.

@rvl rvl force-pushed the devops-810-fix-gitrev-env branch 2 times, most recently from 8bee667 to 76da2ba Compare July 4, 2018 23:38
@rvl
Copy link
Contributor Author

rvl commented Jul 4, 2018

I have added a few more useful filters to localLib.cleanSourceTree, and changed other instances of builtins.filterSource in the source code tests to use lib.cleanSourceWith.

Copy link
Contributor

@disassembler disassembler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

# This is so that cached build products can be used whenever possible.
# It also applies the lib.cleanSource filter from nixpkgs which
# removes VCS directories, emacs backup files, etc.
cleanSourceTree = src:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add doc files to this function as well so changing md files doesn't trigger new builds?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably not because there is usually extra-source-files: README.md in the cabal file.

@rvl rvl force-pushed the devops-810-fix-gitrev-env branch from 76da2ba to 1eb2cb2 Compare July 5, 2018 01:33
@rvl rvl merged commit f62739c into develop Jul 5, 2018
@rvl rvl deleted the devops-810-fix-gitrev-env branch July 5, 2018 15:09
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants