Add experimental flake example
This commit is contained in:
parent
127a5babaa
commit
1da9c00cd5
5 changed files with 109 additions and 0 deletions
19
examples/flake/arion-compose.nix
Normal file
19
examples/flake/arion-compose.nix
Normal file
|
@ -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";
|
||||
};
|
||||
};
|
||||
}
|
13
examples/flake/arion-pkgs.nix
Normal file
13
examples/flake/arion-pkgs.nix
Normal file
|
@ -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
|
44
examples/flake/flake.lock
Normal file
44
examples/flake/flake.lock
Normal file
|
@ -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
|
||||
}
|
19
examples/flake/flake.nix
Normal file
19
examples/flake/flake.nix
Normal file
|
@ -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;
|
||||
|
||||
};
|
||||
}
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue