-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor setup for generated nix files
the reiterates on #1220. The motivation for the refactoring was that the generated files were not using `gitSource`, so I would get cache misses and dirty files in the repo. Fixing this was easier if all generated nix files are in one place, so I did the following changes: * All generated nix files are in `nix/generated`. This de-pollutes the normal working area with generated files, and keeps them out from sources (more precise derivations). * The local generated files now use `gitSource`. * The generator is now `nix/generate.nix`. * I moved complex logic from `nix/default.nix` to `nix/generate.nix`, this means everything is in one place, instead of spread over several nix files. * There is now only a single check to check if the generated files are upto date, and a single command to update the files. * This check is no longer marked `allowSubstitutes = false`. The check isn’t cheap (it requires `cabal2nix`) and we want the check to happen on builders, not hydra itself, so that the cache has `cabal2nix`. * The check is now included in `all-systems-go`.
- Loading branch information
Showing
12 changed files
with
125 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
# This file generates the contents of nix/generated/. Use | ||
# | ||
# cp -fv $(nix-build generate.nix --no-link)/ generated/ | ||
# | ||
# to update | ||
|
||
{ pkgs ? import ../nix {} }: | ||
|
||
let | ||
|
||
# `haskellSrc2nixWithDoc` is used to generate `default.nix` files for | ||
# Haskell packages which are intended to be stored in the repository. | ||
# | ||
# The function generates a directory containing a `default.nix` which | ||
# is the result of running `cabal2nix` with the `extraCabal2nixOptions` | ||
# on the provided `src`. | ||
# | ||
# A header is added to `default.nix` which contains instructions on | ||
# how to regenerate that file. | ||
# | ||
# Finally the `src` attribute in the `default.nix` will be defined as | ||
# `src_subst` such that it can be pointed to local or niv-managed | ||
# sources. | ||
haskellSrc2nixWithDoc = {name, src, src_subst, extraCabal2nixOptions}: | ||
let | ||
drv = pkgs.haskellPackages.haskellSrc2nix { | ||
inherit name extraCabal2nixOptions src; | ||
}; | ||
in drv.overrideAttrs (oldAttrs: { | ||
message = '' | ||
# THIS IS AN AUTOMATICALLY GENERATED FILE. DO NOT EDIT MANUALLY!\ | ||
# See ./nix/generate.nix for instructions.\ | ||
''; | ||
inherit src_subst; | ||
installPhase = oldAttrs.installPhase + '' | ||
sed -i "1i$message;s|src = .*|src = $src_subst;|" $out/default.nix | ||
# Accept `pkgs` as an argument in case the `src_subst` depends on it. | ||
sed -i "s|{ mkDerivation|{ mkDerivation, pkgs|" $out/default.nix | ||
''; | ||
}); | ||
|
||
# A variant of `haskellSrc2nixWithDoc` for local Haskell packages. | ||
localHaskellSrc2nixWithDoc = name: path: extraCabal2nixOptions: | ||
haskellSrc2nixWithDoc { | ||
inherit name extraCabal2nixOptions; | ||
src = import ./gitSource.nix path; | ||
src_subst = "import ../gitSource.nix \"${path}\""; | ||
}; | ||
|
||
|
||
winter = (haskellSrc2nixWithDoc { | ||
name = "winter"; | ||
src = pkgs.sources.winter; | ||
src_subst = "pkgs.sources.winter"; | ||
extraCabal2nixOptions = "--no-check"; | ||
}); | ||
|
||
ic-stub = localHaskellSrc2nixWithDoc "ic-stub" "ic-stub" "--no-check"; | ||
random = localHaskellSrc2nixWithDoc "qc-motoko" "test/random" ""; | ||
lsp-int = localHaskellSrc2nixWithDoc "lsp-int" "test/lsp-int" ""; | ||
|
||
allGenerated = pkgs.runCommandNoCC "generated" {} '' | ||
mkdir -p $out | ||
cp ${winter}/default.nix $out/winter.nix | ||
cp ${ic-stub}/default.nix $out/ic-stub.nix | ||
cp ${random}/default.nix $out/random.nix | ||
cp ${lsp-int}/default.nix $out/lsp-int.nix | ||
''; | ||
in | ||
allGenerated | ||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# THIS IS AN AUTOMATICALLY GENERATED FILE. DO NOT EDIT MANUALLY! | ||
# See ./nix/generate.nix for instructions. | ||
|
||
{ mkDerivation, pkgs, base, data-default, directory, filepath | ||
, haskell-lsp-types, hspec, HUnit, lens, lsp-test, stdenv, text | ||
}: | ||
mkDerivation { | ||
pname = "lsp-int"; | ||
version = "0"; | ||
src = import ../gitSource.nix "test/lsp-int"; | ||
isLibrary = false; | ||
isExecutable = true; | ||
executableHaskellDepends = [ | ||
base data-default directory filepath haskell-lsp-types hspec HUnit | ||
lens lsp-test text | ||
]; | ||
description = "Integration tests for the language server"; | ||
license = "unknown"; | ||
hydraPlatforms = stdenv.lib.platforms.none; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.