diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..fb9d00c --- /dev/null +++ b/.envrc @@ -0,0 +1,2 @@ +use flake +dotenv_if_exists .env diff --git a/.github/workflows/nix.yml b/.github/workflows/nix.yml new file mode 100644 index 0000000..9c94b0d --- /dev/null +++ b/.github/workflows/nix.yml @@ -0,0 +1,21 @@ +name: nix build + +on: + - push + - pull_request +jobs: + check_nix: + name: Check nix build + runs-on: ubuntu-latest + steps: + - name: git checkout + uses: actions/checkout@v3 + - name: Install Nix + uses: DeterminateSystems/nix-installer-action@main + with: + extra-conf: system-features = nixos-test benchmark big-parallel kvm + - uses: DeterminateSystems/magic-nix-cache-action@main + - name: Check Nix flake inputs + uses: DeterminateSystems/flake-checker-action@v4 + - name: Build lib + run: nix build -L diff --git a/.gitignore b/.gitignore index 4dc0bc7..5fd55b5 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,7 @@ tags tags.mtime .DS_Store TAGS + +.env +.direnv +result diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..4ef3877 --- /dev/null +++ b/flake.lock @@ -0,0 +1,265 @@ +{ + "nodes": { + "base16": { + "flake": false, + "locked": { + "narHash": "sha256-pLnipLnF7YuQvCwgw7Lp7sbwhab63sdEpubeSpaoEmY=", + "type": "tarball", + "url": "https://hackage.haskell.org/package/base16-1.0/base16-1.0.tar.gz" + }, + "original": { + "type": "tarball", + "url": "https://hackage.haskell.org/package/base16-1.0/base16-1.0.tar.gz" + } + }, + "flake-compat": { + "flake": false, + "locked": { + "lastModified": 1673956053, + "narHash": "sha256-4gtG9iQuiKITOjNQQeQIpoIB6b16fm+504Ch3sNKLd8=", + "owner": "edolstra", + "repo": "flake-compat", + "rev": "35bb57c0c8d8b62bbfd284272c928ceb64ddbde9", + "type": "github" + }, + "original": { + "owner": "edolstra", + "repo": "flake-compat", + "type": "github" + } + }, + "flake-compat_2": { + "flake": false, + "locked": { + "lastModified": 1673956053, + "narHash": "sha256-4gtG9iQuiKITOjNQQeQIpoIB6b16fm+504Ch3sNKLd8=", + "owner": "edolstra", + "repo": "flake-compat", + "rev": "35bb57c0c8d8b62bbfd284272c928ceb64ddbde9", + "type": "github" + }, + "original": { + "owner": "edolstra", + "repo": "flake-compat", + "type": "github" + } + }, + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1694529238, + "narHash": "sha256-zsNZZGTGnMOf9YpHKJqMSsa0dXbfmxeoJ7xHlrt+xmY=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "ff7b65b44d01cf9ba6a71320833626af21126384", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "flake-utils_2": { + "inputs": { + "systems": "systems_2" + }, + "locked": { + "lastModified": 1685518550, + "narHash": "sha256-o2d0KcvaXzTrPRIo0kOLV0/QXHhDQ5DTi+OxcjO8xqY=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "a1720a10a6cfe8234c0e93907ffe81be440f4cef", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "gitignore": { + "inputs": { + "nixpkgs": [ + "libsodium-bindings", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1660459072, + "narHash": "sha256-8DFJjXG8zqoONA1vXtgeKXy68KdJL5UaXR8NtVMUbx8=", + "owner": "hercules-ci", + "repo": "gitignore.nix", + "rev": "a20de23b925fd8264fd7fad6454652e142fd7f73", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "gitignore.nix", + "type": "github" + } + }, + "gitignore_2": { + "inputs": { + "nixpkgs": [ + "libsodium-bindings", + "pre-commit-hooks", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1660459072, + "narHash": "sha256-8DFJjXG8zqoONA1vXtgeKXy68KdJL5UaXR8NtVMUbx8=", + "owner": "hercules-ci", + "repo": "gitignore.nix", + "rev": "a20de23b925fd8264fd7fad6454652e142fd7f73", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "gitignore.nix", + "type": "github" + } + }, + "libsodium-bindings": { + "inputs": { + "base16": "base16", + "flake-compat": "flake-compat", + "flake-utils": "flake-utils_2", + "gitignore": "gitignore", + "nixpkgs": "nixpkgs", + "pre-commit-hooks": "pre-commit-hooks" + }, + "locked": { + "lastModified": 1702158167, + "narHash": "sha256-14Q3KGjpHng85u4ORYTxaAf+/z1/63M5j0a6EH91xpE=", + "owner": "haskell-cryptography", + "repo": "libsodium-bindings", + "rev": "0963da7b3669ada9cce2c24cdfd52ba666b35d8d", + "type": "github" + }, + "original": { + "owner": "haskell-cryptography", + "repo": "libsodium-bindings", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1701693815, + "narHash": "sha256-7BkrXykVWfkn6+c1EhFA3ko4MLi3gVG0p9G96PNnKTM=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "09ec6a0881e1a36c29d67497693a67a16f4da573", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs-stable": { + "locked": { + "lastModified": 1678872516, + "narHash": "sha256-/E1YwtMtFAu2KUQKV/1+KFuReYPANM2Rzehk84VxVoc=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "9b8e5abb18324c7fe9f07cb100c3cd4a29cda8b8", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-22.11", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1701718080, + "narHash": "sha256-6ovz0pG76dE0P170pmmZex1wWcQoeiomUZGggfH9XPs=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "2c7f3c0fb7c08a0814627611d9d7d45ab6d75335", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "pre-commit-hooks": { + "inputs": { + "flake-compat": "flake-compat_2", + "flake-utils": [ + "libsodium-bindings", + "flake-utils" + ], + "gitignore": "gitignore_2", + "nixpkgs": [ + "libsodium-bindings", + "nixpkgs" + ], + "nixpkgs-stable": "nixpkgs-stable" + }, + "locked": { + "lastModified": 1685361114, + "narHash": "sha256-4RjrlSb+OO+e1nzTExKW58o3WRwVGpXwj97iCta8aj4=", + "owner": "cachix", + "repo": "pre-commit-hooks.nix", + "rev": "ca2fdbf3edda2a38140184da6381d49f8206eaf4", + "type": "github" + }, + "original": { + "owner": "cachix", + "repo": "pre-commit-hooks.nix", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "libsodium-bindings": "libsodium-bindings", + "nixpkgs": "nixpkgs_2" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, + "systems_2": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..ddbeee3 --- /dev/null +++ b/flake.nix @@ -0,0 +1,54 @@ +{ + description = "one-time-password"; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + flake-utils.url = "github:numtide/flake-utils"; + libsodium-bindings.url = "github:haskell-cryptography/libsodium-bindings"; + }; + + outputs = { self, nixpkgs, flake-utils, ... }@inputs: + flake-utils.lib.eachDefaultSystem (system: + let + pkgs = import nixpkgs{inherit system;}; + + haskellPackages = pkgs.haskellPackages.override { + overrides = hself: hsuper: { + libsodium-bindings = inputs.libsodium-bindings.packages.${system}.libsodium-bindings; + sel = inputs.libsodium-bindings.packages.${system}.sel; + }; + }; + in + rec + { + packages.one-time-password = + haskellPackages.callCabal2nix "one-time-password" ./. + { + base32 = haskellPackages.base32_0_4; + sel = inputs.libsodium-bindings.packages.${system}.sel; + }; + + defaultPackage = packages.one-time-password; + + devShell = + let + scripts = pkgs.symlinkJoin { + name = "scripts"; + paths = pkgs.lib.mapAttrsToList pkgs.writeShellScriptBin { + }; + }; + in + pkgs.mkShell { + buildInputs = with haskellPackages; [ + pkgs.libsodium + haskell-language-server + ghcid + cabal-install + scripts + ]; + inputsFrom = [ + self.defaultPackage.${system}.env + ]; + }; + }); +}