diff --git a/.github/workflows/nix.yml b/.github/workflows/nix.yml index cbdac3e..4000b88 100644 --- a/.github/workflows/nix.yml +++ b/.github/workflows/nix.yml @@ -4,12 +4,14 @@ on: push: jobs: nix: - name: Build flake example on ${{ matrix.os }} + name: ${{matrix.version}} on ${{matrix.os}} strategy: + fail-fast: false matrix: os: [ubuntu-latest, macos-latest] - runs-on: ${{ matrix.os }} + version: [0.8.4, 0.9.3, 0.10.101] + runs-on: ${{matrix.os}} steps: - uses: actions/checkout@v2.4.0 - uses: cachix/install-nix-action@v15 - - run: cd examples/flake && nix build --show-trace + - run: cd examples/ci && nix build '.#"${{matrix.version}}"' --show-trace diff --git a/default.nix b/default.nix index 410690b..c2921ac 100644 --- a/default.nix +++ b/default.nix @@ -13,7 +13,7 @@ let then "x86_64-darwin" else sdkSystem; - makeVersion = { systems, version }: ( + makeVersion = { systems, url, version }: ( if !acceptLicenseAgreement then error (builtins.concatStringsSep "\n" [ "" @@ -32,14 +32,7 @@ let then systems.${resolvedSystem}.sha256 else error ("unsupported system: " + resolvedSystem); stripRoot = false; - url = builtins.concatStringsSep "/" [ - "https://sdk.dfinity.org" - "downloads" - "dfx" - version - "${resolvedSystem}" - "dfx-${version}.tar.gz" - ]; + url = url; }; nativeBuildInputs = [ self.makeWrapper @@ -81,75 +74,107 @@ let ln -s $CACHE_DIR/$binary $out/bin/$binary done - wrapProgram $CACHE_DIR/dfx --set DFX_CONFIG_ROOT $out + wrapProgram $CACHE_DIR/dfx --set DFX_CACHE_ROOT $out --set DFX_CONFIG_ROOT $TMP rm $out/bin/dfx ln -s $CACHE_DIR/dfx $out/bin/dfx ''; + dontFixup = true; system = resolvedSystem; inherit version; } ); - sdk-0_6_21 = makeVersion { - systems = { - "x86_64-darwin" = { - sha256 = "0i92rwk5x13q7f7nyrgc896w2mlbk63lkgmlrvmyciwbggjiv4pc"; - }; - "x86_64-linux" = { - sha256 = "06akn065x7vaqy56v5jn551zbw5a0wfxvn13q0hpskm2iwrwrpnb"; - }; - }; - version = "0.6.21"; - }; + buildFromGitHub = { commit, ... }@args: + self.lib.fetchFromGitHub { + owner = "dfinity"; + repo = "sdk"; + rev = "f4e24bfee825b4023f85123583f470fc1846008d"; + # sha256 = "FIXME"; + sha256 = self.lib.fakeSha256; + } + ; + + makeVersionFromGitHubRelease = { version, ... }@args: + makeVersion (args // { + url = builtins.concatStringsSep "/" [ + "https://github.com" + "dfinity" + "sdk" + "releases" + "download" + version + "dfx-${version}-${resolvedSystem}.tar.gz" + ]; + }) + ; - sdk-0_7_0-beta_8 = makeVersion { + makeVersionFromManifest = { version, ... }@args: + makeVersion (args // { + url = builtins.concatStringsSep "/" [ + "https://sdk.dfinity.org" + "downloads" + "dfx" + version + "${resolvedSystem}" + "dfx-${version}.tar.gz" + ]; + }) + ; + + sdk-0_8_4 = makeVersionFromManifest { systems = { "x86_64-darwin" = { - sha256 = "19zq8n5ahqmbyp1bvhzv06zfaimxyfgzvanwfkf5px7gb1jcqf0m"; + sha256 = "JJzZzUJtrgmKJdxXGVJedhP5t9maxh3YjIq1xhTcvfU="; }; "x86_64-linux" = { - sha256 = "0nl29155076k23fx1j0zb92cr4p0dh8fk5cnjr67dy3nwlbygh3x"; + sha256 = "yht96jUJ8gTK5Ual1ofItyRBnQ+qIrbk0lOlefu/L7I="; }; }; - version = "0.7.0-beta.8"; + version = "0.8.4"; }; - sdk-0_8_4 = makeVersion { + sdk-0_9_3 = makeVersionFromManifest { systems = { "x86_64-darwin" = { - sha256 = "JJzZzUJtrgmKJdxXGVJedhP5t9maxh3YjIq1xhTcvfU="; + sha256 = "NMsETjzuZRVbnZ9slCmlHszB3GVrNGHBTKOZ6Y7EMEg="; }; "x86_64-linux" = { - sha256 = "yht96jUJ8gTK5Ual1ofItyRBnQ+qIrbk0lOlefu/L7I="; + sha256 = "wuuPDC34nrFc/eUdAownsb/FQ3/C7UXh4phzwZf0yQs="; }; }; - version = "0.8.4"; + version = "0.9.3"; }; - sdk-0_9_2 = makeVersion { + sdk-0_10_101 = makeVersionFromGitHubRelease { systems = { "x86_64-darwin" = { # sha256 = self.lib.fakeSha256; - sha256 = "UITKzQ9XzlsyO4DU72Ah2VH8736eQeW8GL6hzJHTaYA="; + sha256 = "YspeY5M87yRwm2iild0aMOTpVz75TKDrb5wEl6co7vI="; }; "x86_64-linux" = { # sha256 = self.lib.fakeSha256; - sha256 = "41NP4AGp5Ve1Srm9a2jweOEEu6iKDGJEBr+SYtrqUSM="; + sha256 = "OI2m4KHsVEpOnAqZRo6BXB7rK0B8ra+w5f/h1zBtfb0="; }; }; - version = "0.9.2"; + version = "0.10.101"; }; # https://sdk.dfinity.org/manifest.json versions = { - latest = sdk-0_8_4; - "0.6.21" = sdk-0_6_21; - "0.7.0-beta.8" = sdk-0_7_0-beta_8; + #latest = sdk-0_9_3; + latest = sdk-0_10_101; "0.8.4" = sdk-0_8_4; - "0.9.2" = sdk-0_9_2; + "0.9.3" = sdk-0_9_3; + "0.10.101" = sdk-0_10_101; }; in - versions // { inherit makeVersion; } + versions // { + inherit + makeVersion + makeVersionFromGitHubRelease + makeVersionFromManifest + ; + } ); in { diff --git a/examples/basic/default.nix b/examples/basic/default.nix new file mode 100644 index 0000000..c3c66a9 --- /dev/null +++ b/examples/basic/default.nix @@ -0,0 +1 @@ +(import ./release.nix).build diff --git a/examples/basic/dfx.json b/examples/basic/dfx.json new file mode 100644 index 0000000..923d9aa --- /dev/null +++ b/examples/basic/dfx.json @@ -0,0 +1,10 @@ +{ + "version": 1, + "dfx": "0.10.101", + "networks": { + "local": { + "bind": "127.0.0.1:8000", + "type": "ephemeral" + } + } +} diff --git a/examples/basic/release.nix b/examples/basic/release.nix index 6fe7e1f..9b98b2a 100644 --- a/examples/basic/release.nix +++ b/examples/basic/release.nix @@ -3,7 +3,33 @@ let overlays = import ./nix/overlays.nix; }; - shell = { version ? "0.8.4", system ? builtins.currentSystem }: + build = { version ? "0.9.3", system ? builtins.currentSystem }: + let + dfinitySdk = pkgs.dfinity-sdk { + acceptLicenseAgreement = true; + sdkSystem = system; + }; + in + pkgs.runCommand "ci" { + nativeBuildInputs = [ + pkgs.jq + ]; + buildInputs = [ + dfinitySdk."${version}" + pkgs.nodejs-12_x + ]; + } '' + trap "dfx stop" EXIT + jq '.dfx = "${version}"' ${./dfx.json} > dfx.json + dfx start --background --host 127.0.0.1:0 + WEBSERVER_PORT=$(cat .dfx/webserver-port) + # dfx deploy --network "http://127.0.0.1:$WEBSERVER_PORT" + dfx stop + touch $out + '' + ; + + shell = { version ? "0.9.3", system ? builtins.currentSystem }: let dfinitySdk = pkgs.dfinity-sdk { acceptLicenseAgreement = true; @@ -18,5 +44,5 @@ let }; in { - inherit shell; + inherit build shell; } diff --git a/examples/ci/dfx.json b/examples/ci/dfx.json new file mode 100644 index 0000000..923d9aa --- /dev/null +++ b/examples/ci/dfx.json @@ -0,0 +1,10 @@ +{ + "version": 1, + "dfx": "0.10.101", + "networks": { + "local": { + "bind": "127.0.0.1:8000", + "type": "ephemeral" + } + } +} diff --git a/examples/ci/flake.lock b/examples/ci/flake.lock new file mode 100644 index 0000000..32a353d --- /dev/null +++ b/examples/ci/flake.lock @@ -0,0 +1,56 @@ +{ + "nodes": { + "dfinity-sdk": { + "flake": false, + "locked": { + "narHash": "sha256-g+OEfBp2xVqFqBJt2W6I4pfyH49dHKxhP1tYLTGW2os=", + "path": "/nix/store/4bjs4nr86p9fj6mnv9kxnbyz8v6ivfzd-source", + "type": "path" + }, + "original": { + "path": "/nix/store/4bjs4nr86p9fj6mnv9kxnbyz8v6ivfzd-source", + "type": "path" + } + }, + "flake-utils": { + "locked": { + "lastModified": 1644229661, + "narHash": "sha256-1YdnJAsNy69bpcjuoKdOYQX0YxZBiCYZo4Twxerqv7k=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "3cecb5b042f7f209c56ffd8371b2711a290ec797", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1638239011, + "narHash": "sha256-AjhmbT4UBlJWqxY0ea8a6GU2C2HdKUREkG43oRr3TZg=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "a7ecde854aee5c4c7cd6177f54a99d2c1ff28a31", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "21.11", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "dfinity-sdk": "dfinity-sdk", + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/examples/ci/flake.nix b/examples/ci/flake.nix new file mode 100644 index 0000000..cf97672 --- /dev/null +++ b/examples/ci/flake.nix @@ -0,0 +1,70 @@ +{ + inputs = { + nixpkgs.url = "github:nixos/nixpkgs/21.11"; + flake-utils.url = "github:numtide/flake-utils"; + dfinity-sdk = { + # url = "github:paulyoung/nixpkgs-dfinity-sdk"; + url = "../../"; + flake = false; + }; + }; + + outputs = { self, nixpkgs, flake-utils, dfinity-sdk }: + flake-utils.lib.eachSystem ["aarch64-darwin" "x86_64-darwin" "x86_64-linux"] ( + system: let + pkgs = import nixpkgs { + inherit system; + overlays = [ + (final: prev: (import dfinity-sdk) final prev) + ]; + }; + + dfinitySdk = (pkgs.dfinity-sdk { + acceptLicenseAgreement = true; + sdkSystem = system; + }); + + mkPackage = version: + pkgs.runCommand "ci" { + nativeBuildInputs = [ + pkgs.jq + ]; + buildInputs = [ + dfinitySdk."${version}" + ]; + } '' + trap "dfx stop" EXIT + jq '.dfx = "${version}"' ${./dfx.json} > dfx.json + dfx start --background --host 127.0.0.1:0 + WEBSERVER_PORT=$(cat .dfx/webserver-port) + # dfx deploy --network "http://127.0.0.1:$WEBSERVER_PORT" + dfx stop + touch $out + '' + ; + + drvs = + pkgs.lib.attrsets.filterAttrs + (_name: value: pkgs.lib.attrsets.isDerivation value) + dfinitySdk + ; + in + rec { + # `nix build` + defaultPackage = packages."0.10.101"; + + packages = + pkgs.lib.attrsets.mapAttrs + (name: _value: mkPackage name) + drvs + ; + + # `nix develop` + devShell = pkgs.mkShell { + buildInputs = [ + dfinitySdk.latest + ]; + }; + } + ); +} diff --git a/examples/flake/dfx.json b/examples/flake/dfx.json index 6856da2..8240a9e 100644 --- a/examples/flake/dfx.json +++ b/examples/flake/dfx.json @@ -1,6 +1,23 @@ { "version": 1, - "dfx": "0.8.4", + "dfx": "0.11.2", + "canisters": { + "internet_identity": { + "type": "custom", + "wasm": "result-remote/internet_identity/internet_identity_dev.wasm", + "candid": "result-remote/internet_identity/internet_identity.did", + "remote": { + "id": { + "ic": "rdmx6-jaaaa-aaaaa-aaadq-cai" + } + } + } + }, + "ic": { + "providers": [ + "https://ic0.app" + ] + }, "networks": { "local": { "bind": "127.0.0.1:8000", diff --git a/examples/flake/flake.lock b/examples/flake/flake.lock index 8c5bc27..6671b8a 100644 --- a/examples/flake/flake.lock +++ b/examples/flake/flake.lock @@ -3,13 +3,17 @@ "dfinity-sdk": { "flake": false, "locked": { - "narHash": "sha256-zyABLkjsQG10ggHjgsLFczjM2tAMOrB7OsPRhUlCJlw=", - "path": "/nix/store/982fn4524aqcwhd55jw0yhqv6nk3ssa1-source", - "type": "path" + "lastModified": 1648278992, + "narHash": "sha256-2dCMlzjebld3yrNXJ5uCN67/eOKSHt2OcUk1GA9jp5o=", + "owner": "paulyoung", + "repo": "nixpkgs-dfinity-sdk", + "rev": "8ea6347d42e4173767acb74e2c0ff45c4585616a", + "type": "github" }, "original": { - "path": "/nix/store/982fn4524aqcwhd55jw0yhqv6nk3ssa1-source", - "type": "path" + "owner": "paulyoung", + "repo": "nixpkgs-dfinity-sdk", + "type": "github" } }, "flake-utils": { diff --git a/examples/flake/flake.nix b/examples/flake/flake.nix index 815ce5c..7d683a4 100644 --- a/examples/flake/flake.nix +++ b/examples/flake/flake.nix @@ -2,15 +2,17 @@ inputs = { nixpkgs.url = "github:nixos/nixpkgs/21.11"; flake-utils.url = "github:numtide/flake-utils"; + dfinity-sdk = { - # url = "github:paulyoung/nixpkgs-dfinity-sdk"; - url = "../../"; + # url = "github:paulyoung/nixpkgs-dfinity-sdk?rev=28bb54dc1912cd723dc15f427b67c5309cfe851e"; + url = "github:paulyoung/nixpkgs-dfinity-sdk"; flake = false; }; + }; outputs = { self, nixpkgs, flake-utils, dfinity-sdk }: - flake-utils.lib.eachDefaultSystem ( + flake-utils.lib.eachSystem ["aarch64-darwin" "x86_64-darwin" "x86_64-linux"] ( system: let pkgs = import nixpkgs { inherit system; @@ -22,7 +24,19 @@ dfinitySdk = (pkgs.dfinity-sdk { acceptLicenseAgreement = true; sdkSystem = system; - })."0.8.4"; + # })."0.9.3"; + }).makeVersion { + systems = { + "x86_64-darwin" = { + sha256 = "sha256-0dmrknkFJ5UrGYqL2aH6xuUPJFlY6ae+4faHeF5rJBw="; + }; + "x86_64-linux" = { + sha256 = pkgs.lib.fakeSha256; + }; + }; + version = "0.11.2"; + }; + in { # `nix build` @@ -31,8 +45,12 @@ dfinitySdk ]; } '' + HOME=$TMP + trap "dfx stop" EXIT cp ${./dfx.json} dfx.json - dfx start --background + dfx start --background --host 127.0.0.1:0 + WEBSERVER_PORT=$(cat .dfx/webserver-port) + # dfx deploy --network "http://127.0.0.1:$WEBSERVER_PORT" dfx stop touch $out '';