From f5fc5867d3bb5d147d53f1a2e0127c8ed5e3153b Mon Sep 17 00:00:00 2001 From: Greg Burd Date: Thu, 21 Sep 2023 11:52:33 -0400 Subject: [PATCH] forAllSystems --- _flake.nix | 51 ------------- flake.lock | 84 ++++++++++++++++++++- flake.nix | 173 ++++++++++++++++++++++--------------------- nix/lxc.nix | 14 ++-- nix/overlays.nix | 2 + nix/pkg-win64zip.nix | 10 ++- shell.nix | 8 +- 7 files changed, 188 insertions(+), 154 deletions(-) delete mode 100644 _flake.nix create mode 100644 nix/overlays.nix diff --git a/_flake.nix b/_flake.nix deleted file mode 100644 index 812b7ae..0000000 --- a/_flake.nix +++ /dev/null @@ -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") - ''; - }; - } - ); - - }; diff --git a/flake.lock b/flake.lock index 0310f4e..752c589 100644 --- a/flake.lock +++ b/flake.lock @@ -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, diff --git a/flake.nix b/flake.nix index 01dacb3..2962725 100644 --- a/flake.nix +++ b/flake.nix @@ -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 " ]; - 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 "]; + 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); + }; } diff --git a/nix/lxc.nix b/nix/lxc.nix index 7da1c9a..38663d2 100644 --- a/nix/lxc.nix +++ b/nix/lxc.nix @@ -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"]; } diff --git a/nix/overlays.nix b/nix/overlays.nix new file mode 100644 index 0000000..7051552 --- /dev/null +++ b/nix/overlays.nix @@ -0,0 +1,2 @@ +{pkgs}: { +} diff --git a/nix/pkg-win64zip.nix b/nix/pkg-win64zip.nix index a314547..33f256e 100644 --- a/nix/pkg-win64zip.nix +++ b/nix/pkg-win64zip.nix @@ -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"; }; }; -} \ No newline at end of file +} diff --git a/shell.nix b/shell.nix index a627748..a63e092 100644 --- a/shell.nix +++ b/shell.nix @@ -1,7 +1,7 @@ -{ pkgs ? import {} }: - +{pkgs ? import {}}: 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]; }