From 4aff7e3a11fd2bbb016e1d85fbb76e039a1ea81c Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Thu, 1 Dec 2022 23:21:38 +0000 Subject: [PATCH 1/4] Use flake-parts --- default.nix | 9 +- docs/flake-module.nix | 20 ++++ flake.lock | 56 ++++++++++-- flake.nix | 125 +++++++++++++++++-------- nix/ci.nix | 46 ---------- nix/compat.nix | 10 ++ nix/default.nix | 23 ----- nix/haskell-overlay.nix | 16 ---- nix/overlay.nix | 60 ------------ nix/sources.json | 63 ------------- nix/sources.nix | 171 ----------------------------------- shell.nix | 2 +- tests/arion-test/default.nix | 2 +- tests/default.nix | 46 ---------- tests/flake-module.nix | 35 +++++++ update-options | 4 +- 16 files changed, 210 insertions(+), 478 deletions(-) create mode 100644 docs/flake-module.nix delete mode 100644 nix/ci.nix create mode 100644 nix/compat.nix delete mode 100644 nix/default.nix delete mode 100644 nix/haskell-overlay.nix delete mode 100644 nix/overlay.nix delete mode 100644 nix/sources.json delete mode 100644 nix/sources.nix delete mode 100644 tests/default.nix create mode 100644 tests/flake-module.nix diff --git a/default.nix b/default.nix index 7b66620..88685a6 100644 --- a/default.nix +++ b/default.nix @@ -1,6 +1,11 @@ -{ pkgs ? import ./nix {} +let flake = import ./nix/compat.nix; +in +{ pkgs ? import flake.inputs.nixpkgs { } , haskellPackages ? pkgs.haskellPackages }: +let + pkgsWithArion = pkgs.extend flake.overlays.default; +in { - arion = import ./nix/arion.nix { inherit pkgs haskellPackages; }; + inherit (pkgsWithArion) arion; } diff --git a/docs/flake-module.nix b/docs/flake-module.nix new file mode 100644 index 0000000..a442d5d --- /dev/null +++ b/docs/flake-module.nix @@ -0,0 +1,20 @@ +{ + perSystem = { config, pkgs, ... }: + let + doc-options = import ./options.nix { }; + + in + { + packages.doc-options = pkgs.callPackage ./options.nix { }; + + checks.doc-options = pkgs.runCommand "doc-options-check" { } '' + if diff --color -u ${./modules/ROOT/partials/NixOSOptions.adoc} ${config.packages.doc-options}; then + touch $out + else + echo 1>&2 "The doc options have changed and need to be added." + echo 1>&2 "Please run ./update-options in the root of your arion clone." + exit 1 + fi + ''; + }; +} diff --git a/flake.lock b/flake.lock index 4e92b89..79b7879 100644 --- a/flake.lock +++ b/flake.lock @@ -1,21 +1,61 @@ { "nodes": { - "nixpkgs": { + "flake-parts": { + "inputs": { + "nixpkgs-lib": [ + "nixpkgs" + ] + }, "locked": { - "lastModified": 1601906239, - "narHash": "sha256-P1jBYbYeFswig/0FKbgh+BpVhh9iurD3m0T2ae4gdx8=", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "c2bb4af48d26ed091e5674394bacbf8d488c7939", + "lastModified": 1669931201, + "narHash": "sha256-UnYFeaLPLj7e4eEt4GJooeJZhaZXyloQZYinwO/CeUw=", + "owner": "hercules-ci", + "repo": "flake-parts", + "rev": "995d6bc162c0539998ef6375c2c6b612972dc016", "type": "github" }, "original": { - "id": "nixpkgs", - "type": "indirect" + "owner": "hercules-ci", + "ref": "easyOverlay", + "repo": "flake-parts", + "type": "github" + } + }, + "haskell-flake": { + "locked": { + "lastModified": 1668167720, + "narHash": "sha256-5wDTR6xt9BB3BjgKR+YOjOkZgMyDXKaX79g42sStzDU=", + "owner": "srid", + "repo": "haskell-flake", + "rev": "4fc511d93a55fedf815c1647ad146c26d7a2054e", + "type": "github" + }, + "original": { + "owner": "srid", + "repo": "haskell-flake", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1649668654, + "narHash": "sha256-XLLs2mjsnl4Yl9rBpfEwgvm+Tzd+RIta0N7lYdsbxHY=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "14aa201b658f43546b00153bb2ada7206ba8dd26", + "type": "github" + }, + "original": { + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "14aa201b658f43546b00153bb2ada7206ba8dd26", + "type": "github" } }, "root": { "inputs": { + "flake-parts": "flake-parts", + "haskell-flake": "haskell-flake", "nixpkgs": "nixpkgs" } } diff --git a/flake.nix b/flake.nix index b7fb810..ea674e4 100644 --- a/flake.nix +++ b/flake.nix @@ -1,44 +1,91 @@ { description = "Arion - use Docker Compose via Nix"; - outputs = { self, nixpkgs }: - let - lib = import (nixpkgs + "/lib"); - systems = [ - "aarch64-linux" - "x86_64-darwin" - "x86_64-linux" - ]; - arionFromPkgs = pkgs: import ./nix/arion.nix { inherit pkgs; }; - in { - - # The overlay is currently the recommended way to integrate arion, - # because its arion attribute behaves just like Nixpkgs. - overlay = final: prev: { - arion = arionFromPkgs final; - }; - - packages = lib.genAttrs systems (system: - let - pkgs = nixpkgs.legacyPackages.${system}; - in - { - arion = arionFromPkgs pkgs; - }); - - # Does not include the eval and build functions like you may expect from Nixpkgs. - defaultPackage = lib.genAttrs systems (system: - self.packages.${system}.arion - ); - - lib = { - eval = import ./src/nix/eval-composition.nix; - build = args@{...}: - let composition = self.lib.eval args; - in composition.config.out.dockerComposeYaml; - }; - - nixosModules.arion = ./nixos-module.nix; - + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/14aa201b658f43546b00153bb2ada7206ba8dd26"; # TODO nixos-unstable + haskell-flake.url = "github:srid/haskell-flake"; + flake-parts.url = "github:hercules-ci/flake-parts/easyOverlay"; # TODO merge + flake-parts.inputs.nixpkgs-lib.follows = "nixpkgs"; }; + + outputs = inputs@{ self, flake-parts, ... }: + flake-parts.lib.mkFlake { inherit self; } ({ config, lib, extendModules, ... }: { + imports = [ + inputs.haskell-flake.flakeModule + inputs.flake-parts.flakeModules.easyOverlay + ./docs/flake-module.nix + ./tests/flake-module.nix + ]; + # FIXME use: systems = inputs.nixpkgs.lib.systems.flakeExposed; + systems = [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin" ]; + perSystem = { config, self', inputs', pkgs, system, final, ... }: + let h = pkgs.haskell.lib.compose; in + { + overlayAttrs = { + inherit (config.packages) arion; + arionTestingFlags = { + dockerSupportsSystemd = false; + }; + }; + packages.default = config.packages.arion; + packages.overlay-test = final.arion; + packages.arion = import ./nix/arion.nix { inherit pkgs; }; + haskellProjects.haskell-package = { + # not autodetected: https://github.com/srid/haskell-flake/issues/49 + packages.arion-compose.root = ./.; + + overrides = + self: super: { + arion-compose = + lib.pipe super.arion-compose [ + (h.addBuildTools [ pkgs.nix ]) + (h.overrideCabal (o: { + src = pkgs.lib.sourceByRegex ./. [ + ".*[.]cabal" + "LICENSE" + "src/?.*" + "README.asciidoc" + "CHANGELOG.md" + ]; + preCheck = '' + export NIX_LOG_DIR=$TMPDIR + export NIX_STATE_DIR=$TMPDIR + export NIX_PATH=nixpkgs=${pkgs.path} + ''; + })) + ]; + }; + }; + devShells.default = config.devShells.haskell-package.overrideAttrs (o: { + nativeBuildInputs = o.nativeBuildInputs or [ ] ++ [ + pkgs.docker-compose + pkgs.nixpkgs-fmt + config.haskellProjects.haskell-package.haskellPackages.releaser + ]; + }); + }; + flake = { + debug = { inherit inputs config lib; }; + + defaultPackage = + lib.mapAttrs + (ps: lib.warn "arion.defaultPackage has been removed in favor of arion.packages.\${system}.default" + ps.default) + config.flake.packages; + + lib = { + eval = import ./src/nix/eval-composition.nix; + build = args@{ ... }: + let composition = self.lib.eval args; + in composition.config.out.dockerComposeYaml; + }; + nixosModules.arion = ./nixos-module.nix; + herculesCI.ciSystems = [ + # "aarch64-darwin" + # "aarch64-linux" + "x86_64-darwin" + "x86_64-linux" + ]; + }; + }); } diff --git a/nix/ci.nix b/nix/ci.nix deleted file mode 100644 index 1e53108..0000000 --- a/nix/ci.nix +++ /dev/null @@ -1,46 +0,0 @@ -let - sources = import ./sources.nix; - lib = import (sources."nixos-unstable" + "/lib"); - inherit (import (sources."project.nix" + "/lib/dimension.nix") { inherit lib; }) dimension; -in - -dimension "Nixpkgs version" { - "nixos-22_05" = { - nixpkgsSource = "nixos-22.05"; - enableDoc = true; - }; - "nixos-unstable" = { - nixpkgsSource = "nixos-unstable"; - isReferenceNixpkgs = true; # match ./default.nix - enableDoc = true; - }; - } ( - _name: { nixpkgsSource, isReferenceNixpkgs ? false, enableDoc ? true, - dockerSupportsSystemd ? false, nixosHasPodmanDockerSocket ? true }: - - - dimension "System" { - "x86_64-linux" = { isReferenceTarget = isReferenceNixpkgs; }; - "x86_64-darwin" = { enableNixOSTests = false; }; - } ( - system: { isReferenceTarget ? false, enableNixOSTests ? true }: - let - pkgs = import ./. { - inherit system dockerSupportsSystemd nixosHasPodmanDockerSocket; - nixpkgsSrc = sources.${nixpkgsSource}; - }; - in - { - inherit (pkgs) arion; - } // lib.optionalAttrs enableNixOSTests { - inherit (pkgs) tests; - } // lib.optionalAttrs enableDoc { - inherit (pkgs) - # FIXME: nixpkgs antora packaging is broken - # doc - doc-options doc-options-check; - } // lib.optionalAttrs isReferenceTarget { - inherit (pkgs.arion-project.haskellPkgs) arion-compose-checked; - } - ) - ) diff --git a/nix/compat.nix b/nix/compat.nix new file mode 100644 index 0000000..f867cea --- /dev/null +++ b/nix/compat.nix @@ -0,0 +1,10 @@ +(import + ( + let lock = builtins.fromJSON (builtins.readFile ./flake.lock); in + fetchTarball { + url = "https://github.com/edolstra/flake-compat/archive/009399224d5e398d03b22badca40a37ac85412a1.tar.gz"; + sha256 = "sha256:0xcr9fibnapa12ywzcnlf54wrmbqqb96fmmv8043zhsycws7bpqy"; + } + ) + { src = ../.; } +).defaultNix diff --git a/nix/default.nix b/nix/default.nix deleted file mode 100644 index 5cc58ac..0000000 --- a/nix/default.nix +++ /dev/null @@ -1,23 +0,0 @@ -{ sources ? import ./sources.nix -, nixpkgsName ? "nixos-unstable" # match ./ci.nix isReferenceNixpkgs -, nixpkgsSrc ? sources.${nixpkgsName} -, system ? builtins.currentSystem -, dockerSupportsSystemd ? false -, nixosHasPodmanDockerSocket ? true -, ... -}: - -import nixpkgsSrc ({ - # Makes the config pure as well. See /top-level/impure.nix: - config = { - }; - overlays = [ - (_: _: { - arionTestingFlags = { - inherit dockerSupportsSystemd nixosHasPodmanDockerSocket; - }; - }) - (import ./overlay.nix) - ]; - inherit system; -}) diff --git a/nix/haskell-overlay.nix b/nix/haskell-overlay.nix deleted file mode 100644 index f0c5ccb..0000000 --- a/nix/haskell-overlay.nix +++ /dev/null @@ -1,16 +0,0 @@ -self: super: hself: hsuper: -{ - arion-compose = import ./haskell-arion-compose.nix { pkgs = self; haskellPackages = hself; }; - arion-compose-checked = - let pkg = /* super.haskell.lib.buildStrictly currently broken in nixos-unstable */ hself.arion-compose; - checked = super.haskell.lib.overrideCabal pkg (o: { - postConfigure = ''${o.postConfigure or ""} - if ! ${hsuper.cabal-install}/bin/cabal check; - then - echo 1>&2 ERROR: cabal file is invalid. Above warnings were errors. - exit 1 - fi - ''; - }); - in checked; -} \ No newline at end of file diff --git a/nix/overlay.nix b/nix/overlay.nix deleted file mode 100644 index ecdb6af..0000000 --- a/nix/overlay.nix +++ /dev/null @@ -1,60 +0,0 @@ -self: super: -let - inherit (self.arion-project) haskellPkgs; - inherit (super) lib; - - sources = import ./sources.nix; - - fakeRepo = src: super.runCommand "source" { inherit src; nativeBuildInputs = [super.git]; } '' - cp -r --no-preserve=mode $src $out - git init - cp -r .git $out - ''; - -in -{ - - inherit (import ./.. { pkgs = self; }) arion; - tests = super.callPackage ../tests {}; - - doc-options = import ../docs/options.nix {}; - doc-options-check = self.runCommand "doc-options-check" {} '' - if diff --color -u ${../docs/modules/ROOT/partials/NixOSOptions.adoc} ${self.doc-options}; then - touch $out - else - echo 1>&2 "The doc options have changed and need to be added." - echo 1>&2 "Please run ./update-options in the root of your arion clone." - exit 1 - fi - ''; - doc = self.stdenv.mkDerivation { - name = "arion-documentation"; - nativeBuildInputs = [super.antora]; - src = fakeRepo ../.; - HOME = "."; - buildPhase = "antora antora-playbook"; - installPhase = '' - mkdir $out - mv public/* $out/ - ''; - }; - - arion-project = super.recurseIntoAttrs { - haskellPkgs = super.haskellPackages.extend (import ./haskell-overlay.nix self super); - shell = haskellPkgs.shellFor { - packages = p: [p.arion-compose]; - nativeBuildInputs = [ - haskellPkgs.cabal-install - haskellPkgs.ghcid - haskellPkgs.haskell-language-server - super.docker-compose - self.niv - self.nixpkgs-fmt - self.releaser - ]; - }; - }; - - inherit (import (sources.niv) {}) niv; - releaser = self.haskellPackages.callCabal2nix "releaser" sources.releaser {}; -} diff --git a/nix/sources.json b/nix/sources.json deleted file mode 100644 index 037ef0c..0000000 --- a/nix/sources.json +++ /dev/null @@ -1,63 +0,0 @@ -{ - "niv": { - "branch": "master", - "description": "Easy dependency management for Nix projects", - "homepage": "https://github.com/nmattia/niv", - "owner": "nmattia", - "repo": "niv", - "rev": "fad2a6cbfb2e7cdebb7cb0ad2f5cc91e2c9bc06b", - "sha256": "0mghc1j0rd15spdjx81bayjqr0khc062cs25y5dcfzlxk4ynyc6m", - "type": "tarball", - "url": "https://github.com/nmattia/niv/archive/fad2a6cbfb2e7cdebb7cb0ad2f5cc91e2c9bc06b.tar.gz", - "url_template": "https://github.com///archive/.tar.gz" - }, - "nixos-22.05": { - "branch": "nixos-22.05", - "description": "Nix Packages collection", - "homepage": null, - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "a634c8f6c1fbf9b9730e01764999666f3436f10a", - "sha256": "1d40v43x972li5fg7jadxkj341li41mf2cl6vv7xi6j80rkq45q4", - "type": "tarball", - "url": "https://github.com/NixOS/nixpkgs/archive/a634c8f6c1fbf9b9730e01764999666f3436f10a.tar.gz", - "url_template": "https://github.com///archive/.tar.gz" - }, - "nixos-unstable": { - "branch": "lib-modules-allow-disable-_modules.args-docs-internal", - "description": "A read-only mirror of NixOS/nixpkgs tracking the released channels. Send issues and PRs to", - "homepage": "https://github.com/NixOS/nixpkgs", - "owner": "hercules-ci", - "repo": "nixpkgs", - "rev": "14aa201b658f43546b00153bb2ada7206ba8dd26", - "sha256": "0xn43gdn3rfys1d8ni3y6x7vxyc263qsbhfsjwc5x7pcd3dfrcjw", - "type": "tarball", - "url": "https://github.com/hercules-ci/nixpkgs/archive/14aa201b658f43546b00153bb2ada7206ba8dd26.tar.gz", - "url_template": "https://github.com///archive/.tar.gz", - "version": "" - }, - "project.nix": { - "branch": "master", - "description": "A configuration manager for your projects", - "homepage": null, - "owner": "hercules-ci", - "repo": "project.nix", - "rev": "2e598501e7fda6993d2a1a281aa296b26d01e10c", - "sha256": "1rkzpzxpg69px6qwchdlg4xf5irv0snrzk2l6vrs9rsx48gqax9j", - "type": "tarball", - "url": "https://github.com/hercules-ci/project.nix/archive/2e598501e7fda6993d2a1a281aa296b26d01e10c.tar.gz", - "url_template": "https://github.com///archive/.tar.gz" - }, - "releaser": { - "branch": "master", - "description": "Automation of Haskell package release process.", - "homepage": null, - "owner": "domenkozar", - "repo": "releaser", - "rev": "52a2bb0b2ce0bc15d4e7b11d8761a28d82c0c083", - "sha256": "178lv0a0qxd8six0rm83j7wjwlsad1hysdrk4mb38fagbb8csagb", - "type": "tarball", - "url": "https://github.com/domenkozar/releaser/archive/52a2bb0b2ce0bc15d4e7b11d8761a28d82c0c083.tar.gz", - "url_template": "https://github.com///archive/.tar.gz" - } -} diff --git a/nix/sources.nix b/nix/sources.nix deleted file mode 100644 index b796fff..0000000 --- a/nix/sources.nix +++ /dev/null @@ -1,171 +0,0 @@ -# This file has been generated by Niv. - -let - - # - # The fetchers. fetch_ fetches specs of type . - # - - fetch_file = pkgs: name: spec: - let - name' = sanitizeName name + "-src"; - in - if spec.builtin or true then - builtins_fetchurl { inherit (spec) url sha256; name = name'; } - else - pkgs.fetchurl { inherit (spec) url sha256; name = name'; }; - - fetch_tarball = pkgs: name: spec: - let - name' = sanitizeName name + "-src"; - in - if spec.builtin or true then - builtins_fetchTarball { name = name'; inherit (spec) url sha256; } - else - pkgs.fetchzip { name = name'; inherit (spec) url sha256; }; - - fetch_git = name: spec: - let - ref = - if spec ? ref then spec.ref else - if spec ? branch then "refs/heads/${spec.branch}" else - if spec ? tag then "refs/tags/${spec.tag}" else - abort "In git source '${name}': Please specify `ref`, `tag` or `branch`!"; - in - builtins.fetchGit { url = spec.repo; inherit (spec) rev; inherit ref; }; - - fetch_local = spec: spec.path; - - fetch_builtin-tarball = name: throw - ''[${name}] The niv type "builtin-tarball" is deprecated. You should instead use `builtin = true`. - $ niv modify ${name} -a type=tarball -a builtin=true''; - - fetch_builtin-url = name: throw - ''[${name}] The niv type "builtin-url" will soon be deprecated. You should instead use `builtin = true`. - $ niv modify ${name} -a type=file -a builtin=true''; - - # - # Various helpers - # - - # https://github.com/NixOS/nixpkgs/pull/83241/files#diff-c6f540a4f3bfa4b0e8b6bafd4cd54e8bR695 - sanitizeName = name: - ( - concatMapStrings (s: if builtins.isList s then "-" else s) - ( - builtins.split "[^[:alnum:]+._?=-]+" - ((x: builtins.elemAt (builtins.match "\\.*(.*)" x) 0) name) - ) - ); - - # The set of packages used when specs are fetched using non-builtins. - mkPkgs = sources: system: - let - sourcesNixpkgs = - import (builtins_fetchTarball { inherit (sources.nixpkgs) url sha256; }) { inherit system; }; - hasNixpkgsPath = builtins.any (x: x.prefix == "nixpkgs") builtins.nixPath; - hasThisAsNixpkgsPath = == ./.; - in - if builtins.hasAttr "nixpkgs" sources - then sourcesNixpkgs - else if hasNixpkgsPath && ! hasThisAsNixpkgsPath then - import {} - else - abort - '' - Please specify either (through -I or NIX_PATH=nixpkgs=...) or - add a package called "nixpkgs" to your sources.json. - ''; - - # The actual fetching function. - fetch = pkgs: name: spec: - - if ! builtins.hasAttr "type" spec then - abort "ERROR: niv spec ${name} does not have a 'type' attribute" - else if spec.type == "file" then fetch_file pkgs name spec - else if spec.type == "tarball" then fetch_tarball pkgs name spec - else if spec.type == "git" then fetch_git name spec - else if spec.type == "local" then fetch_local spec - else if spec.type == "builtin-tarball" then fetch_builtin-tarball name - else if spec.type == "builtin-url" then fetch_builtin-url name - else - abort "ERROR: niv spec ${name} has unknown type ${builtins.toJSON spec.type}"; - - # If the environment variable NIV_OVERRIDE_${name} is set, then use - # the path directly as opposed to the fetched source. - replace = name: drv: - let - saneName = stringAsChars (c: if isNull (builtins.match "[a-zA-Z0-9]" c) then "_" else c) name; - ersatz = builtins.getEnv "NIV_OVERRIDE_${saneName}"; - in - if ersatz == "" then drv else ersatz; - - # Ports of functions for older nix versions - - # a Nix version of mapAttrs if the built-in doesn't exist - mapAttrs = builtins.mapAttrs or ( - f: set: with builtins; - listToAttrs (map (attr: { name = attr; value = f attr set.${attr}; }) (attrNames set)) - ); - - # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/lists.nix#L295 - range = first: last: if first > last then [] else builtins.genList (n: first + n) (last - first + 1); - - # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/strings.nix#L257 - stringToCharacters = s: map (p: builtins.substring p 1 s) (range 0 (builtins.stringLength s - 1)); - - # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/strings.nix#L269 - stringAsChars = f: s: concatStrings (map f (stringToCharacters s)); - concatMapStrings = f: list: concatStrings (map f list); - concatStrings = builtins.concatStringsSep ""; - - # https://github.com/NixOS/nixpkgs/blob/8a9f58a375c401b96da862d969f66429def1d118/lib/attrsets.nix#L331 - optionalAttrs = cond: as: if cond then as else {}; - - # fetchTarball version that is compatible between all the versions of Nix - builtins_fetchTarball = { url, name ? null, sha256 }@attrs: - let - inherit (builtins) lessThan nixVersion fetchTarball; - in - if lessThan nixVersion "1.12" then - fetchTarball ({ inherit url; } // (optionalAttrs (!isNull name) { inherit name; })) - else - fetchTarball attrs; - - # fetchurl version that is compatible between all the versions of Nix - builtins_fetchurl = { url, name ? null, sha256 }@attrs: - let - inherit (builtins) lessThan nixVersion fetchurl; - in - if lessThan nixVersion "1.12" then - fetchurl ({ inherit url; } // (optionalAttrs (!isNull name) { inherit name; })) - else - fetchurl attrs; - - # Create the final "sources" from the config - mkSources = config: - mapAttrs ( - name: spec: - if builtins.hasAttr "outPath" spec - then abort - "The values in sources.json should not have an 'outPath' attribute" - else - spec // { outPath = replace name (fetch config.pkgs name spec); } - ) config.sources; - - # The "config" used by the fetchers - mkConfig = - { sourcesFile ? if builtins.pathExists ./sources.json then ./sources.json else null - , sources ? if isNull sourcesFile then {} else builtins.fromJSON (builtins.readFile sourcesFile) - , system ? builtins.currentSystem - , pkgs ? mkPkgs sources system - }: rec { - # The sources, i.e. the attribute set of spec name to spec - inherit sources; - - # The "pkgs" (evaluated nixpkgs) to use for e.g. non-builtin fetchers - inherit pkgs; - }; - -in -mkSources (mkConfig {}) // { __functor = _: settings: mkSources (mkConfig settings); } diff --git a/shell.nix b/shell.nix index f6c0ea0..8745f50 100644 --- a/shell.nix +++ b/shell.nix @@ -1 +1 @@ -args@{...}: (import ./nix args).arion-project.shell +(builtins.getFlake ("git+file://" + toString ./.)).devShells.${builtins.currentSystem}.default diff --git a/tests/arion-test/default.nix b/tests/arion-test/default.nix index 9c7a14a..6035d0d 100644 --- a/tests/arion-test/default.nix +++ b/tests/arion-test/default.nix @@ -1,4 +1,4 @@ -{ usePodman ? false, pkgs, lib, ... }: +{ usePodman ? false, pkgs, lib ? pkgs.lib, ... }: let # To make some prebuilt derivations available in the vm diff --git a/tests/default.nix b/tests/default.nix deleted file mode 100644 index 70012ac..0000000 --- a/tests/default.nix +++ /dev/null @@ -1,46 +0,0 @@ -{ pkgs ? import ../pkgs.nix, arionTestingFlags ? {} }: -let - inherit (pkgs) nixosTest recurseIntoAttrs arion lib; - - hasEvalModulesType = (lib.evalModules { modules = [ {} ]; })?type; - -in - -recurseIntoAttrs { - - test = nixosTest ./arion-test; - - nixosModuleWithDocker = - lib.optionalAttrs - hasEvalModulesType - ( - import ./nixos-virtualization-arion-test/test.nix pkgs { - virtualisation.arion.backend = "docker"; - } - ); - - nixosModuleWithPodman = - lib.optionalAttrs - (hasEvalModulesType && arionTestingFlags.nixosHasPodmanDockerSocket) - ( - import ./nixos-virtualization-arion-test/test.nix pkgs { - virtualisation.arion.backend = "podman-socket"; - } - ); - - testWithPodman = - if arionTestingFlags.nixosHasPodmanDockerSocket - then nixosTest (import ./arion-test { usePodman = true; inherit pkgs lib; }) - else {}; - - testBuild = arion.build { - - # To be more accurately, you can do - # pkgs = import ../examples/minimal/arion-pkgs.nix; - # but this is quite efficient: - inherit pkgs; - - modules = [ ../examples/minimal/arion-compose.nix ]; - }; - -} diff --git a/tests/flake-module.nix b/tests/flake-module.nix new file mode 100644 index 0000000..bbfdb1d --- /dev/null +++ b/tests/flake-module.nix @@ -0,0 +1,35 @@ +{ + perSystem = { pkgs, final, ... }: + let + inherit (final) nixosTest arion lib; + in + { + checks = lib.optionalAttrs pkgs.stdenv.isLinux { + test = nixosTest ./arion-test; + + nixosModuleWithDocker = + import ./nixos-virtualization-arion-test/test.nix final { + virtualisation.arion.backend = "docker"; + }; + + nixosModuleWithPodman = + import ./nixos-virtualization-arion-test/test.nix final { + virtualisation.arion.backend = "podman-socket"; + }; + + testWithPodman = + nixosTest (import ./arion-test { usePodman = true; pkgs = final; }); + + testBuild = arion.build { + + # To be more accurate, we could do + # pkgs = import ../examples/minimal/arion-pkgs.nix; + # But let's avoid re-evaluating Nixpkgs + pkgs = final; + + modules = [ ../examples/minimal/arion-compose.nix ]; + }; + + }; + }; +} diff --git a/update-options b/update-options index 14a66e9..0e7a02c 100755 --- a/update-options +++ b/update-options @@ -1,9 +1,9 @@ #!/usr/bin/env nix-shell -#!nix-shell -i bash +#!nix-shell -i bash -p jq set -eu -o pipefail cd "$(dirname ${BASH_SOURCE[0]})" -doc_options="$(nix-build nix -A doc-options)" +doc_options="$(nix build .#doc-options --json | jq -r .[].outputs.out)" cat "$doc_options" >docs/modules/ROOT/partials/NixOSOptions.adoc From 890f9d94289c32e8b2ddfda6ca43f4b82554b32a Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Thu, 1 Dec 2022 23:43:51 +0000 Subject: [PATCH 2/4] flake.nix: Update nixpkgs --- docs/modules/ROOT/partials/NixOSOptions.adoc | 62 +++++++++---------- flake.lock | 8 +-- flake.nix | 5 +- .../service/docker-compose-service.nix | 1 + 4 files changed, 38 insertions(+), 38 deletions(-) diff --git a/docs/modules/ROOT/partials/NixOSOptions.adoc b/docs/modules/ROOT/partials/NixOSOptions.adoc index 131bf4f..68bbcd9 100644 --- a/docs/modules/ROOT/partials/NixOSOptions.adoc +++ b/docs/modules/ROOT/partials/NixOSOptions.adoc @@ -102,7 +102,7 @@ See link:https://docs.docker.com/compose/compose-file/#networks-top-level-elemen [discrete] === details -Type:: lazy attribute set of submodules +Type:: lazy attribute set of (submodule) No Default:: {blank} No Example:: {blank} @@ -147,7 +147,7 @@ See link:https://docs.docker.com/compose/compose-file/#driver_opts[Docker Compos [discrete] === details -Type:: lazy attribute set of raw values +Type:: lazy attribute set of raw value No Default:: {blank} No Example:: {blank} @@ -228,7 +228,7 @@ See link:https://docs.docker.com/compose/compose-file/#labels[Docker Compose#lab [discrete] === details -Type:: attribute set of strings +Type:: attribute set of string No Default:: {blank} No Example:: {blank} @@ -271,7 +271,7 @@ The text of out.dockerComposeYaml. [discrete] === details -Type:: attribute set of unspecifieds +Type:: attribute set of unspecified value No Default:: {blank} Read Only:: {blank} No Example:: {blank} @@ -312,7 +312,7 @@ An attribute set of service configurations. A service specifies how to run an im [discrete] === details -Type:: attribute set of submodules +Type:: attribute set of (submodule) No Default:: {blank} No Example:: {blank} @@ -350,7 +350,7 @@ No Example:: {blank} [discrete] === details -Type:: list of strings +Type:: list of string Default:: + ---- @@ -368,7 +368,7 @@ Top level paths in the container. [discrete] === details -Type:: list of packages +Type:: list of package Default:: + ---- @@ -453,7 +453,7 @@ v1.2.0]. [discrete] === details -Type:: attribute set of unspecifieds +Type:: attribute set of unspecified value Default:: + ---- @@ -494,7 +494,7 @@ NixOS configuration can be used in other ways. [discrete] === details -Type:: list of unspecifieds or unspecified convertible to it +Type:: (list of unspecified value) or unspecified value convertible to it Default:: + ---- @@ -554,7 +554,7 @@ It will be inserted in `x-arion.serviceInfo.`. [discrete] === details -Type:: attribute set of unspecifieds +Type:: attribute set of unspecified value Default:: + ---- @@ -578,7 +578,7 @@ escape hatch for some. [discrete] === details -Type:: attribute set of unspecifieds +Type:: attribute set of unspecified value No Default:: {blank} No Example:: {blank} @@ -618,7 +618,7 @@ according to Docker's link:https://docs.docker.com/engine/reference/run/#runtime [discrete] === details -Type:: attribute set of null or booleans +Type:: attribute set of (null or boolean) Default:: + ---- @@ -640,7 +640,7 @@ See link:https://docs.docker.com/compose/compose-file/#command[Docker Compose#co [discrete] === details -Type:: null or unspecified +Type:: null or unspecified value Default:: + ---- @@ -676,7 +676,7 @@ Container program and arguments to invoke when calling [discrete] === details -Type:: list of strings +Type:: list of string Default:: + ---- @@ -693,7 +693,7 @@ See link:https://docs.docker.com/compose/compose-file/#depends_on[Docker Compose [discrete] === details -Type:: list of strings or attribute set of submodules +Type:: (list of string) or attribute set of (submodule) Default:: + ---- @@ -713,7 +713,7 @@ See link:https://docs.docker.com/compose/compose-file/#devices[Docker Compose#de [discrete] === details -Type:: list of strings +Type:: list of string Default:: + ---- @@ -730,7 +730,7 @@ See link:https://docs.docker.com/compose/compose-file/#dns[Docker Compose#dns] [discrete] === details -Type:: list of strings +Type:: list of string Default:: + ---- @@ -769,7 +769,7 @@ See link:https://docs.docker.com/compose/compose-file/#env_file[Docker Compose#e [discrete] === details -Type:: list of strings +Type:: list of string Default:: + ---- @@ -786,7 +786,7 @@ See link:https://docs.docker.com/compose/compose-file/#environment[Docker Compos [discrete] === details -Type:: attribute set of string or signed integers +Type:: attribute set of (string or signed integer) Default:: + ---- @@ -803,7 +803,7 @@ See link:https://docs.docker.com/compose/compose-file/#expose[Docker Compose#exp [discrete] === details -Type:: list of strings +Type:: list of string Default:: + ---- @@ -820,7 +820,7 @@ See link:https://docs.docker.com/compose/compose-file/#external_links[Docker Com [discrete] === details -Type:: list of strings +Type:: list of string Default:: + ---- @@ -837,7 +837,7 @@ See link:https://docs.docker.com/compose/compose-file/#extra_hosts[Docker Compos [discrete] === details -Type:: list of strings +Type:: list of string Default:: + ---- @@ -849,7 +849,7 @@ No Example:: {blank} == services..service.healthcheck -None +See link:https://docs.docker.com/compose/compose-file/#healthcheck[Docker Compose#healthcheck] [discrete] === details @@ -927,7 +927,7 @@ See link:https://docs.docker.com/compose/compose-file/#healthcheck[Docker Compos [discrete] === details -Type:: null or list of strings +Type:: null or (list of string) Default:: + ---- @@ -1020,7 +1020,7 @@ See link:https://docs.docker.com/compose/compose-file/#labels[Docker Compose#lab [discrete] === details -Type:: attribute set of strings +Type:: attribute set of string Default:: + ---- @@ -1042,7 +1042,7 @@ See link:https://docs.docker.com/compose/compose-file/#links[Docker Compose#link [discrete] === details -Type:: list of strings +Type:: list of string Default:: + ---- @@ -1089,7 +1089,7 @@ See link:https://docs.docker.com/compose/compose-file/#networks[Docker Compose#n [discrete] === details -Type:: null or list of strings +Type:: null or (list of string) Default:: + ---- @@ -1109,7 +1109,7 @@ See link:https://docs.docker.com/compose/compose-file/#ports[Docker Compose#port [discrete] === details -Type:: list of unspecifieds +Type:: list of unspecified value Default:: + ---- @@ -1180,7 +1180,7 @@ See link:https://docs.docker.com/compose/compose-file/#sysctls[Docker Compose#sy [discrete] === details -Type:: attribute set of string or signed integers +Type:: attribute set of (string or signed integer) Default:: + ---- @@ -1197,7 +1197,7 @@ See link:https://docs.docker.com/compose/compose-file/#tmpfs[Docker Compose#tmpf [discrete] === details -Type:: list of strings +Type:: list of string Default:: + ---- @@ -1288,7 +1288,7 @@ See link:https://docs.docker.com/compose/compose-file/#volumes[Docker Compose#vo [discrete] === details -Type:: list of unspecifieds +Type:: list of unspecified value Default:: + ---- diff --git a/flake.lock b/flake.lock index 79b7879..b5bf0a3 100644 --- a/flake.lock +++ b/flake.lock @@ -38,17 +38,17 @@ }, "nixpkgs": { "locked": { - "lastModified": 1649668654, - "narHash": "sha256-XLLs2mjsnl4Yl9rBpfEwgvm+Tzd+RIta0N7lYdsbxHY=", + "lastModified": 1669791787, + "narHash": "sha256-KBfoA2fOI5+wCrm7PR+j7jHqXeTkVRPQ0m5fcKchyuU=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "14aa201b658f43546b00153bb2ada7206ba8dd26", + "rev": "e76c78d20685a043d23f5f9e0ccd2203997f1fb1", "type": "github" }, "original": { "owner": "NixOS", + "ref": "nixos-unstable", "repo": "nixpkgs", - "rev": "14aa201b658f43546b00153bb2ada7206ba8dd26", "type": "github" } }, diff --git a/flake.nix b/flake.nix index ea674e4..3ec601c 100644 --- a/flake.nix +++ b/flake.nix @@ -2,7 +2,7 @@ description = "Arion - use Docker Compose via Nix"; inputs = { - nixpkgs.url = "github:NixOS/nixpkgs/14aa201b658f43546b00153bb2ada7206ba8dd26"; # TODO nixos-unstable + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; haskell-flake.url = "github:srid/haskell-flake"; flake-parts.url = "github:hercules-ci/flake-parts/easyOverlay"; # TODO merge flake-parts.inputs.nixpkgs-lib.follows = "nixpkgs"; @@ -16,8 +16,7 @@ ./docs/flake-module.nix ./tests/flake-module.nix ]; - # FIXME use: systems = inputs.nixpkgs.lib.systems.flakeExposed; - systems = [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin" ]; + systems = inputs.nixpkgs.lib.systems.flakeExposed; perSystem = { config, self', inputs', pkgs, system, final, ... }: let h = pkgs.haskell.lib.compose; in { diff --git a/src/nix/modules/service/docker-compose-service.nix b/src/nix/modules/service/docker-compose-service.nix index 350c215..f1a6875 100644 --- a/src/nix/modules/service/docker-compose-service.nix +++ b/src/nix/modules/service/docker-compose-service.nix @@ -117,6 +117,7 @@ in description = dockerComposeRef "depends_on"; }; service.healthcheck = mkOption { + description = dockerComposeRef "healthcheck"; type = submodule ({ config, options, ...}: { options = { _out = mkOption { From 7987c7ec0d5264a063d58bb0b017144b379870c8 Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Fri, 2 Dec 2022 10:06:43 +0000 Subject: [PATCH 3/4] Fix nixos-unit nginx test --- examples/nixos-unit/arion-compose.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/nixos-unit/arion-compose.nix b/examples/nixos-unit/arion-compose.nix index 642a18e..a8d3df4 100644 --- a/examples/nixos-unit/arion-compose.nix +++ b/examples/nixos-unit/arion-compose.nix @@ -36,8 +36,8 @@ echo nginx:x:${toString config.users.groups.nginx.gid}:nginx >>/etc/group echo 'nobody:x:65534:65534:Unprivileged account do not use:/var/empty:/run/current-system/sw/bin/nologin' >>/etc/passwd echo 'nogroup:x:65534:' >>/etc/group - mkdir -p /var/log/nginx /run/nginx/ /var/cache/nginx /var/lib/nginx/{,logs,proxy_temp,client_body_temp,fastcgi_temp,scgi_temp,uwsgi_temp} - chown nginx /var/log/nginx /run/nginx/ /var/cache/nginx /var/lib/nginx/{,logs,proxy_temp,client_body_temp,fastcgi_temp,scgi_temp,uwsgi_temp} + mkdir -p /var/log/nginx /run/nginx/ /var/cache/nginx /var/lib/nginx/{,logs,proxy_temp,client_body_temp,fastcgi_temp,scgi_temp,uwsgi_temp} /tmp/nginx_client_body + chown nginx /var/log/nginx /run/nginx/ /var/cache/nginx /var/lib/nginx/{,logs,proxy_temp,client_body_temp,fastcgi_temp,scgi_temp,uwsgi_temp} /tmp/nginx_client_body ${config.systemd.services.nginx.runner} ''; }; From b9525cef7cd95df65b85edff464713a9a2b93d1e Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Fri, 2 Dec 2022 11:34:29 +0000 Subject: [PATCH 4/4] aeson: 1 -> 2 --- arion-compose.cabal | 2 +- flake.lock | 8 ++++---- flake.nix | 2 +- src/haskell/lib/Arion/Services.hs | 3 ++- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/arion-compose.cabal b/arion-compose.cabal index 6b0c14b..1385f18 100644 --- a/arion-compose.cabal +++ b/arion-compose.cabal @@ -31,7 +31,7 @@ source-repository head common common build-depends: base >=4.12.0.0 && <4.17 - , aeson + , aeson >=2 , aeson-pretty , async , bytestring diff --git a/flake.lock b/flake.lock index b5bf0a3..e3a9e45 100644 --- a/flake.lock +++ b/flake.lock @@ -38,16 +38,16 @@ }, "nixpkgs": { "locked": { - "lastModified": 1669791787, - "narHash": "sha256-KBfoA2fOI5+wCrm7PR+j7jHqXeTkVRPQ0m5fcKchyuU=", + "lastModified": 1669980218, + "narHash": "sha256-HBK1tIqarj7ZsSwQEKGlyvbAIFnglytG7FxuS4K3nY8=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "e76c78d20685a043d23f5f9e0ccd2203997f1fb1", + "rev": "da7988fe440ef5b8779d4f76340ad7dc79ff3b33", "type": "github" }, "original": { "owner": "NixOS", - "ref": "nixos-unstable", + "ref": "haskell-updates", "repo": "nixpkgs", "type": "github" } diff --git a/flake.nix b/flake.nix index 3ec601c..826980d 100644 --- a/flake.nix +++ b/flake.nix @@ -2,7 +2,7 @@ description = "Arion - use Docker Compose via Nix"; inputs = { - nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + nixpkgs.url = "github:NixOS/nixpkgs/haskell-updates"; haskell-flake.url = "github:srid/haskell-flake"; flake-parts.url = "github:hercules-ci/flake-parts/easyOverlay"; # TODO merge flake-parts.inputs.nixpkgs-lib.follows = "nixpkgs"; diff --git a/src/haskell/lib/Arion/Services.hs b/src/haskell/lib/Arion/Services.hs index d8ecb30..249ccf7 100644 --- a/src/haskell/lib/Arion/Services.hs +++ b/src/haskell/lib/Arion/Services.hs @@ -9,6 +9,7 @@ import Prelude() import Protolude hiding (to) import qualified Data.Aeson as Aeson +import qualified Data.Aeson.Key as AK import Arion.Aeson (decodeFile) import Control.Lens @@ -20,4 +21,4 @@ getDefaultExec fp service = do v <- decodeFile fp - pure ((v :: Aeson.Value) ^.. key "x-arion" . key "serviceInfo" . key service . key "defaultExec" . _Array . traverse . _String) + pure ((v :: Aeson.Value) ^.. key "x-arion" . key "serviceInfo" . key (AK.fromText service) . key "defaultExec" . _Array . traverse . _String)