Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make stacklock2nix work even if no local packages are specified #50

Merged
merged 3 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
## 4.0.2

* Fix a bug where `stacklock2nix` would throw an error if there were
no local `packages` defined in the input `stack.yaml` file.

This PR also makes `stacklock2nix` use a default package of `"."` if the
top-level `packages` key is missing from the `stack.yaml` file. This
matches `stack`'s behavior.

Fixed in [#50](https://github.com/cdepillabout/stacklock2nix/pull/50).
Thanks [@chris-martin](https://github.com/chris-martin) for reporting this.

## 4.0.1

* Download `.cabal` file revisions from the public Casa instance instead of
Expand Down
13 changes: 12 additions & 1 deletion nix/build-support/stacklock2nix/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,15 @@ let
# Call `mkLocalPkg` for each local package from the `stack.yaml` file.
#
# localPkgs :: [ { pkgPath :: Path, pkgName :: String } ]
localPkgs = map mkLocalPkg stackYamlParsed.packages;
#
# This uses the top-level `packages` key from `stack.yaml`. Note that
# if the `packages` key is not defined, `stack` defaults to using the value
# `["."]`, which defines one package in the same directory as the
# `stack.yaml` file.
localPkgs =
if stackYamlParsed ? packages
then map mkLocalPkg stackYamlParsed.packages
else [ (mkLocalPkg ".") ];

suggestedOverlay = callPackage ./suggestedOverlay.nix {};

Expand Down Expand Up @@ -777,6 +785,9 @@ let
#
# Note that this derivation is specifically meant to be passed to `nix
# develop` or `nix-shell`.
#
# Note that if you don't have any local packages defined in your `stack.yaml`
# file, this `devShell` won't really be useful.
devShell = devShellForPkgSet pkgSet;

# An Nixpkgs Haskell overlay that has GHC boot packages set to `null`. This
Expand Down
8 changes: 8 additions & 0 deletions test/nixpkgs.nix
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ let

# This tests that all-cabal-hashes works correctly as a directory (not a tarball).
all-cabal-hashes-is-dir = final.callPackage ./test-all-cabal-hashes-is-dir.nix {};

# This test that a stack.yaml with no local packages defined is still
# able to be used by stacklock2nix, and produces a reasonable package set.
no-local-packages = final.callPackage ./test-no-local-packages {};

# This tests that leaving out the `packages` top-level key from `stack.yaml` will
# default to just using a single package in the same directory as the `stack.yaml` file.
default-local-package = final.callPackage ./test-default-local-package {};
};

# A list of all stacklock2nix tests. This makes it easy to build all
Expand Down
30 changes: 30 additions & 0 deletions test/test-default-local-package/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
Copyright Dennis Gosnell (c) 2022

All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.

* Neither the name of Dennis Gosnell nor the names of other
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
5 changes: 5 additions & 0 deletions test/test-default-local-package/Main.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

module Main where

main :: IO ()
main = pure ()
68 changes: 68 additions & 0 deletions test/test-default-local-package/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@

{ stacklock2nix
, haskell
, cabal-install
, fetchFromGitHub
}:

let
hasklib = haskell.lib.compose;

stacklock = stacklock2nix {
stackYaml = ./stack.yaml;
baseHaskellPkgSet = haskell.packages.ghc924;
additionalHaskellPkgSetOverrides = hfinal: hprev: {
# The servant-cassava.cabal file is malformed on GitHub:
# https://github.com/haskell-servant/servant-cassava/pull/29
servant-cassava =
hasklib.overrideCabal
{ editedCabalFile = null; revision = null; }
hprev.servant-cassava;

amazonka = hasklib.dontCheck hprev.amazonka;
amazonka-core = hasklib.dontCheck hprev.amazonka-core;
amazonka-sso = hasklib.dontCheck hprev.amazonka-sso;
amazonka-sts = hasklib.dontCheck hprev.amazonka-sts;
};
cabal2nixArgsOverrides = args: args // {
amazonka-sso = ver: { amazonka-test = null; };
amazonka-sts = ver: { amazonka-test = null; };
};
additionalDevShellNativeBuildInputs = stacklockHaskellPkgSet: [
cabal-install
];
all-cabal-hashes = fetchFromGitHub {
owner = "commercialhaskell";
repo = "all-cabal-hashes";
rev = "80869091dcb9f932c15fe57e30d4d0730c5f87df";
sha256 = "sha256-LAD3/5qeJWbzfqkcWccMOq0pHBnSkNnvBjWnlLzWFvQ=";
};
};
in

let
# A list of all the names of the local packages.
localPkgNames = builtins.attrNames (stacklock.stackYamlLocalPkgsOverlay null null);
in

