diff --git a/.gitignore b/.gitignore index ff303bf..b64e008 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ build dist +dist-newstyle result cabal.sandbox.config diff --git a/nix/sources.json b/nix/sources.json index 7b5ed3c..960d4b4 100644 --- a/nix/sources.json +++ b/nix/sources.json @@ -34,5 +34,41 @@ "type": "tarball", "url": "https://github.com/NixOS/nixpkgs/archive/a3fa481cb683d619ab9e1a64877f3c0c5fd24f40.tar.gz", "url_template": "https://github.com///archive/.tar.gz" + }, + "nixpkgs-19.03": { + "branch": "release-19.03", + "description": "Nix Packages collection", + "homepage": "", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "27aaaa5ba6923104a23bae75d323dc975390195e", + "sha256": "1fdzc6psj369bi9bybgm9vwl5c7sa4z6k2sdz95ypcpgcg3s12ql", + "type": "tarball", + "url": "https://github.com/NixOS/nixpkgs/archive/27aaaa5ba6923104a23bae75d323dc975390195e.tar.gz", + "url_template": "https://github.com///archive/.tar.gz" + }, + "nixpkgs-19.09": { + "branch": "release-19.09", + "description": "Nix Packages collection", + "homepage": "", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "75f4ba05c63be3f147bcc2f7bd4ba1f029cedcb1", + "sha256": "157c64220lf825ll4c0cxsdwg7cxqdx4z559fdp7kpz0g6p8fhhr", + "type": "tarball", + "url": "https://github.com/NixOS/nixpkgs/archive/75f4ba05c63be3f147bcc2f7bd4ba1f029cedcb1.tar.gz", + "url_template": "https://github.com///archive/.tar.gz" + }, + "nixpkgs-20.03": { + "branch": "release-20.03", + "description": "Nix Packages collection", + "homepage": "", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "462c6fe4b115804ea4d5bee7103c0f46ff9f9cfb", + "sha256": "0a4bdaxjrds6kyw9s3r2vbc96f7glgy5n03jk4zr5z8h3j4v2s81", + "type": "tarball", + "url": "https://github.com/NixOS/nixpkgs/archive/462c6fe4b115804ea4d5bee7103c0f46ff9f9cfb.tar.gz", + "url_template": "https://github.com///archive/.tar.gz" } } diff --git a/shell.nix b/shell.nix index ef28d9f..63942bf 100644 --- a/shell.nix +++ b/shell.nix @@ -2,9 +2,17 @@ # License: GNU/GPLv3 https://raw.githubusercontent.com/unclechu/place-cursor-at/master/LICENSE let sources = import nix/sources.nix; in -# Forwarded arguments args@ -{ pkgs ? import sources.nixpkgs {} +{ pkgs ? + import sources."nixpkgs${ + if nixpkgs-release == "20.09" then "" else "-${nixpkgs-release}" + }" {} + +# Tested with lower 19.03 and upper 20.09 pins. +, nixpkgs-release ? "20.09" # One of: '20.09', '20.03', '19.09', '19.03' + +# It’s not provided in 19.03 for instance +, yq-go ? (import sources.nixpkgs { inherit (pkgs) config; }).yq-go # Forwarded build options , __src ? null @@ -16,6 +24,7 @@ args@ # Local arguments , withCabal ? false , withStack ? false +, withStackNixDependencies ? false , withPackageRepl ? false # Adds package library modules into GHCi REPL , withHoogle ? true , buildExecutable ? true @@ -28,7 +37,7 @@ let hp = pkg.haskellPackages; name = pkg.haskellPackage.pname; - inherit (nix-utils) wrapExecutable; + inherit (nix-utils) esc wrapExecutable; pkgReplGhc = hp.ghcWithPackages (p: [p.${name}]); # Produces ‘PACKAGE-NAME-ghc’ and ‘PACKAGE-NAME-ghci’ files. @@ -43,6 +52,34 @@ let (exe "ghci") (exe "ghc") ]; + + stackNixDependencies = + let + stackYamlFile = "${./stack.yaml}"; + path = "nix.packages"; + + nixModule = pkgs.runCommand "${name}-stack-yaml-nix-packages" {} '' + set -Eeuo pipefail || exit + JSON=$(${esc yq-go}/bin/yq r -j -- ${esc stackYamlFile} ${esc path}) + + if [[ -z $JSON ]]; then + >&2 printf 'Failed to extract "%s" from "%s"!\n' \ + ${esc path} ${esc stackYamlFile} + exit 1 + fi + + printf '%s' "$JSON" > "$out" + ''; + + attrPathToDerivation = x: + pkgs.lib.attrsets.getAttrFromPath (pkgs.lib.splitString "." x) pkgs; + + attrPaths = builtins.fromJSON (builtins.readFile nixModule); + in + assert builtins.isList attrPaths; + assert builtins.length attrPaths > 0; + assert builtins.all builtins.isString attrPaths; + map attrPathToDerivation attrPaths; in hp.shellFor { packages = p: [ @@ -54,6 +91,7 @@ hp.shellFor { buildInputs = (if withCabal then [ hp.cabal-install ] else []) ++ (if withStack then [ hp.stack ] else []) ++ + (if withStackNixDependencies then stackNixDependencies else []) ++ (if buildExecutable then [ hp.${name} ] else []) ++ (if withPackageRepl then pkgRepl else []); } diff --git a/src/place-cursor-at.hs b/src/place-cursor-at.hs index c7e7b07..1c9301a 100755 --- a/src/place-cursor-at.hs +++ b/src/place-cursor-at.hs @@ -9,7 +9,7 @@ {-# LANGUAGE UnicodeSyntax, BangPatterns, MultiWayIf, ViewPatterns, ScopedTypeVariables, GADTs #-} {-# LANGUAGE LambdaCase, DerivingStrategies, GeneralizedNewtypeDeriving #-} -import Prelude.Unicode +import Prelude.Unicode ((∘), (÷), (≡), (⧺), (∧), (≥)) import Data.Bifunctor (first) import Data.Bits ((.|.)) @@ -582,3 +582,10 @@ mkDoneHandler = newEmptyMVar <&> \mvar → DoneApi (•) = flip (∘) infixl 9 • {-# INLINE (•) #-} + +-- This operator is provided by newer version of ‘base-unicode-symbols’. +-- This adds support for older snaphots. +(×) ∷ Num a ⇒ a → a → a +(×) = (Prelude.*) +infixl 7 × +{-# INLINE (×) #-} diff --git a/stack.yaml b/stack.yaml index 7b79dd3..3c83b0e 100644 --- a/stack.yaml +++ b/stack.yaml @@ -1,5 +1,24 @@ -# also tested with lts-14.27 (ghc 8.6.5) -resolver: lts-16.6 # ghc 8.8.3 +# Also tested with lts-13.19 (ghc 8.6.4). +# +# Test older one using Nix: +# nix-shell \ +# --argstr nixpkgs-release 19.03 \ +# --arg buildExecutable false \ +# --arg withStack true \ +# --arg withStackNixDependencies true \ +# --run '[[ $(ghc --numeric-version) == 8.6.4 ]] && \ +# stack build --system-ghc --no-nix --resolver=lts-13.19 && \ +# stack exec --system-ghc --no-nix --resolver=lts-13.19 \ +# place-cursor-at' +# +# Test current one using Nix: +# nix-shell \ +# --arg buildExecutable false \ +# --arg withStack true \ +# --run 'stack build --system-ghc && \ +# stack exec --system-ghc -- place-cursor-at' +# +resolver: lts-17.6 # ghc 8.10.4 system-ghc: false packages: [.] diff --git a/stack.yaml.lock b/stack.yaml.lock index 0d17c05..a0e9c1f 100644 --- a/stack.yaml.lock +++ b/stack.yaml.lock @@ -6,7 +6,7 @@ packages: [] snapshots: - completed: - size: 531718 - url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/16/6.yaml - sha256: 230a7266fc11f76222bd3bb68e9503ed11d553060a752f164bff6753ed03e271 - original: lts-16.6 + size: 565712 + url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/17/6.yaml + sha256: 4e5e581a709c88e3fe26a9ce8bf331435729bead762fb5c190064c6c5bb1b835 + original: lts-17.6