From cd7e5e7e428aabe364f55c6b909485495797d1cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Gir=C3=A3o?= Date: Fri, 22 Dec 2023 18:59:29 +0000 Subject: [PATCH] stuff --- .gitignore | 1 + dockerImage.nix | 12 ++++++++++ flake.lock | 48 ++++++++++++++-------------------------- flake.nix | 59 ++++++++++++++++++++++++++++++++++--------------- package.nix | 11 ++++----- 5 files changed, 76 insertions(+), 55 deletions(-) create mode 100644 dockerImage.nix diff --git a/.gitignore b/.gitignore index 1912f2a..8f05989 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,4 @@ shell.nix .direnv .pre-commit-config.yaml .env +result diff --git a/dockerImage.nix b/dockerImage.nix new file mode 100644 index 0000000..c11bc76 --- /dev/null +++ b/dockerImage.nix @@ -0,0 +1,12 @@ +{ dockerTools, hello }: + + +dockerTools.buildImage { + + name = "hello-docker"; + + config = { + + Cmd = [ "${hello}/bin/hello" ]; + }; +} diff --git a/flake.lock b/flake.lock index 4e7df3c..b21a642 100644 --- a/flake.lock +++ b/flake.lock @@ -3,11 +3,11 @@ "flake-compat": { "flake": false, "locked": { - "lastModified": 1673956053, - "narHash": "sha256-4gtG9iQuiKITOjNQQeQIpoIB6b16fm+504Ch3sNKLd8=", + "lastModified": 1696426674, + "narHash": "sha256-kvjfFW7WAETZlt09AgDn1MrtKzP7t90Vf7vypd3OL1U=", "owner": "edolstra", "repo": "flake-compat", - "rev": "35bb57c0c8d8b62bbfd284272c928ceb64ddbde9", + "rev": "0f9255e01c2351cc7d116c072cb317785dd33b33", "type": "github" }, "original": { @@ -18,14 +18,16 @@ }, "flake-parts": { "inputs": { - "nixpkgs-lib": "nixpkgs-lib" + "nixpkgs-lib": [ + "nixpkgs" + ] }, "locked": { - "lastModified": 1698882062, - "narHash": "sha256-HkhafUayIqxXyHH1X8d9RDl1M2CkFgZLjKD3MzabiEo=", + "lastModified": 1701473968, + "narHash": "sha256-YcVE5emp1qQ8ieHUnxt1wCZCC3ZfAS+SRRWZ2TMda7E=", "owner": "hercules-ci", "repo": "flake-parts", - "rev": "8c9fa2545007b49a5db5f650ae91f227672c3877", + "rev": "34fed993f1674c8d06d58b37ce1e0fe5eebcb9f5", "type": "github" }, "original": { @@ -39,11 +41,11 @@ "systems": "systems" }, "locked": { - "lastModified": 1685518550, - "narHash": "sha256-o2d0KcvaXzTrPRIo0kOLV0/QXHhDQ5DTi+OxcjO8xqY=", + "lastModified": 1701680307, + "narHash": "sha256-kAuep2h5ajznlPMD9rnQyffWG8EM/C73lejGofXvdM8=", "owner": "numtide", "repo": "flake-utils", - "rev": "a1720a10a6cfe8234c0e93907ffe81be440f4cef", + "rev": "4022d587cbbfd70fe950c1e2083a02621806a725", "type": "github" }, "original": { @@ -75,10 +77,10 @@ }, "nixpkgs": { "locked": { - "lastModified": 1691693223, - "narHash": "sha256-9t8ZY1XNAsWqxAJmXgg+GXqF5chORMVnBT6PSHaRV3I=", - "path": "/nix/store/kppl0knhr8p67sjfgbxdwbnw7yawggfw-source", - "rev": "18784aac1013da9b442adf29b6c7c228518b5d3f", + "lastModified": 1701389149, + "narHash": "sha256-rU1suTIEd5DGCaAXKW6yHoCfR1mnYjOXQFOaH7M23js=", + "path": "/nix/store/gjd1iiwgwv7x29b21ng2dpysbgjp6kxr-source", + "rev": "5de0b32be6e85dc1a9404c75131316e4ffbc634c", "type": "path" }, "original": { @@ -86,24 +88,6 @@ "type": "indirect" } }, - "nixpkgs-lib": { - "locked": { - "dir": "lib", - "lastModified": 1690881714, - "narHash": "sha256-h/nXluEqdiQHs1oSgkOOWF+j8gcJMWhwnZ9PFabN6q0=", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "9e1960bc196baf6881340d53dccb203a951745a2", - "type": "github" - }, - "original": { - "dir": "lib", - "owner": "NixOS", - "ref": "nixos-unstable", - "repo": "nixpkgs", - "type": "github" - } - }, "pre-commit-hooks-nix": { "inputs": { "flake-compat": "flake-compat", diff --git a/flake.nix b/flake.nix index 10d1b5f..b490423 100644 --- a/flake.nix +++ b/flake.nix @@ -1,7 +1,10 @@ { inputs = { nixpkgs.url = "flake:nixpkgs"; - flake-parts.url = "github:hercules-ci/flake-parts"; + flake-parts = { + url = "github:hercules-ci/flake-parts"; + inputs.nixpkgs-lib.follows = "nixpkgs"; + }; pre-commit-hooks-nix = { url = "github:cachix/pre-commit-hooks.nix"; inputs.nixpkgs.follows = "nixpkgs"; @@ -39,11 +42,24 @@ # module parameters provide easy access to attributes of the same # system. - packages = rec { - default = ist-discord-bot-env; - ist-discord-bot-env = pkgs.callPackage ./package.nix { }; + packages = + let + ist-discord-bot-env = pkgs.callPackage ./package.nix { }; + binStub = pkgs.writeShellScriptBin "ist-discord-bot" + '' + exec ${pkgs.nodejs_18}/bin/node ${ist-discord-bot-env}/lib/node_modules/ist-discord-bot + ''; - }; + in + rec { + default = ist-discord-bot; + # adds symlinks of hello and stack to current build and prints "links added" + ist-discord-bot = + pkgs.symlinkJoin { name = "ist-discord-bot"; paths = [ ist-discord-bot-env binStub ]; }; + + inherit ist-discord-bot-env; + # docker-img = pkgs.callPackage ./dockerImage.nix { }; + }; devShells.default = pkgs.mkShell { #Add executable packages to the nix-shell environment. @@ -65,26 +81,33 @@ ${config.pre-commit.installationScript} ''; }; - pre-commit = { - check.enable = true; - settings.settings = { - deadnix.edit = true; - }; - settings.hooks = { - actionlint.enable = true; - # denolint.enable = true; - deadnix.enable = true; - statix.enable = true; - markdownlint.enable = true; - prettier.enable = true; + + pre-commit.settings.hooks = { + treefmt.enable = true; + gitleaks = { + enable = true; + name = "gitleaks"; + description = "Prevents commiting secrets"; + entry = "${pkgs.gitleaks}/bin/gitleaks protect --verbose --redact --staged"; + pass_filenames = false; }; + actionlint.enable = true; }; + treefmt.projectRootFile = ./flake.nix; treefmt.programs = { - nixpkgs-fmt.enable = true; yamlfmt.enable = true; + nixpkgs-fmt.enable = true; + shellcheck.enable = true; shfmt.enable = true; mdformat.enable = true; + deadnix.enable = true; + statix.enable = true; + prettier.enable = true; + statix.disabled-lints = [ + "repeated_keys" + ]; + }; }; }; diff --git a/package.nix b/package.nix index 6bc8ef6..638205b 100644 --- a/package.nix +++ b/package.nix @@ -3,20 +3,21 @@ buildNpmPackage rec { pname = "ist-discord-bot"; version = "2.8.4"; - src = ./.; + src = lib.cleanSource ./.; - # npmDepsHash = lib.fakeHash; + + # npmDepsHash = lib.fakeHash; npmDepsHash = "sha256-GtacSNGPLBd+8YpPJwIVRjffPFTMjSaVoCNVVAm2Zmo="; dontNpmBuild = true; configurePhase = '' - ${nodePackages.prisma}/bin/prisma generate + ${nodePackages.prisma}/bin/prisma generate ''; - + buildPhase = '' ${typescript}/bin/tsc; - ''; + ''; postBuildPhase = '' set -exu