# The local packages overlay should contain a single local package.
assert builtins.length localPkgNames == 1;

let
localPkgName = builtins.head localPkgNames;
in

# The name of the local package should be read correctly from the .cabal file.
assert localPkgName == "my-cool-package-foobar";

[ # We should be able to build the local package:
stacklock.pkgSet.my-cool-package-foobar

# We should also be able to build other packages from stack.yaml.
# Two random packages to check:
stacklock.pkgSet.amazonka-core
stacklock.newPkgSet.lens

# Also be able to build the devshell:
stacklock.newPkgSetDevShell
]
29 changes: 29 additions & 0 deletions test/test-default-local-package/my-cool-package-foobar.cabal
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
cabal-version: 1.12

name: my-cool-package-foobar
version: 0.1.0.0
description: Please see the README on GitHub at <https://github.com/cdepillabout/stacklock2nix#readme>
homepage: https://github.com/cdepillabout/stacklock2nix#readme
bug-reports: https://github.com/cdepillabout/stacklock2nix/issues
author: Your Name Here
maintainer: [email protected]
copyright: Copyright (c) 2018 You
license: BSD3
license-file: LICENSE
build-type: Simple
extra-source-files:
README.md

source-repository head
type: git
location: https://github.com/cdepillabout/stacklock2nix

executable my-cool-package-foobar
main-is: Main.hs
ghc-options: -threaded -rtsopts -with-rtsopts=-N
build-depends:
base >=4.7 && <5
, optparse-applicative
, unagi-streams
default-language: Haskell2010

40 changes: 40 additions & 0 deletions test/test-default-local-package/stack.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
resolver: nightly-2022-10-18

# This is a test that stacklock2nix works even if the top-level `packages` key
# is not specified. In this case, `stack` defaults to having a single package
# in this same directory.
# packages: ["."]

extra-deps:

# example dep from hackage
- "unagi-streams-0.2.7"

# example git dep
- git: "https://github.com/haskell-servant/servant-cassava"
commit: "f76308b42b9f93a6641c70847cec8ecafbad3abc"

# example git dep with single subdir
- git: "https://github.com/haskell-servant/servant"
commit: "1fba9dc6048cea6184964032b861b052cd54878c"
subdir: "servant-client"

# example git dep with multiple subdirs
- git: "https://github.com/haskell-servant/servant"
commit: "1fba9dc6048cea6184964032b861b052cd54878c"
subdirs:
- "servant"
- "servant-server"

# example of a GitHub dep without subdirs
- github: cdepillabout/pretty-simple
commit: "d8ef1b3c2d913a05515b2d1c4fec0b52d2744434"

# example of a GitHub dep with multiple subdirs
- github: brendanhay/amazonka
commit: "43e8fb7e6e30e24adef11f66331ae6752642bffd"
subdirs:
- lib/amazonka
- lib/amazonka-core
- lib/services/amazonka-sso
- lib/services/amazonka-sts
132 changes: 132 additions & 0 deletions test/test-default-local-package/stack.yaml.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
# This file was autogenerated by Stack.
# You should not edit this file by hand.
# For more information, please see the documentation at:
# https://docs.haskellstack.org/en/stable/lock_files

