From 1a678d4b9d4cab3ce49abe41bc207b7fc7953345 Mon Sep 17 00:00:00 2001 From: Sarah Vaupel Date: Fri, 31 Mar 2023 14:31:19 +0000 Subject: [PATCH] chore(nix): update flake.nix and shell.nix --- flake.lock | 17 +++++++++++++ flake.nix | 74 +++++++++++++++++++++++++++++++++++++++++++++++++----- shell.nix | 3 ++- 3 files changed, 87 insertions(+), 7 deletions(-) diff --git a/flake.lock b/flake.lock index b6a59f914..3f9923aee 100644 --- a/flake.lock +++ b/flake.lock @@ -1,5 +1,21 @@ { "nodes": { + "docker-nixpkgs": { + "flake": false, + "locked": { + "lastModified": 1678089139, + "narHash": "sha256-cK0RDcxR4eWMrdZIcqNVqnjo9k2LwVmNZO3qj1ctDXU=", + "owner": "nix-community", + "repo": "docker-nixpkgs", + "rev": "2205fb4968adf683324e6d0401b74b9d250d8f56", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "docker-nixpkgs", + "type": "github" + } + }, "flake-utils": { "locked": { "lastModified": 1678901627, @@ -34,6 +50,7 @@ }, "root": { "inputs": { + "docker-nixpkgs": "docker-nixpkgs", "flake-utils": "flake-utils", "nixpkgs": "nixpkgs" } diff --git a/flake.nix b/flake.nix index 74ee40ff2..089067178 100644 --- a/flake.nix +++ b/flake.nix @@ -2,14 +2,21 @@ # # SPDX-License-Identifier: AGPL-3.0-or-later -{ +rec { inputs = { + # haskell-nix = { + # url = "github:input-output-hk/haskell.nix"; + # }; nixpkgs = { type = "github"; owner = "NixOS"; repo = "nixpkgs"; ref = "master"; }; + docker-nixpkgs = { + url = "github:nix-community/docker-nixpkgs"; + flake = false; + }; flake-utils = { type = "github"; owner = "numtide"; @@ -18,19 +25,74 @@ }; }; - outputs = { self, nixpkgs, flake-utils, ... }: flake-utils.lib.eachDefaultSystem + outputs = { self, nixpkgs, docker-nixpkgs, flake-utils, ... }: flake-utils.lib.eachDefaultSystem (system: - let pkgs = import nixpkgs { - inherit system; + let frontendSource = pkgs.lib.sourceByRegex ./. [ + "^(assets|frontend)(/.*)?$" + "^config(/(favicon\.json|robots\.txt))?$" + "^(webpack|postcss)\.config\.js$" + "^karma\.conf\.js$" + "^(package|jsconfig|\.eslintrc)\.json$" + "^\.babelrc$" + ]; + + backendSource = pkgs.lib.sourceByRegex ./. [ + "^(\.hlint|package|stack-flake)\.yaml$" + "^stack\.yaml\.lock$" + "^config(/(archive-types|mimetypes|personalised-sheet-files-collate|settings\.yml|submission-blacklist|test-settings\.yml|video-types|wordlist\.txt))?$" + "^routes$" + "^testdata(/.*)?$" + ]; + + pkgs = import nixpkgs { + inherit system overlays; config.allowUnfree = true; }; - overlay = import ./nix/maildev; + + overlays = [ + (import "${docker-nixpkgs}/overlay.nix") + + (import ./nix/maildev) + # haskell-nix.overlay + (import ./nix/uniworx { inherit inputs frontendSource backendSource; }) + (import ./nix/docker { inherit self; }) + (import ./nix/parse-changelog.nix {}) + ]; + + haskellFlake = pkgs.uniworx.flake {}; + + mkPushDocker = imageName: dockerImage: pkgs.writeScriptBin "push-${dockerImage.imageName}" '' + #!${pkgs.zsh}/bin/zsh -xe + + target=''${1-docker://registry.gitlab.com/fradrive/fradrive/${imageName}:${dockerImage.imageTag}} + [[ -n "''${1}" ]] && shift + ${pkgs.skopeo}/bin/skopeo ''${@} --insecure-policy copy docker-archive://${dockerImage} ''${target} + ''; inherit (pkgs.lib) recursiveUpdate; in { + packages = haskellFlake.packages // { + inherit (pkgs) uniworxNodeDependencies uniworxWellKnown uniworxFrontend uniworxDemoDocker uniworxDocker ciDocker changelogJson; + }; + + apps = haskellFlake.apps // { + pushUniworxDemoDocker = flake-utils.lib.mkApp { drv = mkPushDocker "uniworx-demo" pkgs.uniworxDemoDocker; }; + pushUniworxDocker = flake-utils.lib.mkApp { drv = mkPushDocker "uniworx" pkgs.uniworxDocker; }; + pushCIDocker = flake-utils.lib.mkApp { drv = mkPushDocker "nix-unstable" pkgs.ciDocker; }; + calculateMaterializedSha = flake-utils.lib.mkApp { drv = pkgs.uniworx.stack-nix.passthru.calculateMaterializedSha; execPath = ""; }; + jqChangelogJson = flake-utils.lib.mkApp { drv = pkgs.jqChangelogJson; }; + }; + + checks = haskellFlake.checks // { + uniworxFrontend = pkgs.uniworxFrontend.check; + }; + devShell = import ./shell.nix { pkgs = self.legacyPackages.${system}; nixpkgsPath = nixpkgs; }; - legacyPackages = recursiveUpdate (overlay self.legacyPackages.${system} pkgs) pkgs; + legacyPackages = pkgs.lib.foldr (overlay: acc: acc // recursiveUpdate (overlay self.legacyPackages.${system} pkgs) pkgs) {} overlays; + + defaultPackage = self.packages.${system}."uniworx:exe:uniworx"; + defaultApp = self.apps.${system}."uniworx:exe:uniworx"; } ); } diff --git a/shell.nix b/shell.nix index 56038d602..c36f0e8fd 100644 --- a/shell.nix +++ b/shell.nix @@ -1,4 +1,4 @@ -# SPDX-FileCopyrightText: 2022 Gregor Kleen ,Sarah Vaupel +# SPDX-FileCopyrightText: 2022-2023 Gregor Kleen ,Sarah Vaupel ,Steffen Jost # # SPDX-License-Identifier: AGPL-3.0-or-later @@ -284,6 +284,7 @@ in pkgs.mkShell { babel-german babel-english booktabs textpos enumitem eurosym koma-script parskip xcolor dejavu luatexbase lualatex-math unicode-math selnolig # required for LuaTeX + ; }) ] ) ++ (with pkgs.haskellPackages; [ stack yesod-bin hlint cabal-install weeder profiteur ]);