X-Git-Url: https://gitweb.ps.run/chirp/blobdiff_plain/4eda259f142c2ba004e9182ec196f50999e562aa..e72f3f9d2c8a06cab6a5fd6ae773057effcef8b2:/flake.nix diff --git a/flake.nix b/flake.nix index fd691a8..29c9ade 100644 --- a/flake.nix +++ b/flake.nix @@ -1,56 +1,65 @@ { - description = "Chirp!"; - - inputs = { - zig.url = "github:mitchellh/zig-overlay"; - }; - - outputs = { - self, - zig, - pkgs, - }: let - nixosModule = { - config, - lib, - pkgs, - ... - }: { - options.services.chirp = { - enable = lib.mkEnableOption "Chirp"; - - port = lib.mkOption { - type = lib.types.port; - default = 8080; - description = "Port to listen on"; + description = "Chirp Flake"; + + inputs.self.submodules = true; + inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + inputs.flake-utils.url = "github:numtide/flake-utils"; + + outputs = { self, nixpkgs, flake-utils }: + flake-utils.lib.eachDefaultSystem (system: + let + pkgs = import nixpkgs { inherit system; }; + in { + packages.default = pkgs.stdenv.mkDerivation { + pname = "chirp"; + version = "0.0.0"; + src = ./.; + + buildPhase = '' + mkdir -p .zig-cache-global/zig + ${pkgs.zig}/bin/zig build --verbose --global-cache-dir .zig-cache-global + ''; + + installPhase = '' + mkdir -p $out/bin $out/db + cp zig-out/bin/chirp $out/bin + ''; }; - }; - config = lib.mkIf config.services.chirp.enable { - systemd.services.chirp = { - description = "Chirp SystemD Service!"; - wantedBy = ["multi-user.target"]; - after = ["network.target"]; - serviceConfig = { - ExecStart = "${zig.packages.master}"; - Restart = "always"; - Type = "simple"; - DynamicUser = "yes"; + apps.default = { + type = "app"; + program = "${self.packages.${system}.default}/bin/chirp"; + }; + }) + // { + nixosModules.default = { config, lib, pkgs, ... }: { + options.services.chirp = { + enable = lib.mkEnableOption "Enable Chirp"; + + port = lib.mkOption { + type = lib.types.port; + default = 8080; + description = "Port to listen on"; + }; }; - environment = { - PORT = toString config.services.chirp.port; + + config = lib.mkIf config.services.chirp.enable { + systemd.services.chirp = { + description = "Chirp SystemD Service"; + wantedBy = ["multi-user.target"]; + after = ["network.target"]; + serviceConfig = { + ExecStart = "${self.packages.${pkgs.system}.default}/bin/chirp"; + Restart = "always"; + Type = "simple"; + DynamicUser = "yes"; + }; + environment = { + PORT = toString config.services.chirp.port; + }; + }; }; }; }; - }; - in { - # TODO: packages.default build - apps.default = { - type = "app"; - program = "${zig.packages.${pkgs.system}."0.14.0"} build run"; - }; - } - // { - nixosModules.default = nixosModule; - }; } +