flake-utils and add container
This commit is contained in:
parent
f4c39ef325
commit
7bb0fe54e4
3 changed files with 43 additions and 113 deletions
9
TODO
9
TODO
|
@ -4,10 +4,17 @@
|
||||||
* Docker container on DockerHub, GitHub Container Repository (ghcr.io)
|
* Docker container on DockerHub, GitHub Container Repository (ghcr.io)
|
||||||
* containers could have multiple tags as in `latest` and `1.0.0`
|
* containers could have multiple tags as in `latest` and `1.0.0`
|
||||||
* add Nix Flake
|
* add Nix Flake
|
||||||
* devshell
|
* devShell
|
||||||
* direnv/envrc
|
* direnv/envrc
|
||||||
* build windows MSYS2
|
* build windows MSYS2
|
||||||
* formatting
|
* formatting
|
||||||
* lint
|
* lint
|
||||||
* security audits
|
* security audits
|
||||||
* Gitpod
|
* Gitpod
|
||||||
|
* recorded ascii demo
|
||||||
|
* README.md
|
||||||
|
* build and other badges
|
||||||
|
|
||||||
|
-----
|
||||||
|
nix flake show
|
||||||
|
nix flake show --json | jq '.packages."x86_64-linux"|keys[]'| xargs -I {} nix build .#{}
|
||||||
|
|
17
flake.lock
17
flake.lock
|
@ -1,21 +1,5 @@
|
||||||
{
|
{
|
||||||
"nodes": {
|
"nodes": {
|
||||||
"flake-compat": {
|
|
||||||
"flake": false,
|
|
||||||
"locked": {
|
|
||||||
"lastModified": 1673956053,
|
|
||||||
"narHash": "sha256-4gtG9iQuiKITOjNQQeQIpoIB6b16fm+504Ch3sNKLd8=",
|
|
||||||
"owner": "edolstra",
|
|
||||||
"repo": "flake-compat",
|
|
||||||
"rev": "35bb57c0c8d8b62bbfd284272c928ceb64ddbde9",
|
|
||||||
"type": "github"
|
|
||||||
},
|
|
||||||
"original": {
|
|
||||||
"owner": "edolstra",
|
|
||||||
"repo": "flake-compat",
|
|
||||||
"type": "github"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"flake-utils": {
|
"flake-utils": {
|
||||||
"inputs": {
|
"inputs": {
|
||||||
"systems": "systems"
|
"systems": "systems"
|
||||||
|
@ -51,7 +35,6 @@
|
||||||
},
|
},
|
||||||
"root": {
|
"root": {
|
||||||
"inputs": {
|
"inputs": {
|
||||||
"flake-compat": "flake-compat",
|
|
||||||
"flake-utils": "flake-utils",
|
"flake-utils": "flake-utils",
|
||||||
"nixpkgs": "nixpkgs"
|
"nixpkgs": "nixpkgs"
|
||||||
}
|
}
|
||||||
|
|
118
flake.nix
118
flake.nix
|
@ -5,19 +5,13 @@
|
||||||
inputs = {
|
inputs = {
|
||||||
nixpkgs.url = "github:nixos/nixpkgs";
|
nixpkgs.url = "github:nixos/nixpkgs";
|
||||||
flake-utils.url = "github:numtide/flake-utils";
|
flake-utils.url = "github:numtide/flake-utils";
|
||||||
flake-compat = {
|
|
||||||
url = "github:edolstra/flake-compat";
|
|
||||||
flake = false;
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
outputs = { self, nixpkgs, flake-utils, flake-compat }:
|
outputs = { self, nixpkgs, flake-utils }:
|
||||||
let
|
let
|
||||||
|
|
||||||
# to work with older version of flakes
|
|
||||||
lastModifiedDate = self.lastModifiedDate or self.lastModified or "19700101";
|
lastModifiedDate = self.lastModifiedDate or self.lastModified or "19700101";
|
||||||
|
|
||||||
# Generate a user-friendly version number.
|
# Generate a user-friendly version number for our target.
|
||||||
version = builtins.substring 0 8 lastModifiedDate;
|
version = builtins.substring 0 8 lastModifiedDate;
|
||||||
|
|
||||||
# System types to support.
|
# System types to support.
|
||||||
|
@ -30,95 +24,41 @@
|
||||||
nixpkgsFor = forAllSystems (system: import nixpkgs { inherit system; overlays = [ self.overlay ]; });
|
nixpkgsFor = forAllSystems (system: import nixpkgs { inherit system; overlays = [ self.overlay ]; });
|
||||||
|
|
||||||
in
|
in
|
||||||
|
flake-utils.lib.eachDefaultSystem (system:
|
||||||
|
let
|
||||||
|
pkgs = import nixpkgs {
|
||||||
|
inherit system;
|
||||||
|
|
||||||
{
|
overlays = [
|
||||||
|
(final: prev: {
|
||||||
# A Nixpkgs overlay.
|
|
||||||
overlay = final: prev: {
|
|
||||||
|
|
||||||
hello = with final; stdenv.mkDerivation rec {
|
hello = with final; stdenv.mkDerivation rec {
|
||||||
pname = "hello";
|
pname = "hello";
|
||||||
inherit version;
|
inherit version;
|
||||||
|
|
||||||
src = ./.;
|
src = ./.;
|
||||||
|
|
||||||
nativeBuildInputs = [ autoreconfHook ];
|
nativeBuildInputs = [ autoreconfHook ];
|
||||||
enableParallelBuilding = true;
|
};
|
||||||
|
})
|
||||||
|
];
|
||||||
|
};
|
||||||
|
in rec {
|
||||||
|
|
||||||
|
packages = { inherit (pkgs) hello; };
|
||||||
|
packages.default = self.packages.${system}.hello;
|
||||||
|
packages.container = pkgs.dockerTools.buildImage {
|
||||||
|
name = "hello";
|
||||||
|
tag = "0.1.0";
|
||||||
|
created = "now";
|
||||||
|
copyToRoot = pkgs.buildEnv {
|
||||||
|
name = "image-root";
|
||||||
|
paths = [ packages.default ];
|
||||||
|
pathsToLink = [ "/bin" ];
|
||||||
|
};
|
||||||
|
config.Cmd = [ "${packages.default}/bin/hello" ];
|
||||||
};
|
};
|
||||||
|
|
||||||
};
|
apps.hello = flake-utils.lib.mkApp { drv = packages.hello; };
|
||||||
|
defaultApp = apps.hello;
|
||||||
# Provide some binary packages for selected system types.
|
# devShells.default = import ./shell.nix { inherit pkgs; };
|
||||||
packages = forAllSystems (system:
|
|
||||||
{
|
|
||||||
inherit (nixpkgsFor.${system}) hello;
|
|
||||||
});
|
|
||||||
|
|
||||||
# The default package for 'nix build'. This makes sense if the flake
|
|
||||||
# provides only one package or there is a clear "main" package.
|
|
||||||
defaultPackage = forAllSystems (system: self.packages.${system}.hello);
|
|
||||||
|
|
||||||
# A NixOS module, if applicable (e.g. if the package provides a system
|
|
||||||
# service).
|
|
||||||
nixosModules.hello =
|
|
||||||
{ pkgs, ... }:
|
|
||||||
{
|
|
||||||
nixpkgs.overlays = [ self.overlay ];
|
|
||||||
|
|
||||||
environment.systemPackages = [ pkgs.hello ];
|
|
||||||
|
|
||||||
#systemd.services = { ... };
|
|
||||||
};
|
|
||||||
|
|
||||||
# Tests run by 'nix flake check' and by Hydra.
|
|
||||||
checks = forAllSystems
|
|
||||||
(system:
|
|
||||||
with nixpkgsFor.${system};
|
|
||||||
|
|
||||||
{
|
|
||||||
inherit (self.packages.${system}) hello;
|
|
||||||
|
|
||||||
# Additional tests, if applicable.
|
|
||||||
test = stdenv.mkDerivation {
|
|
||||||
pname = "hello-test";
|
|
||||||
inherit version;
|
|
||||||
|
|
||||||
buildInputs = [ hello ];
|
|
||||||
|
|
||||||
dontUnpack = true;
|
|
||||||
|
|
||||||
buildPhase = ''
|
|
||||||
echo 'running some integration tests'
|
|
||||||
[[ $(hello) = 'Hello Nixers!' ]]
|
|
||||||
'';
|
|
||||||
|
|
||||||
installPhase = "mkdir -p $out";
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
// lib.optionalAttrs stdenv.isLinux {
|
|
||||||
# A VM test of the NixOS module.
|
|
||||||
vmTest =
|
|
||||||
with import (nixpkgs + "/nixos/lib/testing-python.nix") {
|
|
||||||
inherit system;
|
|
||||||
};
|
|
||||||
|
|
||||||
makeTest {
|
|
||||||
nodes = {
|
|
||||||
client = { ... }: {
|
|
||||||
imports = [ self.nixosModules.hello ];
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
testScript =
|
|
||||||
''
|
|
||||||
start_all()
|
|
||||||
client.wait_for_unit("multi-user.target")
|
|
||||||
client.succeed("hello")
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue