From 9b0a3914822e8518ae4d5d4e3c6e935be9af956e Mon Sep 17 00:00:00 2001 From: Xe Date: Sat, 19 Feb 2022 14:10:17 -0500 Subject: [PATCH] use flakes Signed-off-by: Xe --- .envrc | 2 +- .github/workflows/build_nix.yml | 13 ++++++ .gitignore | 1 + default.nix | 7 +++ flake.lock | 77 +++++++++++++++++++++++++++++++++ flake.nix | 48 ++++++++++++++++++++ shell.nix | 33 +++----------- src/main.rs | 3 +- 8 files changed, 156 insertions(+), 28 deletions(-) create mode 100644 .github/workflows/build_nix.yml create mode 100644 default.nix create mode 100644 flake.lock create mode 100644 flake.nix diff --git a/.envrc b/.envrc index 051d09d..3550a30 100644 --- a/.envrc +++ b/.envrc @@ -1 +1 @@ -eval "$(lorri direnv)" +use flake diff --git a/.github/workflows/build_nix.yml b/.github/workflows/build_nix.yml new file mode 100644 index 0000000..2f684e1 --- /dev/null +++ b/.github/workflows/build_nix.yml @@ -0,0 +1,13 @@ +name: "Build legacy Nix package on Ubuntu" + +on: + push: + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: cachix/install-nix-action@v12 + - name: Building package + run: nix-build . -A defaultPackage.x86_64-linux diff --git a/.gitignore b/.gitignore index 9e45dd3..579536f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ .#* +.direnv /target config.yaml var/* diff --git a/default.nix b/default.nix new file mode 100644 index 0000000..39bacff --- /dev/null +++ b/default.nix @@ -0,0 +1,7 @@ +(import ( + fetchTarball { + url = "https://github.com/edolstra/flake-compat/archive/99f1c2157fba4bfe6211a321fd0ee43199025dbf.tar.gz"; + sha256 = "0x2jn3vrawwv9xp15674wjz9pixwjyj3j771izayl962zziivbx2"; } +) { + src = ./.; +}).defaultNix diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..8c09f0d --- /dev/null +++ b/flake.lock @@ -0,0 +1,77 @@ +{ + "nodes": { + "naersk": { + "inputs": { + "nixpkgs": "nixpkgs" + }, + "locked": { + "lastModified": 1639947939, + "narHash": "sha256-pGsM8haJadVP80GFq4xhnSpNitYNQpaXk4cnA796Cso=", + "owner": "nmattia", + "repo": "naersk", + "rev": "2fc8ce9d3c025d59fee349c1f80be9785049d653", + "type": "github" + }, + "original": { + "owner": "nmattia", + "ref": "master", + "repo": "naersk", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1645013224, + "narHash": "sha256-b7OEC8vwzJv3rsz9pwnTX2LQDkeOWz2DbKypkVvNHXc=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "b66b39216b1fef2d8c33cc7a5c72d8da80b79970", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "type": "indirect" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1645013224, + "narHash": "sha256-b7OEC8vwzJv3rsz9pwnTX2LQDkeOWz2DbKypkVvNHXc=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "b66b39216b1fef2d8c33cc7a5c72d8da80b79970", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "naersk": "naersk", + "nixpkgs": "nixpkgs_2", + "utils": "utils" + } + }, + "utils": { + "locked": { + "lastModified": 1644229661, + "narHash": "sha256-1YdnJAsNy69bpcjuoKdOYQX0YxZBiCYZo4Twxerqv7k=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "3cecb5b042f7f209c56ffd8371b2711a290ec797", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..95563c8 --- /dev/null +++ b/flake.nix @@ -0,0 +1,48 @@ +{ + + inputs = { + naersk.url = "github:nmattia/naersk/master"; + nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; + utils.url = "github:numtide/flake-utils"; + }; + + outputs = { self, nixpkgs, utils, naersk }: + utils.lib.eachDefaultSystem (system: + let + pkgs = import nixpkgs { inherit system; }; + naersk-lib = pkgs.callPackage naersk { }; + in { + + defaultPackage = naersk-lib.buildPackage ./.; + + defaultApp = utils.lib.mkApp { drv = self.defaultPackage."${system}"; }; + + devShell = with pkgs; + mkShell { + buildInputs = [ + # rust + cargo + cargo-watch + rustc + rust-analyzer + rustfmt + rustPackages.clippy + + # system + pkg-config + openssl + cmake + + # dhall + dhall + dhall-json + + jo + ]; + RUST_LOG = "info"; + RUST_SRC_PATH = rustPlatform.rustLibSrc; + }; + + }); + +} diff --git a/shell.nix b/shell.nix index 3a3dbf9..77db547 100644 --- a/shell.nix +++ b/shell.nix @@ -1,26 +1,7 @@ -{ pkgs ? import { } }: - -pkgs.mkShell { - buildInputs = with pkgs; [ - # rust - cargo - cargo-watch - rustc - rust-analyzer - rustfmt - - # system - pkg-config - openssl - cmake - - # dhall - dhall - dhall-json - - jo - ]; - - RUST_LOG = "info"; - RUST_SRC_PATH = "${pkgs.rustPlatform.rustLibSrc}"; -} +(import ( + fetchTarball { + url = "https://github.com/edolstra/flake-compat/archive/99f1c2157fba4bfe6211a321fd0ee43199025dbf.tar.gz"; + sha256 = "0x2jn3vrawwv9xp15674wjz9pixwjyj3j771izayl962zziivbx2"; } +) { + src = ./.; +}).shellNix diff --git a/src/main.rs b/src/main.rs index 14750d8..ec3bc90 100644 --- a/src/main.rs +++ b/src/main.rs @@ -31,7 +31,8 @@ async fn main() -> Result<()> { tracing_subscriber::fmt::init(); color_eyre::install()?; - let cfg: Config = serde_yaml::from_str(&std::fs::read_to_string("config.yaml")?)?; + let mut cfg: Config = serde_yaml::from_str(&std::fs::read_to_string("config.yaml")?)?; + cfg.irc.version = Some(APPLICATION_NAME.to_string()); let db = Arc::new(Mutex::new({ let db = Connection::open(cfg.database_path.clone())?;