From 087e76388d3c7a6052531dd8b514e6f621f55c7c Mon Sep 17 00:00:00 2001 From: notohh Date: Mon, 8 Apr 2024 11:11:05 -0400 Subject: [PATCH] nix: init rewrite first pass of my nix rewrite nix: rename module nix: update module nix: update module nix: update module nix: refactor nix: remove package option nix: fix serviceConfig nix: add package back to module nix: update module nix: update module nix: update module nix: update module remove default.nix --- .gitignore | 5 +++- flake.lock | 30 +++++++++++++++----- flake.nix | 77 ++++++++++++++++++++++++++++++++------------------ nix/module.nix | 30 ++++++++++++++++++++ 4 files changed, 107 insertions(+), 35 deletions(-) create mode 100644 nix/module.nix diff --git a/.gitignore b/.gitignore index 5c5e6b4..51b0be2 100644 --- a/.gitignore +++ b/.gitignore @@ -22,4 +22,7 @@ target/ *.log # debug -.vscode/ \ No newline at end of file +.vscode/ + +# nix +result/ \ No newline at end of file diff --git a/flake.lock b/flake.lock index 84f1b48..f66c5b5 100644 --- a/flake.lock +++ b/flake.lock @@ -38,16 +38,16 @@ }, "nixpkgs_2": { "locked": { - "lastModified": 1712439257, - "narHash": "sha256-aSpiNepFOMk9932HOax0XwNxbA38GOUVOiXfUVPOrck=", - "owner": "nixos", + "lastModified": 1712543224, + "narHash": "sha256-9RSfZL1TKYdGxZwgDxwtBtsKMGR4Zgn+DAnF9s71/lU=", + "owner": "NixOS", "repo": "nixpkgs", - "rev": "ff0dbd94265ac470dda06a657d5fe49de93b4599", + "rev": "b0dab7cc34ef4d8a1b2de36178da801090bcb271", "type": "github" }, "original": { - "owner": "nixos", - "ref": "nixos-unstable", + "owner": "NixOS", + "ref": "nixpkgs-unstable", "repo": "nixpkgs", "type": "github" } @@ -55,7 +55,8 @@ "root": { "inputs": { "fenix": "fenix", - "nixpkgs": "nixpkgs_2" + "nixpkgs": "nixpkgs_2", + "systems": "systems" } }, "rust-analyzer-src": { @@ -74,6 +75,21 @@ "repo": "rust-analyzer", "type": "github" } + }, + "systems": { + "locked": { + "lastModified": 1689347949, + "narHash": "sha256-12tWmuL2zgBgZkdoB6qXZsgJEH9LR3oUgpaQq2RbI80=", + "owner": "nix-systems", + "repo": "default-linux", + "rev": "31732fcf5e8fea42e59c2488ad31a0e651500f68", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default-linux", + "type": "github" + } } }, "root": "root", diff --git a/flake.nix b/flake.nix index c6be631..f29c01a 100644 --- a/flake.nix +++ b/flake.nix @@ -1,39 +1,62 @@ { - description = "forcebot_rs flake"; + description = "A basic flake"; inputs = { - nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; + systems.url = "github:nix-systems/default-linux"; + nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; fenix.url = "github:nix-community/fenix/monthly"; }; + outputs = { + self, + systems, nixpkgs, fenix, - ... } @ inputs: let - system = "x86_64-linux"; - overlays = [fenix.overlays.default]; - pkgs = import nixpkgs { - inherit system overlays; - }; + eachSystem = nixpkgs.lib.genAttrs (import systems); + pkgsFor = eachSystem (system: + import nixpkgs { + localSystem.system = system; + overlays = [fenix.overlays.default]; + }); in { - devShells.${system}.default = pkgs.mkShell { - name = "forcebot_rs-devenv"; - nativeBuildInputs = [pkgs.pkg-config]; - buildInputs = with pkgs; [openssl libiconv]; - packages = with pkgs; [ - nil - alejandra - rust-analyzer-nightly - (fenix.packages.${system}.complete.withComponents [ - "cargo" - "clippy" - "rust-src" - "rustc" - "rustfmt" - ]) - ]; - RUST_BACKTRACE = 1; - RUST_SRC_PATH = "${fenix.packages.${system}.complete.rust-src}/lib/rustlib/src/rust/library"; - }; + packages = eachSystem (system: let + pkgs = nixpkgs.legacyPackages.${system}; + in { + default = pkgsFor.${system}.rustPlatform.buildRustPackage { + pname = "forcebot_rs"; + version = "v0.1"; + + src = self; + + cargoLock = { + lockFile = ./Cargo.lock; + }; + + nativeBuildInputs = with pkgs; [pkg-config]; + buildInputs = with pkgs; [openssl]; + + doCheck = false; + }; + }); + devShells = eachSystem (system: { + default = pkgsFor.${system}.mkShell { + packages = with pkgsFor.${system}; [ + nil + alejandra + rust-analyzer-nightly + (fenix.packages.${system}.complete.withComponents [ + "cargo" + "clippy" + "rust-src" + "rustc" + "rustfmt" + ]) + ]; + RUST_BACKTRACE = 1; + RUST_SRC_PATH = "${fenix.packages.${system}.complete.rust-src}/lib/rustlib/src/rust/library"; + }; + }); + nixosModules.default = import ./nix/module.nix {inherit self;}; }; } diff --git a/nix/module.nix b/nix/module.nix new file mode 100644 index 0000000..b615be1 --- /dev/null +++ b/nix/module.nix @@ -0,0 +1,30 @@ +{self}: { + pkgs, + config, + lib, + ... +}: let + inherit (lib) types; + inherit (lib.modules) mkIf; + inherit (lib.options) mkOption mkEnableOption; + inherit (pkgs.stdenv.hostPlatform) system; + cfg = config.services.forcebot_rs; +in { + options.services.forcebot_rs = { + enable = mkEnableOption '' + Enable forcebot + ''; + + package = mkOption { + type = types.package; + default = self.packages.${system}.default; + }; + }; + + config = mkIf cfg.enable { + systemd.services.forcebot_rs = { + wantedBy = ["multi-user.target"]; + serviceConfig.ExecStart = "${cfg.package}/bin/forcebot_rs"; + }; + }; +}