forAllSystems

This commit is contained in:
Greg Burd 2023-09-21 11:52:33 -04:00
parent 419b29a49d
commit f5fc5867d3
No known key found for this signature in database
GPG key ID: 1FC1E7793410DE46
7 changed files with 188 additions and 154 deletions

View file

@ -1,51 +0,0 @@
# Tests run by 'nix flake check' and by Hydra.
checks = forAllSystems
(system:
with pkgs.${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")
'';
};
}
);
};

View file

@ -1,5 +1,50 @@
{
"nodes": {
"alejandra": {
"inputs": {
"fenix": "fenix",
"flakeCompat": "flakeCompat",
"nixpkgs": [
"nixpkgs"
]
},
"locked": {
"lastModified": 1660510326,
"narHash": "sha256-xFumnivtVwu5fFBOrTxrv6fv3geHKF04RGP23EsDVaI=",
"owner": "kamadorueda",
"repo": "alejandra",
"rev": "ef03f7ef74ec97fd91a016a51c9c9667fb315652",
"type": "github"
},
"original": {
"owner": "kamadorueda",
"ref": "3.0.0",
"repo": "alejandra",
"type": "github"
}
},
"fenix": {
"inputs": {
"nixpkgs": [
"alejandra",
"nixpkgs"
],
"rust-analyzer-src": "rust-analyzer-src"
},
"locked": {
"lastModified": 1657607339,
"narHash": "sha256-HaqoAwlbVVZH2n4P3jN2FFPMpVuhxDy1poNOR7kzODc=",
"owner": "nix-community",
"repo": "fenix",
"rev": "b814c83d9e6aa5a28d0cf356ecfdafb2505ad37d",
"type": "github"
},
"original": {
"owner": "nix-community",
"repo": "fenix",
"type": "github"
}
},
"flake-compat": {
"flake": false,
"locked": {
@ -29,9 +74,8 @@
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
"id": "flake-utils",
"type": "indirect"
}
},
"flake-utils_2": {
@ -67,6 +111,22 @@
"type": "github"
}
},
"flakeCompat": {
"flake": false,
"locked": {
"lastModified": 1650374568,
"narHash": "sha256-Z+s0J8/r907g149rllvwhb4pKi8Wam5ij0st8PwAh+E=",
"owner": "edolstra",
"repo": "flake-compat",
"rev": "b4a34015c698c7793d592d66adbab377907a2be8",
"type": "github"
},
"original": {
"owner": "edolstra",
"repo": "flake-compat",
"type": "github"
}
},
"gitignore": {
"inputs": {
"nixpkgs": [
@ -226,6 +286,7 @@
},
"root": {
"inputs": {
"alejandra": "alejandra",
"flake-utils": "flake-utils",
"nix-github-actions": "nix-github-actions",
"nixpkgs": "nixpkgs",
@ -233,6 +294,23 @@
"zicross": "zicross"
}
},
"rust-analyzer-src": {
"flake": false,
"locked": {
"lastModified": 1657557289,
"narHash": "sha256-PRW+nUwuqNTRAEa83SfX+7g+g8nQ+2MMbasQ9nt6+UM=",
"owner": "rust-lang",
"repo": "rust-analyzer",
"rev": "caf23f29144b371035b864a1017dbc32573ad56d",
"type": "github"
},
"original": {
"owner": "rust-lang",
"ref": "nightly",
"repo": "rust-analyzer",
"type": "github"
}
},
"systems": {
"locked": {
"lastModified": 1681028828,

173
flake.nix
View file

@ -7,105 +7,106 @@
inputs = {
nixpkgs.url = "github:nixos/nixpkgs";
flake-utils.url = "github:numtide/flake-utils";
zicross.url = "github:flyx/Zicross";
pre-commit-hooks.url = "github:cachix/pre-commit-hooks.nix";
nix-github-actions.url = "github:nix-community/nix-github-actions";
nix-github-actions.inputs.nixpkgs.follows = "nixpkgs";
alejandra.url = "github:kamadorueda/alejandra/3.0.0";
alejandra.inputs.nixpkgs.follows = "nixpkgs";
};
inputs.pre-commit-hooks.url = "github:cachix/pre-commit-hooks.nix";
inputs.nix-github-actions.url = "github:nix-community/nix-github-actions";
inputs.nix-github-actions.inputs.nixpkgs.follows = "nixpkgs";
outputs = { self, nixpkgs, flake-utils, pre-commit-hooks, nix-github-actions, zicross }:
let
inherit (nixpkgs) lib;
officialRelease = false;
outputs = {
self,
nixpkgs,
flake-utils,
pre-commit-hooks,
nix-github-actions,
alejandra,
zicross,
}: let
inherit (nixpkgs) lib;
officialRelease = false;
version = lib.fileContents ./.version + versionSuffix;
versionSuffix =
if officialRelease
then ""
else "pre${builtins.substring 0 8 (self.lastModifiedDate or self.lastModified or "19700101")}_${self.shortRev or "dirty"}";
version = lib.fileContents ./.version + versionSuffix;
versionSuffix =
if officialRelease
then ""
else "pre${builtins.substring 0 8 (self.lastModifiedDate or self.lastModified or "19700101")}_${self.shortRev or "dirty"}";
#supportedSystems = [ "i386-linux" "x86_64-linux" "armv6l-linux" "armv7l-linux" "aarch64-linux" "powerpc64le-linux" "riscv64-linux" "x86_64-darwin" "aarch64-darwin" "x86_64-windows" "x86_64-windows" ];
supportedSystems = [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin" ];
supportedSystems = ["x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin"];
# ??? [ "i386-linux" "x86_64-linux" "armv6l-linux" "armv7l-linux" "aarch64-linux" "powerpc64le-linux" "riscv64-linux" "x86_64-darwin" "aarch64-darwin" "x86_64-windows" "x86_64-windows" ];
# Generate an attrset '{ x86_64-linux = f "x86_64-linux"; ... }'.
forAllSystems = nixpkgs.lib.genAttrs supportedSystems;
# Generate an attrset '{ x86_64-linux = f "x86_64-linux"; ... }'.
forAllSystems = nixpkgs.lib.genAttrs supportedSystems;
# Nixpkgs instantiated for supported system types.
nixpkgsFor = forAllSystems (system: import nixpkgs {
# Nixpkgs instantiated for supported system types.
nixpkgsFor = forAllSystems (system:
import nixpkgs {
inherit system;
overlays = [ self.overlay ];
overlays =
[
zicross.overlays.zig
zicross.overlays.debian
zicross.overlays.windows
]
++ self.additional_overlays;
});
in
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs {
inherit system;
overlays = [
#zicross.overlays.zig
#zicross.overlays.debian
#zicross.overlays.windows
(final: prev: {
#hello = with final; (if lib.strings.hasSuffix "windows" system then zigStdenv else stdenv).mkDerivation rec {
hello = with final; stdenv.mkDerivation rec {
inherit version system;
pname = "hello";
src = self;
configureFlags = [
"--host ${system}"
];
nativeBuildInputs = [ autoreconfHook ];
meta = {
maintainers = [ "Greg Burd <greg@burd.me>" ];
downloadPage = "https://github.com/gburd/hello/releases";
changelog = "https://raw.githubusercontent.com/gburd/hello/main/ChangeLog";
platforms = supportedSystems;
homepage = "https://github.com/gburd/hello";
license = "https://github.com/gburd/hello/LICENSE";
mainProgram = "hello";
};
};
})
in {
additional_overlays = [
(final: prev: {
hello = with final;
(
if lib.strings.hasSuffix "windows" system
then zigStdenv
else stdenv
)
.mkDerivation rec {
inherit version system;
pname = "hello";
src = self;
configureFlags = [
"--host ${system}"
];
checks = {
pre-commit-check = pre-commit-hooks.lib.${system}.run {
src = ./.;
hooks = {
nixpkgs-fmt.enable = true;
};
};
};
devShell = nixpkgs.legacyPackages.${system}.mkShell {
inherit (self.checks.${system}.pre-commit-check) shellHook;
};
};
in rec {
packages = {
inherit (pkgs) hello;
# This changes things in "packages" below of the form: "packages.x86_64-linux" into
# "githubActions.targets.x86_64-linux.hello" so that the GHA matrix can iterate over them.
githubActions = nix-github-actions.lib.mkGithubMatrix {
checks = nixpkgs.lib.getAttrs supportedSystems self.packages;
nativeBuildInputs = [autoreconfHook];
meta = {
maintainers = ["Greg Burd <greg@burd.me>"];
downloadPage = "https://github.com/gburd/hello/releases";
changelog = "https://raw.githubusercontent.com/gburd/hello/main/ChangeLog";
platforms = supportedSystems;
homepage = "https://github.com/gburd/hello";
license = "https://github.com/gburd/hello/LICENSE";
mainProgram = "hello";
};
};
packages.default = self.packages.${system}.hello;
})
];
packages = forAllSystems (system: let
pkgs = nixpkgsFor.${system};
in rec {
inherit (pkgs) hello;
default = hello;
lxc = pkgs.callPackage ./nix/lxc.nix {package = default;};
x86_64-windows = pkgs.callPackage ./nix/pkg-win64zip.nix {package = default;};
#x86_64-wix = pkgs.callPackage ./nix/pkg-win64-wix.nix { package = default; };
});
#packages.lxc = pkgs.callPackage ./nix/lxc.nix { package = packages.default; };
#packages.x86_64-windows = pkgs.callPackage ./nix/pkg-win64zip.nix { package = packages.default; };
#packages.x86_64-wix = pkgs.callPackage ./nix/pkg-win64-wix.nix { inherit pkgs packages; };
checks = forAllSystems (system: {
pre-commit-check = pre-commit-hooks.lib.${system}.run {
src = ./.;
hooks = {
alejandra.enable = true;
};
};
});
#apps.hello = flake-utils.lib.mkApp { drv = packages.default; };
#apps.${system}.default = apps.hello;
devShells.default = forAllSystems (system: import ./shell.nix {pkgs = nixpkgsFor.${system};});
#devShells.default = import ./shell.nix { inherit pkgs; };
}
);
# This changes things in "packages" below of the form: "packages.x86_64-linux" into
# "githubActions.targets.x86_64-linux.hello" so that the GHA matrix can iterate over them.
githubActions = nix-github-actions.lib.mkGithubMatrix {
checks = nixpkgs.lib.getAttrs ["x86_64-linux" "x86_64-darwin"] self.packages;
};
formatter = forAllSystems (system: nixpkgsFor.${system}.alejandra);
};
}

View file

@ -1,13 +1,15 @@
{ pkgs, package }:
{
pkgs,
package,
}:
pkgs.dockerTools.buildImage {
name = package.pname;
tag = [ "latest" "0.1.0" ]; #package.version
tag = ["latest" "0.1.0"]; #package.version
created = "now";
copyToRoot = pkgs.buildEnv {
name = "image-root";
paths = [ package ];
pathsToLink = [ "/bin" ];
paths = [package];
pathsToLink = ["/bin"];
};
config.Cmd = [ "${package}/bin/hello" ];
config.Cmd = ["${package}/bin/hello"];
}

2
nix/overlays.nix Normal file
View file

@ -0,0 +1,2 @@
{pkgs}: {
}

View file

@ -1,12 +1,14 @@
{ pkgs, package }:
{
pkgs,
package,
}:
pkgs.packageForWindows package {
targetSystem = "x86_64-windows";
appendExe = [ "hello" ];
appendExe = ["hello"];
deps = {
libcpp = {
tail = "libc++-14.0.3-1-any.pkg.tar.zst";
sha256 = "1r73zs9naislzzjn7mr3m8s6pikgg3y4mv550hg09gcsjc719kzz";
};
};
}
}

View file

@ -1,7 +1,7 @@
{ pkgs ? import <nixpkgs> {} }:
{pkgs ? import <nixpkgs> {}}:
pkgs.mkShell {
# nativeBuildInputs is usually what you want -- tools you need to run
nativeBuildInputs = with pkgs.buildPackages; [ ripgrep act ];
#inherit (checks.${system}.pre-commit-check) shellHook;
DOCKER_BUILDKIT = 1;
# nativeBuildInputs -- tools you need to run to facilitate the build
nativeBuildInputs = with pkgs.buildPackages; [ripgrep act];
}