From 89e212ad5cbc62162dd48a48366378d2e127074b Mon Sep 17 00:00:00 2001 From: "lincoln auster [they/them]" Date: Tue, 12 Oct 2021 15:15:01 -0600 Subject: [PATCH 1/9] update naersk to ee7edec --- nix/sources.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/nix/sources.json b/nix/sources.json index cb81160..6294a81 100644 --- a/nix/sources.json +++ b/nix/sources.json @@ -29,10 +29,10 @@ "homepage": "", "owner": "nmattia", "repo": "naersk", - "rev": "dcee40445cfe301ced2d1b11290d6a94ff3aadb9", - "sha256": "0n9d1zirrhi9cr31kbxifrxkk52grbny04xnn1qhmvskyc11pcm4", + "rev": "ee7edec50b49ab6d69b06d62f1de554efccb1ccd", + "sha256": "06g37l34hzi81lc7hmk91mzapsa1iak7yi3agxgdzfc69qk9wp17", "type": "tarball", - "url": "https://github.com/nmattia/naersk/archive/dcee40445cfe301ced2d1b11290d6a94ff3aadb9.tar.gz", + "url": "https://github.com/nmattia/naersk/archive/ee7edec50b49ab6d69b06d62f1de554efccb1ccd.tar.gz", "url_template": "https://github.com///archive/.tar.gz" }, "niv": { From 2c9557234ce2f85c02e7e0b4a5e870db120800fe Mon Sep 17 00:00:00 2001 From: "lincoln auster [they/them]" Date: Tue, 12 Oct 2021 19:36:48 -0600 Subject: [PATCH 2/9] use nix flakes over Niv Pa'i and everything associated can now be compiled with: nix build --impure ...assuming that installed Nix version supports flakes. The `impure` is necessary as not everything down the dependency list is built with flakes, and there are some calls to `builtins.currentSystem`. Note that this currently only builds on x86_64-linux hosts. --- default.nix | 63 -------------------- docs/default.nix | 2 +- flake.lock | 115 ++++++++++++++++++++++++++++++++++++ flake.nix | 92 +++++++++++++++++++++++++++++ nix/dhall.nix | 5 -- nix/rust.nix | 9 --- nix/sources.json | 86 --------------------------- nix/sources.nix | 134 ------------------------------------------ olin-spec/default.nix | 3 +- tests/default.nix | 2 +- 10 files changed, 210 insertions(+), 301 deletions(-) delete mode 100644 default.nix create mode 100644 flake.lock create mode 100644 flake.nix delete mode 100644 nix/dhall.nix delete mode 100644 nix/rust.nix delete mode 100644 nix/sources.json delete mode 100644 nix/sources.nix diff --git a/default.nix b/default.nix deleted file mode 100644 index 055efd0..0000000 --- a/default.nix +++ /dev/null @@ -1,63 +0,0 @@ -{ sources ? import ./nix/sources.nix }: -let - rust = import ./nix/rust.nix { inherit sources; }; - pkgs = import sources.nixpkgs { }; - dhall = import ./nix/dhall.nix { inherit sources pkgs; }; - olin-cwa = import sources.olin { }; - naersk = pkgs.callPackage sources.naersk { - rustc = rust; - cargo = rust; - }; - name = "pahi"; - src = builtins.filterSource - (path: type: type != "directory" || builtins.baseNameOf path != "target") - ./.; - - pahi = naersk.buildPackage { - inherit name src; - buildInputs = [ pkgs.openssl pkgs.pkg-config ]; - }; - - olin = naersk.buildPackage { - name = "olin"; - src = ./wasm; - - buildInputs = [ olin-cwa ]; - doCheck = false; - }; - - olin-spec = import ./olin-spec { inherit pkgs sources; }; - docs = import ./docs { inherit pkgs sources; }; - pahi-testrunner = import ./tests { inherit pkgs sources; }; - - composite = pkgs.stdenv.mkDerivation { - version = "latest"; - phases = "installPhase"; - inherit name src; - - installPhase = '' - mkdir -p $out/docs/olin-spec - cp -rf ${docs}/docs $out - cp -rf ${olin-spec}/docs $out - mkdir -p $out/bin - cp -rf ${olin-cwa}/bin/cwa $out/bin - cp -rf ${pahi}/bin/pahi $out/bin - mkdir -p $out/wasm - - for f in ${olin}/bin/* - do - cp "$f" "$out/wasm/$(basename $f)".wasm - done - - cp -rf ${olin-cwa}/wasm/zig $out/wasm/zig - - cp -rf ${pahi-testrunner}/bin/tests $out/bin/testrunner - mkdir -p $out/tests - cp -rf ${pahi-testrunner}/tests/testdata.dhall $out/tests/testdata.dhall - cp -rf ${pahi-testrunner}/tests/bench.sh $out/tests/bench.sh - - cp $src/README.md $out/README.md - cp $src/LICENSE $out/LICENSE - ''; - }; -in composite diff --git a/docs/default.nix b/docs/default.nix index 5445160..136eaf8 100644 --- a/docs/default.nix +++ b/docs/default.nix @@ -1,4 +1,4 @@ -{ sources ? import ../nix/sources.nix, pkgs ? import sources.nixpkgs { }}: +{ pkgs }: let src = builtins.filterSource (path: type: type != "directory" || builtins.baseNameOf path != "olin-spec") diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..292b153 --- /dev/null +++ b/flake.lock @@ -0,0 +1,115 @@ +{ + "nodes": { + "dhall-lang": { + "flake": false, + "locked": { + "narHash": "sha256-4CHI3du+DpCeU6vdsirhyuvJXt/9Rl89EkdB//SKHKM=", + "type": "tarball", + "url": "https://github.com/dhall-lang/dhall-lang/archive/ccb9f5d54b0ecba05a6493e84442ce445e411e9e.tar.gz" + }, + "original": { + "type": "tarball", + "url": "https://github.com/dhall-lang/dhall-lang/archive/ccb9f5d54b0ecba05a6493e84442ce445e411e9e.tar.gz" + } + }, + "easy-dhall-nix": { + "flake": false, + "locked": { + "narHash": "sha256-r6cU2A2yqRzNkp000TdR5bTCIQGLvfOxiGh5uHjwGQ8=", + "type": "tarball", + "url": "https://github.com/justinwoo/easy-dhall-nix/archive/7c22a145fcb8e00b61d29efc7543af0c80d709ed.tar.gz" + }, + "original": { + "type": "tarball", + "url": "https://github.com/justinwoo/easy-dhall-nix/archive/7c22a145fcb8e00b61d29efc7543af0c80d709ed.tar.gz" + } + }, + "naersk": { + "inputs": { + "nixpkgs": "nixpkgs" + }, + "locked": { + "lastModified": 1632266297, + "narHash": "sha256-J1yeJk6Gud9ef2pEf6aKQemrfg1pVngYDSh+SAY94xk=", + "owner": "nix-community", + "repo": "naersk", + "rev": "ee7edec50b49ab6d69b06d62f1de554efccb1ccd", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "naersk", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1634073448, + "narHash": "sha256-e0z1FxOf6BrPUmzgUKlCLf+jA9aHAOT0pLFctHQveGo=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "5b5d681a0724cc351e84950e6ec92b22134c0e1a", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "type": "indirect" + } + }, + "nixpkgs-mozilla": { + "flake": false, + "locked": { + "lastModified": 1629225446, + "narHash": "sha256-HJX4Pc5ZUAg4apxB/XHuJ+6ukzvRQqeZMjscOBst2bA=", + "owner": "mozilla", + "repo": "nixpkgs-mozilla", + "rev": "0510159186dd2ef46e5464484fbdf119393afa58", + "type": "github" + }, + "original": { + "owner": "mozilla", + "repo": "nixpkgs-mozilla", + "type": "github" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1634073448, + "narHash": "sha256-e0z1FxOf6BrPUmzgUKlCLf+jA9aHAOT0pLFctHQveGo=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "5b5d681a0724cc351e84950e6ec92b22134c0e1a", + "type": "github" + }, + "original": { + "owner": "NixOS", + "repo": "nixpkgs", + "type": "github" + } + }, + "olin": { + "flake": false, + "locked": { + "narHash": "sha256-r8valcDgcyd9LiiW5I0spUTf4TbTycya2W1eQgjt0ZE=", + "type": "tarball", + "url": "https://github.com/Xe/olin/archive/0e8c8eea725307f8f396919cbf7f965a0d67b0e0.tar.gz" + }, + "original": { + "type": "tarball", + "url": "https://github.com/Xe/olin/archive/0e8c8eea725307f8f396919cbf7f965a0d67b0e0.tar.gz" + } + }, + "root": { + "inputs": { + "dhall-lang": "dhall-lang", + "easy-dhall-nix": "easy-dhall-nix", + "naersk": "naersk", + "nixpkgs": "nixpkgs_2", + "nixpkgs-mozilla": "nixpkgs-mozilla", + "olin": "olin" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..7ac3ec1 --- /dev/null +++ b/flake.nix @@ -0,0 +1,92 @@ +{ + description = "The next-generation Olin runtime, made with love"; + + inputs.dhall-lang.url = "https://github.com/dhall-lang/dhall-lang/archive/ccb9f5d54b0ecba05a6493e84442ce445e411e9e.tar.gz"; + inputs.dhall-lang.flake = false; + + inputs.easy-dhall-nix.url = "https://github.com/justinwoo/easy-dhall-nix/archive/7c22a145fcb8e00b61d29efc7543af0c80d709ed.tar.gz"; + inputs.easy-dhall-nix.flake = false; + + inputs.naersk.url = "github:nix-community/naersk"; + inputs.nixpkgs.url = "github:NixOS/nixpkgs"; + + inputs.nixpkgs-mozilla.url = "github:mozilla/nixpkgs-mozilla"; + inputs.nixpkgs-mozilla.flake = false; + + inputs.olin.url = "https://github.com/Xe/olin/archive/0e8c8eea725307f8f396919cbf7f965a0d67b0e0.tar.gz"; + inputs.olin.flake = false; + + outputs = { self, dhall-lang, easy-dhall-nix, naersk, nixpkgs, nixpkgs-mozilla, olin }: + let + pkgs = import nixpkgs { system = "x86_64-linux"; }; + naersk-lib = naersk.lib."x86_64-linux".override { rustc = rust; }; + + mozilla = pkgs.callPackage (nixpkgs-mozilla + "/package-set.nix") {}; + rust = let + channel = "nightly"; + date = "2020-07-27"; + targets = [ "wasm32-unknown-unknown" "wasm32-wasi" ]; + in mozilla.rustChannelOfTargets channel date targets; + + dhall = import easy-dhall-nix; + olin-cwa = import olin { }; + + olin-spec = import ./olin-spec { + inherit dhall-lang pkgs; + dhall = import easy-dhall-nix { inherit pkgs; }; + }; + + docs = import ./docs { inherit pkgs; }; + pahi-testrunner = import ./tests { inherit pkgs; }; + + olin-pkg = naersk-lib.buildPackage { + name = "olin"; + src = ./wasm; + + buildInputs = [ olin-cwa ]; + doCheck = false; + }; + + pahi = naersk-lib.buildPackage { + inherit name src; + buildInputs = [ pkgs.openssl pkgs.pkg-config ]; + }; + + name = "pahi"; + src = builtins.filterSource + (path: type: type != "directory" || builtins.baseNameOf path != "target") + ./.; + + in { + defaultPackage.x86_64-linux = pkgs.stdenv.mkDerivation { + version = "latest"; + phases = "buildPhase installPhase"; + inherit name src; + + installPhase = '' + mkdir -p $out/docs/olin-spec + cp -rf ${docs}/docs $out + cp -rf ${olin-spec}/docs $out + mkdir -p $out/bin + cp -rf ${olin-cwa}/bin/cwa $out/bin + cp -rf ${pahi}/bin/pahi $out/bin + mkdir -p $out/wasm + + for f in ${olin-pkg}/bin/* + do + cp "$f" "$out/wasm/$(basename $f)".wasm + done + + cp -rf ${olin-cwa}/wasm/zig $out/wasm/zig + + cp -rf ${pahi-testrunner}/bin/tests $out/bin/testrunner + mkdir -p $out/tests + cp -rf ${pahi-testrunner}/tests/testdata.dhall $out/tests/testdata.dhall + cp -rf ${pahi-testrunner}/tests/bench.sh $out/tests/bench.sh + + cp $src/README.md $out/README.md + cp $src/LICENSE $out/LICENSE + ''; + }; + }; +} diff --git a/nix/dhall.nix b/nix/dhall.nix deleted file mode 100644 index 2e12e25..0000000 --- a/nix/dhall.nix +++ /dev/null @@ -1,5 +0,0 @@ -let - sources = import ./sources.nix; - pkgs = import sources.nixpkgs { }; - dhall = import sources.easy-dhall-nix { inherit pkgs; }; -in dhall diff --git a/nix/rust.nix b/nix/rust.nix deleted file mode 100644 index 3b7f8ad..0000000 --- a/nix/rust.nix +++ /dev/null @@ -1,9 +0,0 @@ -{ sources ? import ./sources.nix }: - -let - pkgs = - import sources.nixpkgs { overlays = [ (import sources.nixpkgs-mozilla) ]; }; - channel = "nightly"; - date = "2020-07-27"; - targets = [ "wasm32-unknown-unknown" "wasm32-wasi" ]; -in pkgs.rustChannelOfTargets channel date targets diff --git a/nix/sources.json b/nix/sources.json deleted file mode 100644 index 6294a81..0000000 --- a/nix/sources.json +++ /dev/null @@ -1,86 +0,0 @@ -{ - "dhall-lang": { - "branch": "master", - "description": "Maintainable configuration files", - "homepage": "https://dhall-lang.org", - "owner": "dhall-lang", - "repo": "dhall-lang", - "rev": "ccb9f5d54b0ecba05a6493e84442ce445e411e9e", - "sha256": "18qwibsgyha728ymyipxvxgcksyaw4mb5pdbafg903myvgfwh8g0", - "type": "tarball", - "url": "https://github.com/dhall-lang/dhall-lang/archive/ccb9f5d54b0ecba05a6493e84442ce445e411e9e.tar.gz", - "url_template": "https://github.com///archive/.tar.gz" - }, - "easy-dhall-nix": { - "branch": "master", - "description": "Derivations for easily downloading Dhall binaries and putting them to use.", - "homepage": "", - "owner": "justinwoo", - "repo": "easy-dhall-nix", - "rev": "7c22a145fcb8e00b61d29efc7543af0c80d709ed", - "sha256": "03qry1wbhyb8i2qz7gcb04hw5d75a4vx2d4xjb6iradj1pc199xg", - "type": "tarball", - "url": "https://github.com/justinwoo/easy-dhall-nix/archive/7c22a145fcb8e00b61d29efc7543af0c80d709ed.tar.gz", - "url_template": "https://github.com///archive/.tar.gz" - }, - "naersk": { - "branch": "master", - "description": "Build rust crates in Nix. No configuration, no code generation. IFD and sandbox friendly.", - "homepage": "", - "owner": "nmattia", - "repo": "naersk", - "rev": "ee7edec50b49ab6d69b06d62f1de554efccb1ccd", - "sha256": "06g37l34hzi81lc7hmk91mzapsa1iak7yi3agxgdzfc69qk9wp17", - "type": "tarball", - "url": "https://github.com/nmattia/naersk/archive/ee7edec50b49ab6d69b06d62f1de554efccb1ccd.tar.gz", - "url_template": "https://github.com///archive/.tar.gz" - }, - "niv": { - "branch": "master", - "description": "Easy dependency management for Nix projects", - "homepage": "https://github.com/nmattia/niv", - "owner": "nmattia", - "repo": "niv", - "rev": "ab9cc41caf44d1f1d465d8028e4bc0096fd73238", - "sha256": "17k52n8zwp832cqifsc4458mhy4044wmk22f807171hf6p7l4xvr", - "type": "tarball", - "url": "https://github.com/nmattia/niv/archive/ab9cc41caf44d1f1d465d8028e4bc0096fd73238.tar.gz", - "url_template": "https://github.com///archive/.tar.gz" - }, - "nixpkgs": { - "branch": "nixpkgs-unstable", - "description": "A read-only mirror of NixOS/nixpkgs tracking the released channels. Send issues and PRs to", - "homepage": "https://github.com/NixOS/nixpkgs", - "owner": "NixOS", - "repo": "nixpkgs-channels", - "rev": "5ad1cdafe15d4ea79ae6abcddc360dd2de35b44e", - "sha256": "1nn602v3ssj79rxdfl3ical10c1d632vji9nv2h0dqslmycg4aws", - "type": "tarball", - "url": "https://github.com/NixOS/nixpkgs-channels/archive/5ad1cdafe15d4ea79ae6abcddc360dd2de35b44e.tar.gz", - "url_template": "https://github.com///archive/.tar.gz" - }, - "nixpkgs-mozilla": { - "branch": "master", - "description": "mozilla related nixpkgs (extends nixos/nixpkgs repo)", - "homepage": null, - "owner": "mozilla", - "repo": "nixpkgs-mozilla", - "rev": "efda5b357451dbb0431f983cca679ae3cd9b9829", - "sha256": "11wqrg86g3qva67vnk81ynvqyfj0zxk83cbrf0p9hsvxiwxs8469", - "type": "tarball", - "url": "https://github.com/mozilla/nixpkgs-mozilla/archive/efda5b357451dbb0431f983cca679ae3cd9b9829.tar.gz", - "url_template": "https://github.com///archive/.tar.gz" - }, - "olin": { - "branch": "master", - "description": "Webassembly + Event Sourcing", - "homepage": "", - "owner": "Xe", - "repo": "olin", - "rev": "0e8c8eea725307f8f396919cbf7f965a0d67b0e0", - "sha256": "14fixl444pkdv6dcrjfk6vhxyi555j6y95i85ryjfwz0q2axmjxg", - "type": "tarball", - "url": "https://github.com/Xe/olin/archive/0e8c8eea725307f8f396919cbf7f965a0d67b0e0.tar.gz", - "url_template": "https://github.com///archive/.tar.gz" - } -} diff --git a/nix/sources.nix b/nix/sources.nix deleted file mode 100644 index 8a725cb..0000000 --- a/nix/sources.nix +++ /dev/null @@ -1,134 +0,0 @@ -# This file has been generated by Niv. - -let - - # - # The fetchers. fetch_ fetches specs of type . - # - - fetch_file = pkgs: spec: - if spec.builtin or true then - builtins_fetchurl { inherit (spec) url sha256; } - else - pkgs.fetchurl { inherit (spec) url sha256; }; - - fetch_tarball = pkgs: spec: - if spec.builtin or true then - builtins_fetchTarball { inherit (spec) url sha256; } - else - pkgs.fetchzip { inherit (spec) url sha256; }; - - fetch_git = spec: - builtins.fetchGit { url = spec.repo; inherit (spec) rev ref; }; - - fetch_builtin-tarball = spec: - builtins.trace - '' - WARNING: - The niv type "builtin-tarball" will soon be deprecated. You should - instead use `builtin = true`. - - $ niv modify -a type=tarball -a builtin=true - '' - builtins_fetchTarball { inherit (spec) url sha256; }; - - fetch_builtin-url = spec: - builtins.trace - '' - WARNING: - The niv type "builtin-url" will soon be deprecated. You should - instead use `builtin = true`. - - $ niv modify -a type=file -a builtin=true - '' - (builtins_fetchurl { inherit (spec) url sha256; }); - - # - # Various helpers - # - - # The set of packages used when specs are fetched using non-builtins. - mkPkgs = sources: - let - sourcesNixpkgs = - import (builtins_fetchTarball { inherit (sources.nixpkgs) url sha256; }) {}; - 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. - ''; - - # The actual fetching function. - fetch = pkgs: name: spec: - - if ! builtins.hasAttr "type" spec then - abort "ERROR: niv spec ${name} does not have a 'type' attribute" - else if spec.type == "file" then fetch_file pkgs spec - else if spec.type == "tarball" then fetch_tarball pkgs spec - else if spec.type == "git" then fetch_git spec - else if spec.type == "builtin-tarball" then fetch_builtin-tarball spec - else if spec.type == "builtin-url" then fetch_builtin-url spec - else - abort "ERROR: niv spec ${name} has unknown type ${builtins.toJSON spec.type}"; - - # Ports of functions for older nix versions - - # a Nix version of mapAttrs if the built-in doesn't exist - mapAttrs = builtins.mapAttrs or ( - f: set: with builtins; - listToAttrs (map (attr: { name = attr; value = f attr set.${attr}; }) (attrNames set)) - ); - - # fetchTarball version that is compatible between all the versions of Nix - builtins_fetchTarball = { url, sha256 }@attrs: - let - inherit (builtins) lessThan nixVersion fetchTarball; - in - if lessThan nixVersion "1.12" then - fetchTarball { inherit url; } - else - fetchTarball attrs; - - # fetchurl version that is compatible between all the versions of Nix - builtins_fetchurl = { url, sha256 }@attrs: - let - inherit (builtins) lessThan nixVersion fetchurl; - in - if lessThan nixVersion "1.12" then - fetchurl { inherit url; } - 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 = fetch config.pkgs name spec; } - ) config.sources; - - # The "config" used by the fetchers - mkConfig = - { sourcesFile ? ./sources.json - , sources ? builtins.fromJSON (builtins.readFile sourcesFile) - , pkgs ? mkPkgs sources - }: rec { - # The sources, i.e. the attribute set of spec name to spec - inherit sources; - - # The "pkgs" (evaluated nixpkgs) to use for e.g. non-builtin fetchers - inherit pkgs; - }; -in -mkSources (mkConfig {}) // { __functor = _: settings: mkSources (mkConfig settings); } diff --git a/olin-spec/default.nix b/olin-spec/default.nix index 62beeaa..515c9fc 100644 --- a/olin-spec/default.nix +++ b/olin-spec/default.nix @@ -1,5 +1,4 @@ -{ sources ? import ../nix/sources.nix, pkgs ? import sources.nixpkgs { } -, dhall-lang ? sources.dhall-lang, dhall ? import ../nix/dhall.nix }: +{ pkgs, dhall-lang, dhall }: pkgs.stdenv.mkDerivation rec { name = "olin-spec"; version = "latest"; diff --git a/tests/default.nix b/tests/default.nix index 0927752..c0e3aad 100644 --- a/tests/default.nix +++ b/tests/default.nix @@ -1,4 +1,4 @@ -{ sources ? import ../nix/sources.nix, pkgs ? import sources.nixpkgs { } }: +{ pkgs }: with pkgs; buildGoPackage { name = "pahi-tests"; From 0c80fee8adfcd4bde0785700ef54fa947427bd63 Mon Sep 17 00:00:00 2001 From: "lincoln auster [they/them]" Date: Wed, 13 Oct 2021 09:34:33 -0600 Subject: [PATCH 3/9] replace shell.nix with a flake output A dev-shell can be started with `nix shell --impure`. Note that `--impure` is necessary for the same reasons as the build --- see 2c95572. --- flake.nix | 19 +++++++++++++++++++ shell.nix | 35 ----------------------------------- 2 files changed, 19 insertions(+), 35 deletions(-) delete mode 100644 shell.nix diff --git a/flake.nix b/flake.nix index 7ac3ec1..4a0a2a7 100644 --- a/flake.nix +++ b/flake.nix @@ -29,8 +29,10 @@ in mozilla.rustChannelOfTargets channel date targets; dhall = import easy-dhall-nix; + dhall-lang-pkg = import dhall-lang { inherit pkgs; }; olin-cwa = import olin { }; + olin-spec = import ./olin-spec { inherit dhall-lang pkgs; dhall = import easy-dhall-nix { inherit pkgs; }; @@ -88,5 +90,22 @@ cp $src/LICENSE $out/LICENSE ''; }; + + devShell.x86_64-linux = pkgs.mkShell { + buildInputs = [ + rust + + pkgs.hyperfine + + pkgs.openssl + pkgs.pkg-config + + dhall-lang-pkg + dhall + + pkgs.go + olin + ]; + }; }; } diff --git a/shell.nix b/shell.nix deleted file mode 100644 index d0f54aa..0000000 --- a/shell.nix +++ /dev/null @@ -1,35 +0,0 @@ -let - sources = import ./nix/sources.nix; - niv = import sources.niv { }; - pkgs = import sources.nixpkgs { }; - olin = import sources.olin { inherit pkgs; }; - rust = import ./nix/rust.nix { inherit sources; }; - dhall = import ./nix/dhall.nix; -in pkgs.mkShell { - buildInputs = [ - rust - - # benchmarks - pkgs.hyperfine - - # dependency management - niv.niv - - # native dependencies - pkgs.openssl - pkgs.pkg-config - - # olin-docs - dhall.dhall-simple - sources.dhall-lang - - # tests - pkgs.go - olin - ]; - nativeBuildInputs = [ pkgs.removeReferencesTo ]; - - # envvars - RUST_LOG = "pahi=error,pahi_olin=debug"; - MAGIC_CONCH = "yes"; -} From 95eafcf18c8211f4972920a20203b9db28948a4f Mon Sep 17 00:00:00 2001 From: "lincoln auster [they/them]" Date: Thu, 14 Oct 2021 22:04:42 -0600 Subject: [PATCH 4/9] replace docker.nix with a flake output This wraps the existing script into a derivation which writes the image to $out/docker, and can be built with nix build .#docker --- docker.nix | 31 ------------------------------- flake.nix | 31 ++++++++++++++++++++++++++++++- 2 files changed, 30 insertions(+), 32 deletions(-) delete mode 100644 docker.nix diff --git a/docker.nix b/docker.nix deleted file mode 100644 index 847c865..0000000 --- a/docker.nix +++ /dev/null @@ -1,31 +0,0 @@ -{ system ? builtins.currentSystem }: - -let - sources = import ./nix/sources.nix; - pkgs = import sources.nixpkgs { }; - dhall = import ./nix/dhall.nix; - callPackage = pkgs.lib.callPackageWith pkgs; - pahi = callPackage ./default.nix { }; - - dockerImage = pkg: - pkgs.dockerTools.buildLayeredImage { - name = "xena/pahi"; - tag = "latest"; - - contents = [ - pkg - pkgs.bash - pkgs.cacert - pkgs.coreutils - pkgs.hyperfine - dhall.dhall-json-simple - ]; - - config = { - Cmd = [ "/bin/bash" ]; - WorkingDir = "/"; - Env = [ "NIX_SSL_CERT_FILE=/etc/ssl/certs/ca-bundle.crt" ]; - }; - }; - -in dockerImage pahi diff --git a/flake.nix b/flake.nix index 4a0a2a7..148339e 100644 --- a/flake.nix +++ b/flake.nix @@ -28,7 +28,7 @@ targets = [ "wasm32-unknown-unknown" "wasm32-wasi" ]; in mozilla.rustChannelOfTargets channel date targets; - dhall = import easy-dhall-nix; + dhall = import easy-dhall-nix { inherit pkgs; }; dhall-lang-pkg = import dhall-lang { inherit pkgs; }; olin-cwa = import olin { }; @@ -107,5 +107,34 @@ olin ]; }; + + packages.x86_64-linux.docker = let + img = pkgs.dockerTools.buildLayeredImage { + name = "xena/pahi"; + tag = "latest"; + + contents = [ self.defaultPackage.x86_64-linux # pahi + pkgs.bash pkgs.coreutils pkgs.cacert pkgs.hyperfine + dhall.dhall-json-simple ]; + + config = { + Cmd = [ "/bin/bash" ]; + WorkingDir = "/"; + Env = [ "NIX_SSL_CERT_FILE=/etc/ssl/certs/ca-bundle.crt" ]; + }; + }; + in pkgs.stdenv.mkDerivation { + name = "pahi-docker"; + version = "latest"; + src = ./.; # this is a bit of a lie, but it works + + installPhase = '' + mkdir -p $out/docker/ + cp ${img} $out/docker/ + ''; + + doConfigure = false; + doBuild = false; + }; }; } From 56a0ff78731be64e80f8cb27cdee3bde28daf8f6 Mon Sep 17 00:00:00 2001 From: "lincoln auster [they/them]" Date: Tue, 12 Oct 2021 19:36:48 -0600 Subject: [PATCH 5/9] use Nix Flakes over Niv Pa'i and everything associated can be compiled with: nix build --impure shell.nix has been replace with Nix's inferences from the default package output. It can be accessed with: nix shell --impure docker.nix has been replaced with a *derivation* that wraps buildLayeredImage. It installs the image to $out/docker/, and can be built with: nix build .#docker --impure All of the above commands assume that the installed Nix version supports flakes. The `impure` option is necessary as not everything down the dependency list is built with flakes, and there are some impure/non-hermetic calls to `builtins.currentSystem`. Note that this currently only builds on x86_64-linux hosts. I don't have any other kernels or architectures to test with on-hand, so I can't verify build correctness for anything else --- this is *technically* the proper behavior for Flakes. --- default.nix | 63 -------------------- docker.nix | 31 ---------- docs/default.nix | 2 +- flake.lock | 115 ++++++++++++++++++++++++++++++++++++ flake.nix | 123 ++++++++++++++++++++++++++++++++++++++ nix/dhall.nix | 5 -- nix/rust.nix | 9 --- nix/sources.json | 86 --------------------------- nix/sources.nix | 134 ------------------------------------------ olin-spec/default.nix | 3 +- shell.nix | 35 ----------- tests/default.nix | 2 +- 12 files changed, 241 insertions(+), 367 deletions(-) delete mode 100644 default.nix delete mode 100644 docker.nix create mode 100644 flake.lock create mode 100644 flake.nix delete mode 100644 nix/dhall.nix delete mode 100644 nix/rust.nix delete mode 100644 nix/sources.json delete mode 100644 nix/sources.nix delete mode 100644 shell.nix diff --git a/default.nix b/default.nix deleted file mode 100644 index 055efd0..0000000 --- a/default.nix +++ /dev/null @@ -1,63 +0,0 @@ -{ sources ? import ./nix/sources.nix }: -let - rust = import ./nix/rust.nix { inherit sources; }; - pkgs = import sources.nixpkgs { }; - dhall = import ./nix/dhall.nix { inherit sources pkgs; }; - olin-cwa = import sources.olin { }; - naersk = pkgs.callPackage sources.naersk { - rustc = rust; - cargo = rust; - }; - name = "pahi"; - src = builtins.filterSource - (path: type: type != "directory" || builtins.baseNameOf path != "target") - ./.; - - pahi = naersk.buildPackage { - inherit name src; - buildInputs = [ pkgs.openssl pkgs.pkg-config ]; - }; - - olin = naersk.buildPackage { - name = "olin"; - src = ./wasm; - - buildInputs = [ olin-cwa ]; - doCheck = false; - }; - - olin-spec = import ./olin-spec { inherit pkgs sources; }; - docs = import ./docs { inherit pkgs sources; }; - pahi-testrunner = import ./tests { inherit pkgs sources; }; - - composite = pkgs.stdenv.mkDerivation { - version = "latest"; - phases = "installPhase"; - inherit name src; - - installPhase = '' - mkdir -p $out/docs/olin-spec - cp -rf ${docs}/docs $out - cp -rf ${olin-spec}/docs $out - mkdir -p $out/bin - cp -rf ${olin-cwa}/bin/cwa $out/bin - cp -rf ${pahi}/bin/pahi $out/bin - mkdir -p $out/wasm - - for f in ${olin}/bin/* - do - cp "$f" "$out/wasm/$(basename $f)".wasm - done - - cp -rf ${olin-cwa}/wasm/zig $out/wasm/zig - - cp -rf ${pahi-testrunner}/bin/tests $out/bin/testrunner - mkdir -p $out/tests - cp -rf ${pahi-testrunner}/tests/testdata.dhall $out/tests/testdata.dhall - cp -rf ${pahi-testrunner}/tests/bench.sh $out/tests/bench.sh - - cp $src/README.md $out/README.md - cp $src/LICENSE $out/LICENSE - ''; - }; -in composite diff --git a/docker.nix b/docker.nix deleted file mode 100644 index 847c865..0000000 --- a/docker.nix +++ /dev/null @@ -1,31 +0,0 @@ -{ system ? builtins.currentSystem }: - -let - sources = import ./nix/sources.nix; - pkgs = import sources.nixpkgs { }; - dhall = import ./nix/dhall.nix; - callPackage = pkgs.lib.callPackageWith pkgs; - pahi = callPackage ./default.nix { }; - - dockerImage = pkg: - pkgs.dockerTools.buildLayeredImage { - name = "xena/pahi"; - tag = "latest"; - - contents = [ - pkg - pkgs.bash - pkgs.cacert - pkgs.coreutils - pkgs.hyperfine - dhall.dhall-json-simple - ]; - - config = { - Cmd = [ "/bin/bash" ]; - WorkingDir = "/"; - Env = [ "NIX_SSL_CERT_FILE=/etc/ssl/certs/ca-bundle.crt" ]; - }; - }; - -in dockerImage pahi diff --git a/docs/default.nix b/docs/default.nix index 5445160..136eaf8 100644 --- a/docs/default.nix +++ b/docs/default.nix @@ -1,4 +1,4 @@ -{ sources ? import ../nix/sources.nix, pkgs ? import sources.nixpkgs { }}: +{ pkgs }: let src = builtins.filterSource (path: type: type != "directory" || builtins.baseNameOf path != "olin-spec") diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..292b153 --- /dev/null +++ b/flake.lock @@ -0,0 +1,115 @@ +{ + "nodes": { + "dhall-lang": { + "flake": false, + "locked": { + "narHash": "sha256-4CHI3du+DpCeU6vdsirhyuvJXt/9Rl89EkdB//SKHKM=", + "type": "tarball", + "url": "https://github.com/dhall-lang/dhall-lang/archive/ccb9f5d54b0ecba05a6493e84442ce445e411e9e.tar.gz" + }, + "original": { + "type": "tarball", + "url": "https://github.com/dhall-lang/dhall-lang/archive/ccb9f5d54b0ecba05a6493e84442ce445e411e9e.tar.gz" + } + }, + "easy-dhall-nix": { + "flake": false, + "locked": { + "narHash": "sha256-r6cU2A2yqRzNkp000TdR5bTCIQGLvfOxiGh5uHjwGQ8=", + "type": "tarball", + "url": "https://github.com/justinwoo/easy-dhall-nix/archive/7c22a145fcb8e00b61d29efc7543af0c80d709ed.tar.gz" + }, + "original": { + "type": "tarball", + "url": "https://github.com/justinwoo/easy-dhall-nix/archive/7c22a145fcb8e00b61d29efc7543af0c80d709ed.tar.gz" + } + }, + "naersk": { + "inputs": { + "nixpkgs": "nixpkgs" + }, + "locked": { + "lastModified": 1632266297, + "narHash": "sha256-J1yeJk6Gud9ef2pEf6aKQemrfg1pVngYDSh+SAY94xk=", + "owner": "nix-community", + "repo": "naersk", + "rev": "ee7edec50b49ab6d69b06d62f1de554efccb1ccd", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "naersk", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1634073448, + "narHash": "sha256-e0z1FxOf6BrPUmzgUKlCLf+jA9aHAOT0pLFctHQveGo=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "5b5d681a0724cc351e84950e6ec92b22134c0e1a", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "type": "indirect" + } + }, + "nixpkgs-mozilla": { + "flake": false, + "locked": { + "lastModified": 1629225446, + "narHash": "sha256-HJX4Pc5ZUAg4apxB/XHuJ+6ukzvRQqeZMjscOBst2bA=", + "owner": "mozilla", + "repo": "nixpkgs-mozilla", + "rev": "0510159186dd2ef46e5464484fbdf119393afa58", + "type": "github" + }, + "original": { + "owner": "mozilla", + "repo": "nixpkgs-mozilla", + "type": "github" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1634073448, + "narHash": "sha256-e0z1FxOf6BrPUmzgUKlCLf+jA9aHAOT0pLFctHQveGo=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "5b5d681a0724cc351e84950e6ec92b22134c0e1a", + "type": "github" + }, + "original": { + "owner": "NixOS", + "repo": "nixpkgs", + "type": "github" + } + }, + "olin": { + "flake": false, + "locked": { + "narHash": "sha256-r8valcDgcyd9LiiW5I0spUTf4TbTycya2W1eQgjt0ZE=", + "type": "tarball", + "url": "https://github.com/Xe/olin/archive/0e8c8eea725307f8f396919cbf7f965a0d67b0e0.tar.gz" + }, + "original": { + "type": "tarball", + "url": "https://github.com/Xe/olin/archive/0e8c8eea725307f8f396919cbf7f965a0d67b0e0.tar.gz" + } + }, + "root": { + "inputs": { + "dhall-lang": "dhall-lang", + "easy-dhall-nix": "easy-dhall-nix", + "naersk": "naersk", + "nixpkgs": "nixpkgs_2", + "nixpkgs-mozilla": "nixpkgs-mozilla", + "olin": "olin" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..ed5ab7d --- /dev/null +++ b/flake.nix @@ -0,0 +1,123 @@ +{ + description = "The next-generation Olin runtime, made with love"; + + inputs.dhall-lang.url = "https://github.com/dhall-lang/dhall-lang/archive/ccb9f5d54b0ecba05a6493e84442ce445e411e9e.tar.gz"; + inputs.dhall-lang.flake = false; + + inputs.easy-dhall-nix.url = "https://github.com/justinwoo/easy-dhall-nix/archive/7c22a145fcb8e00b61d29efc7543af0c80d709ed.tar.gz"; + inputs.easy-dhall-nix.flake = false; + + inputs.naersk.url = "github:nix-community/naersk"; + inputs.nixpkgs.url = "github:NixOS/nixpkgs"; + + inputs.nixpkgs-mozilla.url = "github:mozilla/nixpkgs-mozilla"; + inputs.nixpkgs-mozilla.flake = false; + + inputs.olin.url = "https://github.com/Xe/olin/archive/0e8c8eea725307f8f396919cbf7f965a0d67b0e0.tar.gz"; + inputs.olin.flake = false; + + outputs = { self, dhall-lang, easy-dhall-nix, naersk, nixpkgs, nixpkgs-mozilla, olin }: + let + pkgs = import nixpkgs { system = "x86_64-linux"; }; + naersk-lib = naersk.lib."x86_64-linux".override { rustc = rust; }; + + mozilla = pkgs.callPackage (nixpkgs-mozilla + "/package-set.nix") {}; + rust = let + channel = "nightly"; + date = "2020-07-27"; + targets = [ "wasm32-unknown-unknown" "wasm32-wasi" ]; + in mozilla.rustChannelOfTargets channel date targets; + + dhall = import easy-dhall-nix { inherit pkgs; }; + dhall-lang-pkg = import dhall-lang { inherit pkgs; }; + olin-cwa = import olin { }; + + + olin-spec = import ./olin-spec { + inherit dhall-lang pkgs; + dhall = import easy-dhall-nix { inherit pkgs; }; + }; + + docs = import ./docs { inherit pkgs; }; + pahi-testrunner = import ./tests { inherit pkgs; }; + + olin-pkg = naersk-lib.buildPackage { + name = "olin"; + src = ./wasm; + + buildInputs = [ olin-cwa ]; + doCheck = false; + }; + + pahi = naersk-lib.buildPackage { + inherit name src; + buildInputs = [ pkgs.openssl pkgs.pkg-config ]; + }; + + name = "pahi"; + src = builtins.filterSource + (path: type: type != "directory" || builtins.baseNameOf path != "target") + ./.; + + in { + defaultPackage.x86_64-linux = pkgs.stdenv.mkDerivation { + version = "latest"; + phases = "buildPhase installPhase"; + inherit name src; + + installPhase = '' + mkdir -p $out/docs/olin-spec + cp -rf ${docs}/docs $out + cp -rf ${olin-spec}/docs $out + mkdir -p $out/bin + cp -rf ${olin-cwa}/bin/cwa $out/bin + cp -rf ${pahi}/bin/pahi $out/bin + mkdir -p $out/wasm + + for f in ${olin-pkg}/bin/* + do + cp "$f" "$out/wasm/$(basename $f)".wasm + done + + cp -rf ${olin-cwa}/wasm/zig $out/wasm/zig + + cp -rf ${pahi-testrunner}/bin/tests $out/bin/testrunner + mkdir -p $out/tests + cp -rf ${pahi-testrunner}/tests/testdata.dhall $out/tests/testdata.dhall + cp -rf ${pahi-testrunner}/tests/bench.sh $out/tests/bench.sh + + cp $src/README.md $out/README.md + cp $src/LICENSE $out/LICENSE + ''; + }; + + packages.x86_64-linux.docker = let + img = pkgs.dockerTools.buildLayeredImage { + name = "xena/pahi"; + tag = "latest"; + + contents = [ self.defaultPackage.x86_64-linux # pahi + pkgs.bash pkgs.coreutils pkgs.cacert pkgs.hyperfine + dhall.dhall-json-simple ]; + + config = { + Cmd = [ "/bin/bash" ]; + WorkingDir = "/"; + Env = [ "NIX_SSL_CERT_FILE=/etc/ssl/certs/ca-bundle.crt" ]; + }; + }; + in pkgs.stdenv.mkDerivation { + name = "pahi-docker"; + version = "latest"; + src = ./.; # this is a bit of a lie, but it works + + installPhase = '' + mkdir -p $out/docker/ + cp ${img} $out/docker/ + ''; + + doConfigure = false; + doBuild = false; + }; + }; +} diff --git a/nix/dhall.nix b/nix/dhall.nix deleted file mode 100644 index 2e12e25..0000000 --- a/nix/dhall.nix +++ /dev/null @@ -1,5 +0,0 @@ -let - sources = import ./sources.nix; - pkgs = import sources.nixpkgs { }; - dhall = import sources.easy-dhall-nix { inherit pkgs; }; -in dhall diff --git a/nix/rust.nix b/nix/rust.nix deleted file mode 100644 index 3b7f8ad..0000000 --- a/nix/rust.nix +++ /dev/null @@ -1,9 +0,0 @@ -{ sources ? import ./sources.nix }: - -let - pkgs = - import sources.nixpkgs { overlays = [ (import sources.nixpkgs-mozilla) ]; }; - channel = "nightly"; - date = "2020-07-27"; - targets = [ "wasm32-unknown-unknown" "wasm32-wasi" ]; -in pkgs.rustChannelOfTargets channel date targets diff --git a/nix/sources.json b/nix/sources.json deleted file mode 100644 index 6294a81..0000000 --- a/nix/sources.json +++ /dev/null @@ -1,86 +0,0 @@ -{ - "dhall-lang": { - "branch": "master", - "description": "Maintainable configuration files", - "homepage": "https://dhall-lang.org", - "owner": "dhall-lang", - "repo": "dhall-lang", - "rev": "ccb9f5d54b0ecba05a6493e84442ce445e411e9e", - "sha256": "18qwibsgyha728ymyipxvxgcksyaw4mb5pdbafg903myvgfwh8g0", - "type": "tarball", - "url": "https://github.com/dhall-lang/dhall-lang/archive/ccb9f5d54b0ecba05a6493e84442ce445e411e9e.tar.gz", - "url_template": "https://github.com///archive/.tar.gz" - }, - "easy-dhall-nix": { - "branch": "master", - "description": "Derivations for easily downloading Dhall binaries and putting them to use.", - "homepage": "", - "owner": "justinwoo", - "repo": "easy-dhall-nix", - "rev": "7c22a145fcb8e00b61d29efc7543af0c80d709ed", - "sha256": "03qry1wbhyb8i2qz7gcb04hw5d75a4vx2d4xjb6iradj1pc199xg", - "type": "tarball", - "url": "https://github.com/justinwoo/easy-dhall-nix/archive/7c22a145fcb8e00b61d29efc7543af0c80d709ed.tar.gz", - "url_template": "https://github.com///archive/.tar.gz" - }, - "naersk": { - "branch": "master", - "description": "Build rust crates in Nix. No configuration, no code generation. IFD and sandbox friendly.", - "homepage": "", - "owner": "nmattia", - "repo": "naersk", - "rev": "ee7edec50b49ab6d69b06d62f1de554efccb1ccd", - "sha256": "06g37l34hzi81lc7hmk91mzapsa1iak7yi3agxgdzfc69qk9wp17", - "type": "tarball", - "url": "https://github.com/nmattia/naersk/archive/ee7edec50b49ab6d69b06d62f1de554efccb1ccd.tar.gz", - "url_template": "https://github.com///archive/.tar.gz" - }, - "niv": { - "branch": "master", - "description": "Easy dependency management for Nix projects", - "homepage": "https://github.com/nmattia/niv", - "owner": "nmattia", - "repo": "niv", - "rev": "ab9cc41caf44d1f1d465d8028e4bc0096fd73238", - "sha256": "17k52n8zwp832cqifsc4458mhy4044wmk22f807171hf6p7l4xvr", - "type": "tarball", - "url": "https://github.com/nmattia/niv/archive/ab9cc41caf44d1f1d465d8028e4bc0096fd73238.tar.gz", - "url_template": "https://github.com///archive/.tar.gz" - }, - "nixpkgs": { - "branch": "nixpkgs-unstable", - "description": "A read-only mirror of NixOS/nixpkgs tracking the released channels. Send issues and PRs to", - "homepage": "https://github.com/NixOS/nixpkgs", - "owner": "NixOS", - "repo": "nixpkgs-channels", - "rev": "5ad1cdafe15d4ea79ae6abcddc360dd2de35b44e", - "sha256": "1nn602v3ssj79rxdfl3ical10c1d632vji9nv2h0dqslmycg4aws", - "type": "tarball", - "url": "https://github.com/NixOS/nixpkgs-channels/archive/5ad1cdafe15d4ea79ae6abcddc360dd2de35b44e.tar.gz", - "url_template": "https://github.com///archive/.tar.gz" - }, - "nixpkgs-mozilla": { - "branch": "master", - "description": "mozilla related nixpkgs (extends nixos/nixpkgs repo)", - "homepage": null, - "owner": "mozilla", - "repo": "nixpkgs-mozilla", - "rev": "efda5b357451dbb0431f983cca679ae3cd9b9829", - "sha256": "11wqrg86g3qva67vnk81ynvqyfj0zxk83cbrf0p9hsvxiwxs8469", - "type": "tarball", - "url": "https://github.com/mozilla/nixpkgs-mozilla/archive/efda5b357451dbb0431f983cca679ae3cd9b9829.tar.gz", - "url_template": "https://github.com///archive/.tar.gz" - }, - "olin": { - "branch": "master", - "description": "Webassembly + Event Sourcing", - "homepage": "", - "owner": "Xe", - "repo": "olin", - "rev": "0e8c8eea725307f8f396919cbf7f965a0d67b0e0", - "sha256": "14fixl444pkdv6dcrjfk6vhxyi555j6y95i85ryjfwz0q2axmjxg", - "type": "tarball", - "url": "https://github.com/Xe/olin/archive/0e8c8eea725307f8f396919cbf7f965a0d67b0e0.tar.gz", - "url_template": "https://github.com///archive/.tar.gz" - } -} diff --git a/nix/sources.nix b/nix/sources.nix deleted file mode 100644 index 8a725cb..0000000 --- a/nix/sources.nix +++ /dev/null @@ -1,134 +0,0 @@ -# This file has been generated by Niv. - -let - - # - # The fetchers. fetch_ fetches specs of type . - # - - fetch_file = pkgs: spec: - if spec.builtin or true then - builtins_fetchurl { inherit (spec) url sha256; } - else - pkgs.fetchurl { inherit (spec) url sha256; }; - - fetch_tarball = pkgs: spec: - if spec.builtin or true then - builtins_fetchTarball { inherit (spec) url sha256; } - else - pkgs.fetchzip { inherit (spec) url sha256; }; - - fetch_git = spec: - builtins.fetchGit { url = spec.repo; inherit (spec) rev ref; }; - - fetch_builtin-tarball = spec: - builtins.trace - '' - WARNING: - The niv type "builtin-tarball" will soon be deprecated. You should - instead use `builtin = true`. - - $ niv modify -a type=tarball -a builtin=true - '' - builtins_fetchTarball { inherit (spec) url sha256; }; - - fetch_builtin-url = spec: - builtins.trace - '' - WARNING: - The niv type "builtin-url" will soon be deprecated. You should - instead use `builtin = true`. - - $ niv modify -a type=file -a builtin=true - '' - (builtins_fetchurl { inherit (spec) url sha256; }); - - # - # Various helpers - # - - # The set of packages used when specs are fetched using non-builtins. - mkPkgs = sources: - let - sourcesNixpkgs = - import (builtins_fetchTarball { inherit (sources.nixpkgs) url sha256; }) {}; - 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. - ''; - - # The actual fetching function. - fetch = pkgs: name: spec: - - if ! builtins.hasAttr "type" spec then - abort "ERROR: niv spec ${name} does not have a 'type' attribute" - else if spec.type == "file" then fetch_file pkgs spec - else if spec.type == "tarball" then fetch_tarball pkgs spec - else if spec.type == "git" then fetch_git spec - else if spec.type == "builtin-tarball" then fetch_builtin-tarball spec - else if spec.type == "builtin-url" then fetch_builtin-url spec - else - abort "ERROR: niv spec ${name} has unknown type ${builtins.toJSON spec.type}"; - - # Ports of functions for older nix versions - - # a Nix version of mapAttrs if the built-in doesn't exist - mapAttrs = builtins.mapAttrs or ( - f: set: with builtins; - listToAttrs (map (attr: { name = attr; value = f attr set.${attr}; }) (attrNames set)) - ); - - # fetchTarball version that is compatible between all the versions of Nix - builtins_fetchTarball = { url, sha256 }@attrs: - let - inherit (builtins) lessThan nixVersion fetchTarball; - in - if lessThan nixVersion "1.12" then - fetchTarball { inherit url; } - else - fetchTarball attrs; - - # fetchurl version that is compatible between all the versions of Nix - builtins_fetchurl = { url, sha256 }@attrs: - let - inherit (builtins) lessThan nixVersion fetchurl; - in - if lessThan nixVersion "1.12" then - fetchurl { inherit url; } - 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 = fetch config.pkgs name spec; } - ) config.sources; - - # The "config" used by the fetchers - mkConfig = - { sourcesFile ? ./sources.json - , sources ? builtins.fromJSON (builtins.readFile sourcesFile) - , pkgs ? mkPkgs sources - }: rec { - # The sources, i.e. the attribute set of spec name to spec - inherit sources; - - # The "pkgs" (evaluated nixpkgs) to use for e.g. non-builtin fetchers - inherit pkgs; - }; -in -mkSources (mkConfig {}) // { __functor = _: settings: mkSources (mkConfig settings); } diff --git a/olin-spec/default.nix b/olin-spec/default.nix index 62beeaa..515c9fc 100644 --- a/olin-spec/default.nix +++ b/olin-spec/default.nix @@ -1,5 +1,4 @@ -{ sources ? import ../nix/sources.nix, pkgs ? import sources.nixpkgs { } -, dhall-lang ? sources.dhall-lang, dhall ? import ../nix/dhall.nix }: +{ pkgs, dhall-lang, dhall }: pkgs.stdenv.mkDerivation rec { name = "olin-spec"; version = "latest"; diff --git a/shell.nix b/shell.nix deleted file mode 100644 index d0f54aa..0000000 --- a/shell.nix +++ /dev/null @@ -1,35 +0,0 @@ -let - sources = import ./nix/sources.nix; - niv = import sources.niv { }; - pkgs = import sources.nixpkgs { }; - olin = import sources.olin { inherit pkgs; }; - rust = import ./nix/rust.nix { inherit sources; }; - dhall = import ./nix/dhall.nix; -in pkgs.mkShell { - buildInputs = [ - rust - - # benchmarks - pkgs.hyperfine - - # dependency management - niv.niv - - # native dependencies - pkgs.openssl - pkgs.pkg-config - - # olin-docs - dhall.dhall-simple - sources.dhall-lang - - # tests - pkgs.go - olin - ]; - nativeBuildInputs = [ pkgs.removeReferencesTo ]; - - # envvars - RUST_LOG = "pahi=error,pahi_olin=debug"; - MAGIC_CONCH = "yes"; -} diff --git a/tests/default.nix b/tests/default.nix index 0927752..c0e3aad 100644 --- a/tests/default.nix +++ b/tests/default.nix @@ -1,4 +1,4 @@ -{ sources ? import ../nix/sources.nix, pkgs ? import sources.nixpkgs { } }: +{ pkgs }: with pkgs; buildGoPackage { name = "pahi-tests"; From 302cececfd1e5ff084debd31f2b40a62f7533c10 Mon Sep 17 00:00:00 2001 From: "lincoln auster [they/them]" Date: Sun, 17 Oct 2021 10:47:29 -0600 Subject: [PATCH 6/9] fix CI for the flake This involves: + name tests properly in the docker output + add dhall binaries to the docker output + use unstable nix in CI (to access Flakes) + build .#docker --impure instead of docker.nix --- .github/workflows/nix.yml | 19 +++++++++++++------ flake.nix | 4 ++-- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/.github/workflows/nix.yml b/.github/workflows/nix.yml index d3f17fb..ec4828e 100644 --- a/.github/workflows/nix.yml +++ b/.github/workflows/nix.yml @@ -2,18 +2,25 @@ name: "Nix" on: pull_request: push: + workflow_dispatch: jobs: test: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v1 - - uses: cachix/install-nix-action@v6 - - uses: cachix/cachix-action@v3 + - uses: actions/checkout@v2.3.4 + - uses: cachix/install-nix-action@v13 + with: + install_url: https://github.com/numtide/nix-unstable-installer/releases/download/nix-2.5pre20211015_130284b/install + extra_nix_config: | + experimental-features = nix-command flakes + - uses: cachix/cachix-action@v10 with: name: xe - run: | - rm result - nix-build docker.nix - docker load -i result + nix build .#docker --impure + # the shell expansion will identify the build, and, because we know + # we're guaranteed to only have one file in result/docker due to the + nix build .#docker + docker load -i result/docker/* docker run --rm xena/pahi:latest /bin/testrunner docker run --rm -w /wasm xena/pahi:latest /tests/bench.sh diff --git a/flake.nix b/flake.nix index ed5ab7d..5f5e404 100644 --- a/flake.nix +++ b/flake.nix @@ -76,7 +76,7 @@ for f in ${olin-pkg}/bin/* do - cp "$f" "$out/wasm/$(basename $f)".wasm + cp "$f" "$out/wasm/$(basename $f)" done cp -rf ${olin-cwa}/wasm/zig $out/wasm/zig @@ -98,7 +98,7 @@ contents = [ self.defaultPackage.x86_64-linux # pahi pkgs.bash pkgs.coreutils pkgs.cacert pkgs.hyperfine - dhall.dhall-json-simple ]; + dhall.dhall-json-simple dhall-lang ]; config = { Cmd = [ "/bin/bash" ]; From 5e2444472c1ad329ad5db17767b34d7320a475a1 Mon Sep 17 00:00:00 2001 From: "lincoln auster [they/them]" Date: Sun, 17 Oct 2021 17:18:00 -0600 Subject: [PATCH 7/9] correct merge conflict resolution A comment was replaced with a pure evaluation causing a CI fail. This fixes that. --- .github/workflows/nix.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/nix.yml b/.github/workflows/nix.yml index ec4828e..83bff84 100644 --- a/.github/workflows/nix.yml +++ b/.github/workflows/nix.yml @@ -20,7 +20,7 @@ jobs: nix build .#docker --impure # the shell expansion will identify the build, and, because we know # we're guaranteed to only have one file in result/docker due to the - nix build .#docker + # pure flake, will always properly expand to just the one target image. docker load -i result/docker/* docker run --rm xena/pahi:latest /bin/testrunner docker run --rm -w /wasm xena/pahi:latest /tests/bench.sh From 41e0621e2a46b44dfd95cebcb4371ac0406e5edd Mon Sep 17 00:00:00 2001 From: "lincoln auster [they/them]" Date: Fri, 26 Nov 2021 13:24:55 -0700 Subject: [PATCH 8/9] allow pure evaluation of rust toolchain This slpits rustChannelOfTargets into exlpicit rustChannelOf's and passes in the sha256 required for pure evaluation. --- flake.nix | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/flake.nix b/flake.nix index 148339e..049c80a 100644 --- a/flake.nix +++ b/flake.nix @@ -26,7 +26,10 @@ channel = "nightly"; date = "2020-07-27"; targets = [ "wasm32-unknown-unknown" "wasm32-wasi" ]; - in mozilla.rustChannelOfTargets channel date targets; + in (mozilla.rustChannelOf { + inherit channel date; + sha256 = "sha256-75eK1CNDEkeVvJ1phWOHZBuujMhalYCxbi5sgAFUlvI="; + }).rust.override { inherit targets; }; dhall = import easy-dhall-nix { inherit pkgs; }; dhall-lang-pkg = import dhall-lang { inherit pkgs; }; From d34411fd4776fc919e924a22fe3486d75b233259 Mon Sep 17 00:00:00 2001 From: "lincoln auster [they/them]" Date: Fri, 26 Nov 2021 13:26:09 -0700 Subject: [PATCH 9/9] pass pkgs to olin expression for pure evaluation --- flake.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flake.nix b/flake.nix index 049c80a..dd38b02 100644 --- a/flake.nix +++ b/flake.nix @@ -33,7 +33,7 @@ dhall = import easy-dhall-nix { inherit pkgs; }; dhall-lang-pkg = import dhall-lang { inherit pkgs; }; - olin-cwa = import olin { }; + olin-cwa = import olin { inherit pkgs; }; olin-spec = import ./olin-spec {