Skip to content

Commit

Permalink
build updates
Browse files Browse the repository at this point in the history
Try to build with more-modern systems. There's no functional change
here.
  • Loading branch information
DougBurke committed Jun 3, 2024
1 parent b757e2f commit dad7746
Show file tree
Hide file tree
Showing 6 changed files with 159 additions and 90 deletions.
53 changes: 25 additions & 28 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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/[email protected]
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/[email protected]
# 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: |
Expand All @@ -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/[email protected]
name: Cache ~/.stack
with:
path: ~/.stack
key: ${{ runner.os }}-${{ matrix.ghc }}-stack
# drop the cache for now
#- uses: actions/[email protected]
# name: Cache ~/.stack
# with:
# path: ~/.stack
# key: ${{ runner.os }}-${{ matrix.ghc }}-stack

- name: Install dependencies
run: |
Expand Down
48 changes: 48 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -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 '
'';
});
};
}
14 changes: 7 additions & 7 deletions nix/sources.json
Original file line number Diff line number Diff line change
Expand Up @@ -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/<owner>/<repo>/archive/<rev>.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/<owner>/<repo>/archive/<rev>.tar.gz"
}
}
118 changes: 71 additions & 47 deletions nix/sources.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -66,16 +87,16 @@ let
hasNixpkgsPath = builtins.any (x: x.prefix == "nixpkgs") builtins.nixPath;
hasThisAsNixpkgsPath = <nixpkgs> == ./.;
in
if builtins.hasAttr "nixpkgs" sources
then sourcesNixpkgs
else if hasNixpkgsPath && ! hasThisAsNixpkgsPath then
import <nixpkgs> {}
else
abort
''
Please specify either <nixpkgs> (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 <nixpkgs> { }
else
abort
''
Please specify either <nixpkgs> (through -I or NIX_PATH=nixpkgs=...) or
add a package called "nixpkgs" to your sources.json.
'';

# The actual fetching function.
fetch = pkgs: name: spec:
Expand All @@ -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

Expand All @@ -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));
Expand All @@ -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 {
Expand All @@ -171,4 +195,4 @@ let
};

in
mkSources (mkConfig {}) // { __functor = _: settings: mkSources (mkConfig settings); }
mkSources (mkConfig { }) // { __functor = _: settings: mkSources (mkConfig settings); }
2 changes: 1 addition & 1 deletion release.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{ sources ? import ./nix/sources.nix
, pkgs ? import sources.nixpkgs {}
, compiler ? "ghc8104"
, compiler ? "ghc96"
}:

let
Expand Down
14 changes: 7 additions & 7 deletions stack.yaml
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit dad7746

Please sign in to comment.