diff --git a/examples/flake/arion-compose.nix b/examples/flake/arion-compose.nix new file mode 100644 index 0000000..9531a9f --- /dev/null +++ b/examples/flake/arion-compose.nix @@ -0,0 +1,19 @@ +{ pkgs, ... }: +{ + config.project.name = "webapp"; + config.services = { + + webserver = { + service.useHostStore = true; + service.command = [ "sh" "-c" '' + cd "$$WEB_ROOT" + ${pkgs.python3}/bin/python -m http.server + '' ]; + service.ports = [ + "8000:8000" # host:container + ]; + service.environment.WEB_ROOT = "${pkgs.nix.doc}/share/doc/nix/manual"; + service.stop_signal = "SIGINT"; + }; + }; +} diff --git a/examples/flake/arion-pkgs.nix b/examples/flake/arion-pkgs.nix new file mode 100644 index 0000000..7f16edd --- /dev/null +++ b/examples/flake/arion-pkgs.nix @@ -0,0 +1,13 @@ +let + flake = if builtins ? getFlake + then (builtins.getFlake (toString ./.)).pkgs + else (import flake-compat { src = ./.; }).defaultNix; + # NB: this is lazy + lock = builtins.fromJSON (builtins.readFile ./flake.lock); + inherit (lock.nodes.flake-compat.locked) owner repo rev narHash; + flake-compat = builtins.fetchTarball { + url = "https://github.com/${owner}/${repo}/archive/${rev}.tar.gz"; + sha256 = narHash; + }; +in + flake.pkgs diff --git a/examples/flake/flake.lock b/examples/flake/flake.lock new file mode 100644 index 0000000..cf44f98 --- /dev/null +++ b/examples/flake/flake.lock @@ -0,0 +1,44 @@ +{ + "nodes": { + "flake-compat": { + "flake": false, + "locked": { + "lastModified": 1606424373, + "narHash": "sha256-oq8d4//CJOrVj+EcOaSXvMebvuTkmBJuT5tzlfewUnQ=", + "owner": "edolstra", + "repo": "flake-compat", + "rev": "99f1c2157fba4bfe6211a321fd0ee43199025dbf", + "type": "github" + }, + "original": { + "owner": "edolstra", + "repo": "flake-compat", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1618853290, + "narHash": "sha256-K4fddnrGOcKL+6CEchRrVmepiwvwvHxB87goqBTI5Bs=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "9a1672105db0eebe8ef59f310397435f2d0298d0", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-20.09", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-compat": "flake-compat", + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/examples/flake/flake.nix b/examples/flake/flake.nix new file mode 100644 index 0000000..a8252bd --- /dev/null +++ b/examples/flake/flake.nix @@ -0,0 +1,19 @@ +{ + description = "A very basic flake"; + + inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-20.09"; + inputs.flake-compat.url = "github:edolstra/flake-compat"; + inputs.flake-compat.flake = false; + + outputs = { self, nixpkgs, ... }: { + + pkgs = nixpkgs.legacyPackages.x86_64-linux; + # # alternative: + # pkgs = import nixpkgs { config = { }; overlays = [ ]; system = "x86_64-linux"; }; + + packages.x86_64-linux.hello = nixpkgs.legacyPackages.x86_64-linux.hello; + + defaultPackage.x86_64-linux = self.packages.x86_64-linux.hello; + + }; +} diff --git a/tests/arion-test/default.nix b/tests/arion-test/default.nix index cd32b35..dcbd376 100644 --- a/tests/arion-test/default.nix +++ b/tests/arion-test/default.nix @@ -57,6 +57,20 @@ in ) machine.wait_until_fails("curl --fail localhost:8000") + # Tests + # - examples/flake + # This _test_ doesn't work because flake-compat fetches the github + # tarballs without sha256 and/or Nix doesn't consult the store before + # downloading. + # See https://github.com/edolstra/flake-compat/pull/12 + # with subtest("flake"): + # machine.succeed( + # "rm -rf work && cp -frT ''${../../examples/flake} work && cd work && NIX_PATH= arion up -d" + # ) + # machine.wait_until_succeeds("curl --fail localhost:8000") + # machine.succeed("cd work && NIX_PATH= arion down") + # machine.wait_until_fails("curl --fail localhost:8000") + # Tests # - arion exec # - examples/full-nixos