packages:
- completed:
hackage: unagi-streams-0.2.7@sha256:4aa0290e5e92145686ba54ab5a53972c0f9fd22b9e06492d769ae61c8423aa22,1142
pantry-tree:
sha256: fe3eb224bf3771c039081e6097e9199095354be78770ab1215688f9316f692d6
size: 329
original:
hackage: unagi-streams-0.2.7
- completed:
commit: f76308b42b9f93a6641c70847cec8ecafbad3abc
git: https://github.com/haskell-servant/servant-cassava
name: servant-cassava
pantry-tree:
sha256: 1e040a08512e69847e2c9a9e313927b4a1864408a32ac935819247291d154ea7
size: 652
version: 0.10.1
original:
commit: f76308b42b9f93a6641c70847cec8ecafbad3abc
git: https://github.com/haskell-servant/servant-cassava
- completed:
commit: 1fba9dc6048cea6184964032b861b052cd54878c
git: https://github.com/haskell-servant/servant
name: servant-client
pantry-tree:
sha256: c37445bd27aa2f7234b3c5ef73533b0952b979f005d38ca5ebfc8230e2712f92
size: 1481
subdir: servant-client
version: '0.19'
original:
commit: 1fba9dc6048cea6184964032b861b052cd54878c
git: https://github.com/haskell-servant/servant
subdir: servant-client
- completed:
commit: 1fba9dc6048cea6184964032b861b052cd54878c
git: https://github.com/haskell-servant/servant
name: servant
pantry-tree:
sha256: ce0c502681ffbf5cb48f5606e9a9947e4c956b39ed8ce5b1a590dbaeff112dd9
size: 2949
subdir: servant
version: '0.19'
original:
commit: 1fba9dc6048cea6184964032b861b052cd54878c
git: https://github.com/haskell-servant/servant
subdir: servant
- completed:
commit: 1fba9dc6048cea6184964032b861b052cd54878c
git: https://github.com/haskell-servant/servant
name: servant-server
pantry-tree:
sha256: 2f0df25ed677c6f08aaf1499eec2c82830aedbbe19564d7356ed77cbd49ceeed
size: 2727
subdir: servant-server
version: 0.19.1
original:
commit: 1fba9dc6048cea6184964032b861b052cd54878c
git: https://github.com/haskell-servant/servant
subdir: servant-server
- completed:
name: pretty-simple
pantry-tree:
sha256: da2d314323affae4fa11f523bc2655ed0d5f27fd47f781654396d231673e0a68
size: 2200
sha256: aba1659b4c133b00b7a28837bcb413672823d72835bcee0f1594e0ba4e2ea4af
size: 101732
url: https://github.com/cdepillabout/pretty-simple/archive/d8ef1b3c2d913a05515b2d1c4fec0b52d2744434.tar.gz
version: 4.1.2.0
original:
url: https://github.com/cdepillabout/pretty-simple/archive/d8ef1b3c2d913a05515b2d1c4fec0b52d2744434.tar.gz
- completed:
name: amazonka
pantry-tree:
sha256: f1ba46f355d47bd1494d01b4eb1002c8efdd666639aa3fd0163581409071b7b8
size: 1318
sha256: 3cc2cdb4add25e6ef36c5124301387039b2f71fb7a809732cfce182b830787b1
size: 30018929
subdir: lib/amazonka
url: https://github.com/brendanhay/amazonka/archive/43e8fb7e6e30e24adef11f66331ae6752642bffd.tar.gz
version: '2.0'
original:
subdir: lib/amazonka
url: https://github.com/brendanhay/amazonka/archive/43e8fb7e6e30e24adef11f66331ae6752642bffd.tar.gz
- completed:
name: amazonka-core
pantry-tree:
sha256: 8707039e4fb7c575fbcd04906e4f541948ed152534da6d3830b9675badb4c71d
size: 3192
sha256: 3cc2cdb4add25e6ef36c5124301387039b2f71fb7a809732cfce182b830787b1
size: 30018929
subdir: lib/amazonka-core
url: https://github.com/brendanhay/amazonka/archive/43e8fb7e6e30e24adef11f66331ae6752642bffd.tar.gz
version: '2.0'
original:
subdir: lib/amazonka-core
url: https://github.com/brendanhay/amazonka/archive/43e8fb7e6e30e24adef11f66331ae6752642bffd.tar.gz
- completed:
name: amazonka-sso
pantry-tree:
sha256: e9a165eda0567cdf0581d29d8b1e9fe2df543474d7c70590e04ec1047ebe6d48
size: 1869
sha256: 3cc2cdb4add25e6ef36c5124301387039b2f71fb7a809732cfce182b830787b1
size: 30018929
subdir: lib/services/amazonka-sso
url: https://github.com/brendanhay/amazonka/archive/43e8fb7e6e30e24adef11f66331ae6752642bffd.tar.gz
version: '2.0'
original:
subdir: lib/services/amazonka-sso
url: https://github.com/brendanhay/amazonka/archive/43e8fb7e6e30e24adef11f66331ae6752642bffd.tar.gz
- completed:
name: amazonka-sts
pantry-tree:
sha256: 3a0d4983a363e953e6dc651d1aaa6ca30755a16c01edf63e5104ece7745e3954
size: 2932
sha256: 3cc2cdb4add25e6ef36c5124301387039b2f71fb7a809732cfce182b830787b1
size: 30018929
subdir: lib/services/amazonka-sts
url: https://github.com/brendanhay/amazonka/archive/43e8fb7e6e30e24adef11f66331ae6752642bffd.tar.gz
version: '2.0'
original:
subdir: lib/services/amazonka-sts
url: https://github.com/brendanhay/amazonka/archive/43e8fb7e6e30e24adef11f66331ae6752642bffd.tar.gz
snapshots:
- completed:
sha256: 895204e9116cba1f32047525ec5bad7423216587706e5df044c4a7c191a5d8cb
size: 644482
url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/nightly/2022/10/18.yaml
original: nightly-2022-10-18
Loading
Loading