diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d690066..e3c56cf 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,49 +17,45 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - os: [ubuntu-latest, macOS-latest, windows-latest] + os: [ubuntu-latest] cabal: ["latest"] ghc: - # - "8.6.5" - - "8.8.3" - - "8.10.4" - - "9.0.1" - exclude: - - os: macOS-latest - ghc: 9.0.1 + - "8.10" + - "9.6" + - "9.10" + + include: - os: macOS-latest - ghc: 8.8.3 - #- os: macOS-latest - # ghc: 8.6.5 - - os: windows-latest - ghc: 9.0.1 + ghc: 9.6 - os: windows-latest - ghc: 8.8.3 + ghc: 9.6 steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 if: github.event.action == 'opened' || github.event.action == 'synchronize' || github.event.ref == 'refs/heads/main' - - uses: haskell/actions/setup@v1 + - uses: haskell-actions/setup@v2 id: setup-haskell-cabal name: Setup Haskell with: ghc-version: ${{ matrix.ghc }} cabal-version: ${{ matrix.cabal }} + cabal-update: true - name: Configure run: | - cabal configure --enable-tests --enable-benchmarks --test-show-details=direct + cabal configure --enable-tests --enable-benchmarks --test-show-details=direct # although we have no tests - name: Freeze run: | cabal freeze - - uses: actions/cache@v2.1.3 - name: Cache ~/.cabal/store - with: - path: ${{ steps.setup-haskell-cabal.outputs.cabal-store }} - key: ${{ runner.os }}-${{ matrix.ghc }}-${{ hashFiles('cabal.project.freeze') }} + # drop the cache for now + #- uses: actions/cache@v2.1.3 + # name: Cache ~/.cabal/store + # with: + # path: ${{ steps.setup-haskell-cabal.outputs.cabal-store }} + # key: ${{ runner.os }}-${{ matrix.ghc }}-${{ hashFiles('cabal.project.freeze') }} - name: Install dependencies run: | @@ -81,17 +77,18 @@ jobs: - uses: actions/checkout@v2 if: github.event.action == 'opened' || github.event.action == 'synchronize' || github.event.ref == 'refs/heads/main' - - uses: haskell/actions/setup@v1 + - uses: haskell-actions/setup@v2 name: Setup Haskell Stack with: ghc-version: ${{ matrix.ghc }} stack-version: ${{ matrix.stack }} - - uses: actions/cache@v2.1.3 - name: Cache ~/.stack - with: - path: ~/.stack - key: ${{ runner.os }}-${{ matrix.ghc }}-stack + # drop the cache for now + #- uses: actions/cache@v2.1.3 + # name: Cache ~/.stack + # with: + # path: ~/.stack + # key: ${{ runner.os }}-${{ matrix.ghc }}-stack - name: Install dependencies run: | diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..882757c --- /dev/null +++ b/flake.nix @@ -0,0 +1,48 @@ +{ + # inspired by: https://serokell.io/blog/practical-nix-flakes#packaging-existing-applications + description = "view Vega/Vega-Lite visualizations in a web browser"; + + inputs = { + nixpkgs.url = "nixpkgs"; + }; + + outputs = { self, nixpkgs }: + let + supportedSystems = [ "x86_64-linux" "x86_64-darwin" ]; + # supportedSystems = [ "x86_64-linux" ]; + forAllSystems = f: nixpkgs.lib.genAttrs supportedSystems (system: f system); + nixpkgsFor = forAllSystems (system: import nixpkgs { + inherit system; + overlays = [ self.overlay ]; + }); + in + { + overlay = (final: prev: { + vega-view = final.haskellPackages.callCabal2nix "vega-view" ./. {}; + }); + packages = forAllSystems (system: { + vega-view = nixpkgsFor.${system}.vega-view; + }); + defaultPackage = forAllSystems (system: self.packages.${system}.vega-view); + checks = self.packages; + devShell = forAllSystems (system: let haskellPackages = nixpkgsFor.${system}.haskellPackages; + in haskellPackages.shellFor { + packages = p: [self.packages.${system}.vega-view]; + withHoogle = true; + buildInputs = with haskellPackages; [ + haskell-language-server + hlint + cabal-install + ]; + # Change the prompt to show that you are in a devShell + shellHook = '' + echo -e "*** \e[1;32mWelcome to vega-view development\e[0m ***" + ghc --version + cabal --version + hlint --version + echo -e "" + export PS1='vega-view:\A \e[1;34m\w\e[0m ' + ''; + }); + }; +} diff --git a/nix/sources.json b/nix/sources.json index 454593c..fc78f15 100644 --- a/nix/sources.json +++ b/nix/sources.json @@ -5,22 +5,22 @@ "homepage": "https://github.com/nmattia/niv", "owner": "nmattia", "repo": "niv", - "rev": "e0ca65c81a2d7a4d82a189f1e23a48d59ad42070", - "sha256": "1pq9nh1d8nn3xvbdny8fafzw87mj7gsmp6pxkdl65w2g18rmcmzx", + "rev": "f7c538837892dd2eb83567c9f380a11efb59b53f", + "sha256": "0xl33k24vfc29cg9lnp95kvcq69qbq5fzb7jk9ig4lgrhaarh651", "type": "tarball", - "url": "https://github.com/nmattia/niv/archive/e0ca65c81a2d7a4d82a189f1e23a48d59ad42070.tar.gz", + "url": "https://github.com/nmattia/niv/archive/f7c538837892dd2eb83567c9f380a11efb59b53f.tar.gz", "url_template": "https://github.com///archive/.tar.gz" }, "nixpkgs": { - "branch": "release-21.05", + "branch": "release-24.05", "description": "Nix Packages collection", "homepage": "", "owner": "NixOS", "repo": "nixpkgs", - "rev": "0e03bcd64170e347a387211cb018f1ff9ea3d00d", - "sha256": "0x5bs9dh6431wybxs0558pdxlzv2bqs6n9i03g2a4893rb1jfmww", + "rev": "bbbedb870e36978f473c97dce801261014abf498", + "sha256": "0azx048alk7z7lqav67ha6rhk35vs8zhpd3w85050mxia18qphcf", "type": "tarball", - "url": "https://github.com/NixOS/nixpkgs/archive/0e03bcd64170e347a387211cb018f1ff9ea3d00d.tar.gz", + "url": "https://github.com/NixOS/nixpkgs/archive/bbbedb870e36978f473c97dce801261014abf498.tar.gz", "url_template": "https://github.com///archive/.tar.gz" } } diff --git a/nix/sources.nix b/nix/sources.nix index 1938409..fe3dadf 100644 --- a/nix/sources.nix +++ b/nix/sources.nix @@ -10,29 +10,50 @@ let let name' = sanitizeName name + "-src"; in - if spec.builtin or true then - builtins_fetchurl { inherit (spec) url sha256; name = name'; } - else - pkgs.fetchurl { inherit (spec) url sha256; name = name'; }; + if spec.builtin or true then + builtins_fetchurl { inherit (spec) url sha256; name = name'; } + else + pkgs.fetchurl { inherit (spec) url sha256; name = name'; }; fetch_tarball = pkgs: name: spec: let name' = sanitizeName name + "-src"; in - if spec.builtin or true then - builtins_fetchTarball { name = name'; inherit (spec) url sha256; } - else - pkgs.fetchzip { name = name'; inherit (spec) url sha256; }; + if spec.builtin or true then + builtins_fetchTarball { name = name'; inherit (spec) url sha256; } + else + pkgs.fetchzip { name = name'; inherit (spec) url sha256; }; fetch_git = name: spec: let ref = - if spec ? ref then spec.ref else + spec.ref or ( if spec ? branch then "refs/heads/${spec.branch}" else - if spec ? tag then "refs/tags/${spec.tag}" else - abort "In git source '${name}': Please specify `ref`, `tag` or `branch`!"; + if spec ? tag then "refs/tags/${spec.tag}" else + abort "In git source '${name}': Please specify `ref`, `tag` or `branch`!" + ); + submodules = spec.submodules or false; + submoduleArg = + let + nixSupportsSubmodules = builtins.compareVersions builtins.nixVersion "2.4" >= 0; + emptyArgWithWarning = + if submodules + then + builtins.trace + ( + "The niv input \"${name}\" uses submodules " + + "but your nix's (${builtins.nixVersion}) builtins.fetchGit " + + "does not support them" + ) + { } + else { }; + in + if nixSupportsSubmodules + then { inherit submodules; } + else emptyArgWithWarning; in - builtins.fetchGit { url = spec.repo; inherit (spec) rev; inherit ref; }; + builtins.fetchGit + ({ url = spec.repo; inherit (spec) rev; inherit ref; } // submoduleArg); fetch_local = spec: spec.path; @@ -66,16 +87,16 @@ let hasNixpkgsPath = builtins.any (x: x.prefix == "nixpkgs") builtins.nixPath; hasThisAsNixpkgsPath = == ./.; in - if builtins.hasAttr "nixpkgs" sources - then sourcesNixpkgs - else if hasNixpkgsPath && ! hasThisAsNixpkgsPath then - import {} - else - abort - '' - Please specify either (through -I or NIX_PATH=nixpkgs=...) or - add a package called "nixpkgs" to your sources.json. - ''; + if builtins.hasAttr "nixpkgs" sources + then sourcesNixpkgs + else if hasNixpkgsPath && ! hasThisAsNixpkgsPath then + import { } + else + abort + '' + Please specify either (through -I or NIX_PATH=nixpkgs=...) or + add a package called "nixpkgs" to your sources.json. + ''; # The actual fetching function. fetch = pkgs: name: spec: @@ -95,13 +116,13 @@ let # the path directly as opposed to the fetched source. replace = name: drv: let - saneName = stringAsChars (c: if isNull (builtins.match "[a-zA-Z0-9]" c) then "_" else c) name; + saneName = stringAsChars (c: if (builtins.match "[a-zA-Z0-9]" c) == null then "_" else c) name; ersatz = builtins.getEnv "NIV_OVERRIDE_${saneName}"; in - if ersatz == "" then drv else - # this turns the string into an actual Nix path (for both absolute and - # relative paths) - if builtins.substring 0 1 ersatz == "/" then /. + ersatz else /. + builtins.getEnv "PWD" + "/${ersatz}"; + if ersatz == "" then drv else + # this turns the string into an actual Nix path (for both absolute and + # relative paths) + if builtins.substring 0 1 ersatz == "/" then /. + ersatz else /. + builtins.getEnv "PWD" + "/${ersatz}"; # Ports of functions for older nix versions @@ -112,7 +133,7 @@ let ); # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/lists.nix#L295 - range = first: last: if first > last then [] else builtins.genList (n: first + n) (last - first + 1); + range = first: last: if first > last then [ ] else builtins.genList (n: first + n) (last - first + 1); # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/strings.nix#L257 stringToCharacters = s: map (p: builtins.substring p 1 s) (range 0 (builtins.stringLength s - 1)); @@ -123,43 +144,46 @@ let concatStrings = builtins.concatStringsSep ""; # https://github.com/NixOS/nixpkgs/blob/8a9f58a375c401b96da862d969f66429def1d118/lib/attrsets.nix#L331 - optionalAttrs = cond: as: if cond then as else {}; + optionalAttrs = cond: as: if cond then as else { }; # fetchTarball version that is compatible between all the versions of Nix builtins_fetchTarball = { url, name ? null, sha256 }@attrs: let inherit (builtins) lessThan nixVersion fetchTarball; in - if lessThan nixVersion "1.12" then - fetchTarball ({ inherit url; } // (optionalAttrs (!isNull name) { inherit name; })) - else - fetchTarball attrs; + if lessThan nixVersion "1.12" then + fetchTarball ({ inherit url; } // (optionalAttrs (name != null) { inherit name; })) + else + fetchTarball attrs; # fetchurl version that is compatible between all the versions of Nix builtins_fetchurl = { url, name ? null, sha256 }@attrs: let inherit (builtins) lessThan nixVersion fetchurl; in - if lessThan nixVersion "1.12" then - fetchurl ({ inherit url; } // (optionalAttrs (!isNull name) { inherit name; })) - else - fetchurl attrs; + if lessThan nixVersion "1.12" then + fetchurl ({ inherit url; } // (optionalAttrs (name != null) { inherit name; })) + else + fetchurl attrs; # Create the final "sources" from the config mkSources = config: - mapAttrs ( - name: spec: - if builtins.hasAttr "outPath" spec - then abort - "The values in sources.json should not have an 'outPath' attribute" - else - spec // { outPath = replace name (fetch config.pkgs name spec); } - ) config.sources; + mapAttrs + ( + name: spec: + if builtins.hasAttr "outPath" spec + then + abort + "The values in sources.json should not have an 'outPath' attribute" + else + spec // { outPath = replace name (fetch config.pkgs name spec); } + ) + config.sources; # The "config" used by the fetchers mkConfig = { sourcesFile ? if builtins.pathExists ./sources.json then ./sources.json else null - , sources ? if isNull sourcesFile then {} else builtins.fromJSON (builtins.readFile sourcesFile) + , sources ? if sourcesFile == null then { } else builtins.fromJSON (builtins.readFile sourcesFile) , system ? builtins.currentSystem , pkgs ? mkPkgs sources system }: rec { @@ -171,4 +195,4 @@ let }; in -mkSources (mkConfig {}) // { __functor = _: settings: mkSources (mkConfig settings); } +mkSources (mkConfig { }) // { __functor = _: settings: mkSources (mkConfig settings); } diff --git a/release.nix b/release.nix index 2c3b71a..0c6d009 100644 --- a/release.nix +++ b/release.nix @@ -1,6 +1,6 @@ { sources ? import ./nix/sources.nix , pkgs ? import sources.nixpkgs {} -, compiler ? "ghc8104" +, compiler ? "ghc96" }: let diff --git a/stack.yaml b/stack.yaml index 4bfddf4..59b4e69 100644 --- a/stack.yaml +++ b/stack.yaml @@ -1,11 +1,11 @@ -resolver: lts-18.13 +resolver: lts-22.24 packages: - . -extra-deps: -- aeson-2.0.1.0 -- semialign-1.2 -- time-compat-1.9.6.1 -- hashable-1.3.4.1 -- scotty-0.12 +#extra-deps: +#- aeson-2.1.2.1 +#- semialign-1.2 +#- time-compat-1.9.6.1 +#- hashable-1.3.4.1 +#- scotty-0.12