Commit Graph

19 Commits

Author SHA1 Message Date
Ewout f1bb3aa2f2 Fix cleanGit when src is a git submodule. (#1469)
Suppose you have a repository with a submodule checked out in the
subdirectory `smod`.

`cleanGit { src = ./smod; }` would return the following error:

    error: getting status of '/.git/modules/smod': No such file or directory

`smod/.git` is a file that contains a reference to the git module repo.

    gitdir: ../.git/modules/smod

This is the same as a worktree (in fact, isWorktree = true here),
but it's a relative path instead of an absolute path.

Co-authored-by: Ewout Van Troostenberghe <evantroostenberghe@hubspot.com>
2022-05-13 20:00:41 +12:00
Michael Peyton Jones 315b6d353d Don't use allowSubstitutes=false (#1389)
`runCommandLocal` sets both `preferLocalBuild=true` and
`allowSubstitutes=false`. There's an
[argument](https://github.com/NixOS/nix/issues/4442) that the latter is a
misfeature. There's really no reason not to download something from a
substitutor if it's actually been built already.

We can get the effect that we want easily enough by just setting
`preferLocalBuild=true` alone.
2022-03-03 15:17:42 +13:00
Cheng Shao c084516ada git-ls-files should prefer local building (#1378) 2022-02-22 14:24:33 +00:00
Hamish Mackenzie 9085d9f44e Fix cleanGit submodule support performance issue (#1072)
Currently in order to support submodules all the directories are included (but not all files) when building the whitelist.  This is done because we need the `.git` files (or directories) the contain to be present when we run `git ls-files --recurse-submodules`.

Including every directory causes two performance issues:

* Creating a directory in your repo (even empty one not added to git at all) will require the whitelist to be recalculated.

* Recalculation of the whiltelist may be slowed down if there are a large number of directories.  In particular `lstat` is called on every file (probably to get the right `type` to pass to the filter function).

The fix is to use `git submodule status --recursive` to get a list of all the submodule directories.  Then the `.git` files (or directories) in them can be included.  This has to be repeated until all the submodules are known (as `--recursive` will not see the submodules until the parent module is included).
2021-03-18 19:49:10 +13:00
Hamish Mackenzie 64efc98852 Support githash package and cross package refs (#843)
* Adds support for cross package refs (with a project).  Relative
  directory references between packages within a project should now
  work.
* Adds `includeSiblings` to `cleanSourceWith`.  When `true` it
  prevents the `subDir` arg from causing filtering of other directories.
* Adds `keepGitDir` to `cleanGit` to allow `.git` directory to be kept
  (useful for components that use the `githash` package).
2021-01-14 12:34:06 +13:00
Hamish Mackenzie 3991463043 Revert "cleanGit: Detect when called inside a submodule (#847)" (#890)
This reverts commit 3798469c3f.
2020-10-20 22:25:34 +13:00
Thomas Tuegel 3798469c3f cleanGit: Detect when called inside a submodule (#847)
If cleanGit is called inside a submodule, the true gitdir is not available, so
fall back to cleanSourceWith as if called outside the repository.
2020-09-16 22:25:40 +12:00
Hamish Mackenzie 6935e7d044 cleanGit on an already cleaned copies to store (#788)
```
cleanGit {
  src = cleanSrcWith { ... }
}
```

Results in the full `src` being copied to the store before filtering
the files not in the git index.

This change uses `src.origSrcSubDir` if it exists to avoid this.
2020-07-27 10:22:19 +12:00
Hamish Mackenzie ecc72c1949 Add cleanGits and support it incabalProject (#631)
Some times it is handy to temporarily use a relative path between git
repos.  If the repos are individually cleaned this is not possible
(since the cleaned version of one repo will never include the files
of the other).

`cleanGits` allows us to specify a root directory and any number of
sub directories containing git repos.
2020-05-28 21:59:36 +12:00
Hamish Mackenzie 0aa17d8afc Use subDir not src to construct default names (#506)
When no name is provided to `cleanSourceWith` or `cleanGit` we
currently use `baseNameOf src` as a default.

This was cute, but it lead to cache misses.  For instance if
`x = cleanSourceWith { src = ./.; }` then `baseName src`
will be different when `src` resolves to "/nix/store/X"
than when it is in a local directory.  If people use
git worktrees they also may wind up with different
values for `name`. Anything that depends on `x.name` will
propagate the issue.

This change uses `subDir` if present or if it is not it encourages
adding a suitable `name` with a warning message.
2020-03-25 13:45:43 +13:00
Alexander Bantyev 78526fca32 Pass name argument through cleanGit (#437) 2020-02-08 16:09:23 +13:00
Samuel Leathers 4afd58dc9d fix paths for worktree when sandbox is enabled (#423) 2020-01-30 10:32:08 +13:00
Hamish Mackenzie 674cdf215e Fix cleanGit for submodules of submodules (#413)
Repos that have submodules with submodules will have a `.git` file
that references the relative location of the submodules dir in the
`.git/modules`.  Without this file the contents of submodules of
submodules are excluded from the `cleanGit` output.
2020-01-23 17:19:11 +13:00
Jonas Carpay 50180fb684 Improve cleanGit error handling (#408) 2020-01-21 22:07:40 +13:00
Hamish Mackenzie 3c78559621 Fix cleaning git submodules not in a worktree (#311)
When we are not in a worktree the submodule info is in the
`.git` dirs scattered throughout the repo itself.  In that situation
we need to copy the `.git` dirs into the temp location we are using
to run `git ls-files`.
2019-11-10 14:25:26 +13:00
Hamish Mackenzie 707c7b82f4 Fix cleanGit for repositories with no submodules (#304) 2019-11-08 17:52:41 +13:00
Hamish Mackenzie 5393c501e2 Fix cleanGit when using a worktree (#282)
Joachim's original version had logic to handle git worktree's but
it was not wired into the updated version that uses cleanSourceWith.
2019-11-06 22:44:09 +13:00
Hamish Mackenzie 23e0c2fcea Add subDir argument to cleanGit (#280)
Co-Authored-By: Viktor Kronvall <viktor.kronvall@gmail.com>
2019-10-30 15:09:45 +13:00
Moritz Angermann 5884ab02be Overlays (#261)
The Overlays branch

This is a major reorganization in how haskell.nix is used, and marks our 1.0 release.
The branch doesn't build due to numerous issues that we believe to be with the CI
and not this branch. We expect only very minor adjustments prior to calling this the
official 1.0 release.

* Move iohk-nix patches into haskell.nix

This moves the customizations we did in iohk-nix
into haskell.nix via overlays and config.

Add bootPkgs logic

this moves the nuking of bootPkgs where it belongs. This should eventually still be
removed and replaced by a proper solution, that doesn't require the nuking of
bootPkgs.

Allow us to bootstrap binary ghcs and a cabal-install

With this we can do the following:

```
$ nix repl compiler/old-ghc-nix
nix-repl> :b (let pkgs = import <nixpkgs> {}; in with import ./. {}; import ./compiler/bootstrap/cabal-install.nix { inherit (pkgs) fetchurl stdenv zlib; inherit hackage
; ghc = ghc844; src = pkgs.fetchurl { url = "https://github.com/haskell/cabal/archive/Cabal-v3.0.0.0-rc3.tar.gz"; sha256 = "1zl2mgg8307ykq3v8nmafc6zdhhj1cw7w8ffpap16dsm6
5lbnx33"; }; })
```

which wile it may look daunting, will allow us to bootstrap a
cabal-install with a ghc. From that point onwards, we should be able to
build any hackage package via haskell.nix.

Pass through cabal-install version

Better threading of arguments.

Add bootstrap overlay

Allow alex + happy to be built

This still has a wart: we need nix-tools, and for that we use the ghc865 from
nixpkgs. Ideally we'd build nix-tools against a specific ghc, but then
we'd need a build expression for that.

Make ghcjs work

Building something like this:
```
 nix build '(with import ./. { nixpkgs = ../nixpkgs; nixpkgsArgs = { crossSystem = { config = "js-unknown-ghcjs"; }; }; }; (haskell-nix.hackage-package { name = "hello"; version = "1.0.0.2"; })).components.exes.hello'
```
will now work. Assuming `nixpkgs` has been appropriately patched to support the `js-unknown-ghcjs` triple.

Also: this will need an additional `Cabal` patch, to make `Cabal` understand what it needs to do with: `dist/build/hello/hello: copyFile: does not exist (No such file or directory)`

It needs to learn that `dist/build/hello/hello.jsexe` is what it wants to copy and that that is a directory.  Luckily we do have some code in Cabal already that does this for `.exe` on windows.

Build `js-unknown-ghcjs` packages with haskell.nix

Using the following expression:
```
with import ./. { nixpkgs = ../nixpkgs; nixpkgsArgs = { crossSystem = { config = "js-unknown-ghcjs"; }; }; };
let Cabal = buildPackages.haskell-nix.hackage-package {
    name = "Cabal"; version = "2.4.1.0";
    modules = [
        { packages.Cabal.patches = [ ./Cabal-install-folder.diff ]; }
    ];
}; in
(haskell-nix.hackage-package {
    name = "hello"; version = "1.0.0.2";
    modules = [
    	    ({config, ... }:{ packages.hello.package.setup-depends = [ Cabal ]; })
    ];}).components.exes.hello
```
in a `test.nix` file. And running
```
nix build -f ./test.nix
```
on it, will produce
```
./result
├── bin
│   └── hello.jsexe
│       ├── all.js
│       ├── all.js.externs
│       ├── index.html
│       ├── lib.js
│       ├── manifest.webapp
│       ├── out.frefs.js
│       ├── out.frefs.json
│       ├── out.js
│       ├── out.stats
│       ├── rts.js
│       └── runmain.js
└── share
    └── doc
        └── x86_64-linux-ghc-8.6.5
            └── hello-1.0.0.2
                └── LICENSE

6 directories, 12 files
```
2019-10-21 20:07:58 +08:00