diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..3550a30 --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use flake diff --git a/.gitignore b/.gitignore index ea8c4bf..7d2a20b 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,5 @@ /target +result +result-* +*.tmp +.direnv/ diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..93aaeca --- /dev/null +++ b/flake.lock @@ -0,0 +1,164 @@ +{ + "nodes": { + "crate2nix": { + "flake": false, + "locked": { + "lastModified": 1681086579, + "narHash": "sha256-MEcdG7EXkFsmrTo1/X5tq7UDFY6enHdl65k0wbTCuD0=", + "owner": "kolloch", + "repo": "crate2nix", + "rev": "1b042dab3928aaa37421a83d4e1023e7a79527e2", + "type": "github" + }, + "original": { + "owner": "kolloch", + "repo": "crate2nix", + "type": "github" + } + }, + "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-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1681202837, + "narHash": "sha256-H+Rh19JDwRtpVPAWp64F+rlEtxUWBAQW28eAi3SRSzg=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "cfacdce06f30d2b68473a46042957675eebb3401", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1687898314, + "narHash": "sha256-B4BHon3uMXQw8ZdbwxRK1BmxVOGBV4viipKpGaIlGwk=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "e18dc963075ed115afb3e312b64643bf8fd4b474", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1681358109, + "narHash": "sha256-eKyxW4OohHQx9Urxi7TQlFBTDWII+F+x2hklDOQPB50=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "96ba1c52e54e74c3197f4d43026b3f3d92e83ff9", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "crate2nix": "crate2nix", + "flake-compat": "flake-compat", + "nixpkgs": "nixpkgs", + "rust-overlay": "rust-overlay", + "utils": "utils" + } + }, + "rust-overlay": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs_2" + }, + "locked": { + "lastModified": 1688092301, + "narHash": "sha256-NTgT955DzXWVjHsuBn1t2K0x4hUghY7uE1jG2nGL5R4=", + "owner": "oxalica", + "repo": "rust-overlay", + "rev": "4c31223801dd0f28ac15d60f2e5ddbd4d51ce17a", + "type": "github" + }, + "original": { + "owner": "oxalica", + "repo": "rust-overlay", + "type": "github" + } + }, + "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" + } + }, + "utils": { + "inputs": { + "systems": "systems_2" + }, + "locked": { + "lastModified": 1687709756, + "narHash": "sha256-Y5wKlQSkgEK2weWdOu4J3riRd+kV/VCgHsqLNTTWQ/0=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "dbabf0ca0c0c4bce6ea5eaf65af5cb694d2082c7", + "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..bb8a244 --- /dev/null +++ b/flake.nix @@ -0,0 +1,88 @@ +{ + description = "trivia on the command line"; + + inputs = { + nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; + utils.url = "github:numtide/flake-utils"; + rust-overlay.url = "github:oxalica/rust-overlay"; + crate2nix = { + url = "github:kolloch/crate2nix"; + flake = false; + }; + flake-compat = { + url = "github:edolstra/flake-compat"; + flake = false; + }; + }; + + outputs = { self, nixpkgs, utils, rust-overlay, crate2nix, ... }: + let + name = "oi"; + in + utils.lib.eachDefaultSystem + (system: + let + # Imports + pkgs = import nixpkgs { + inherit system; + overlays = [ + rust-overlay.overlays.default + (self: super: { + # Because rust-overlay bundles multiple rust packages into one + # derivation, specify that mega-bundle here, so that crate2nix + # will use them automatically. + rustc = self.rust-bin.stable.latest.default; + cargo = self.rust-bin.stable.latest.default; + }) + ]; + }; + inherit (import "${crate2nix}/tools.nix" { inherit pkgs; }) + generatedCargoNix; + + # Create the cargo2nix project + project = pkgs.callPackage + (generatedCargoNix { + inherit name; + src = ./.; + }) + { + # Individual crate overrides go here + # Example: https://github.com/balsoft/simple-osd-daemons/blob/6f85144934c0c1382c7a4d3a2bbb80106776e270/flake.nix#L28-L50 + defaultCrateOverrides = pkgs.defaultCrateOverrides // { + # The app crate itself is overriden here. Typically we + # configure non-Rust dependencies (see below) here. + ${name} = oldAttrs: { + inherit buildInputs nativeBuildInputs; + } // buildEnvVars; + }; + }; + + # Configuration for the non-Rust dependencies + buildInputs = with pkgs; [ openssl.dev ]; + nativeBuildInputs = with pkgs; [ rustc cargo pkgconfig nixpkgs-fmt ]; + buildEnvVars = { + PKG_CONFIG_PATH = "${pkgs.openssl.dev}/lib/pkgconfig"; + }; + in + rec { + packages.${name} = project.rootCrate.build; + + # `nix build` + defaultPackage = packages.${name}; + + # `nix run` + apps.${name} = utils.lib.mkApp { + inherit name; + drv = packages.${name}; + }; + defaultApp = apps.${name}; + + # `nix develop` + devShell = pkgs.mkShell + { + inherit buildInputs nativeBuildInputs; + RUST_SRC_PATH = "${pkgs.rust.packages.stable.rustPlatform.rustLibSrc}"; + } // buildEnvVars; + } + ); +}