From c31d638dc023479d792171159ffd8999f839ed10 Mon Sep 17 00:00:00 2001 From: Greg Hellings Date: Tue, 15 Oct 2024 19:57:26 -0500 Subject: [PATCH] Base scaffold --- .gitignore | 1 + .gitlab-ci.yml | 8 +++ flake.lock | 97 ++++++++++++++++++++++++++- flake.nix | 175 ++++++++++++++++++++++++++++--------------------- src/lib.rs | 17 +++-- 5 files changed, 213 insertions(+), 85 deletions(-) create mode 100644 .gitlab-ci.yml diff --git a/.gitignore b/.gitignore index 2d5df85..9624092 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ /target .direnv +result diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000..006862e --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,8 @@ +phases: + - check + +check: + tags: + - nix + script: + - nix flake check diff --git a/flake.lock b/flake.lock index 41c7650..5a74e0e 100644 --- a/flake.lock +++ b/flake.lock @@ -18,6 +18,22 @@ "type": "github" } }, + "flake-compat": { + "flake": false, + "locked": { + "lastModified": 1696426674, + "narHash": "sha256-kvjfFW7WAETZlt09AgDn1MrtKzP7t90Vf7vypd3OL1U=", + "owner": "edolstra", + "repo": "flake-compat", + "rev": "0f9255e01c2351cc7d116c072cb317785dd33b33", + "type": "github" + }, + "original": { + "owner": "edolstra", + "repo": "flake-compat", + "type": "github" + } + }, "flake-parts": { "inputs": { "nixpkgs-lib": "nixpkgs-lib" @@ -51,9 +67,51 @@ "type": "github" } }, + "gitignore": { + "inputs": { + "nixpkgs": [ + "hooks", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1709087332, + "narHash": "sha256-HG2cCnktfHsKV0s4XW83gU3F57gaTljL9KNSuG6bnQs=", + "owner": "hercules-ci", + "repo": "gitignore.nix", + "rev": "637db329424fd7e46cf4185293b9cc8c88c95394", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "gitignore.nix", + "type": "github" + } + }, + "hooks": { + "inputs": { + "flake-compat": "flake-compat", + "gitignore": "gitignore", + "nixpkgs": "nixpkgs_2", + "nixpkgs-stable": "nixpkgs-stable" + }, + "locked": { + "lastModified": 1728778939, + "narHash": "sha256-WybK5E3hpGxtCYtBwpRj1E9JoiVxe+8kX83snTNaFHE=", + "owner": "cachix", + "repo": "git-hooks.nix", + "rev": "ff68f91754be6f3427e4986d7949e6273659be1d", + "type": "github" + }, + "original": { + "owner": "cachix", + "repo": "git-hooks.nix", + "type": "github" + } + }, "naersk": { "inputs": { - "nixpkgs": "nixpkgs_2" + "nixpkgs": "nixpkgs_3" }, "locked": { "lastModified": 1721727458, @@ -97,7 +155,39 @@ "url": "https://github.com/NixOS/nixpkgs/archive/fb192fec7cc7a4c26d51779e9bab07ce6fa5597a.tar.gz" } }, + "nixpkgs-stable": { + "locked": { + "lastModified": 1720386169, + "narHash": "sha256-NGKVY4PjzwAa4upkGtAMz1npHGoRzWotlSnVlqI40mo=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "194846768975b7ad2c4988bdb82572c00222c0d7", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-24.05", + "repo": "nixpkgs", + "type": "github" + } + }, "nixpkgs_2": { + "locked": { + "lastModified": 1719082008, + "narHash": "sha256-jHJSUH619zBQ6WdC21fFAlDxHErKVDJ5fpN0Hgx4sjs=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "9693852a2070b398ee123a329e68f0dab5526681", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_3": { "locked": { "lastModified": 0, "narHash": "sha256-HP89HZOT0ReIbI7IJZJQoJgxvB2Tn28V6XS3MNKnfLs=", @@ -109,7 +199,7 @@ "type": "indirect" } }, - "nixpkgs_3": { + "nixpkgs_4": { "locked": { "lastModified": 1728538411, "narHash": "sha256-f0SBJz1eZ2yOuKUr5CA9BHULGXVSn6miBuUWdTyhUhU=", @@ -130,8 +220,9 @@ "devshell": "devshell", "flake-parts": "flake-parts", "flake-root": "flake-root", + "hooks": "hooks", "naersk": "naersk", - "nixpkgs": "nixpkgs_3" + "nixpkgs": "nixpkgs_4" } } }, diff --git a/flake.nix b/flake.nix index 13b9c9b..d25d108 100644 --- a/flake.nix +++ b/flake.nix @@ -1,78 +1,107 @@ # github.com/brianmcgee has lots of great ideas for going above and beyond for this { - description = "Greg's homepage"; - inputs = { - nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; - devshell.url = "github:numtide/devshell"; - flake-parts.url = "github:hercules-ci/flake-parts"; - flake-root.url = "github:srid/flake-root"; - naersk.url = "github:nix-community/naersk"; - #process-compose.url = "github:Platonic-Systems/process-compose-flake"; - #services-flake.url = "github:juspay/services-flake"; - }; + description = "Greg's homepage"; + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; + devshell.url = "github:numtide/devshell"; + flake-parts.url = "github:hercules-ci/flake-parts"; + flake-root.url = "github:srid/flake-root"; + hooks.url = "github:cachix/git-hooks.nix"; + naersk.url = "github:nix-community/naersk"; + }; - outputs = { flake-parts, ... }@inputs: - flake-parts.lib.mkFlake { inherit inputs; } { - imports = [ - inputs.devshell.flakeModule - inputs.flake-root.flakeModule - #inputs.process-compose.flakeModule - ]; - flake = { - # Universal things - overlays.default = final: prev: {}; - }; - systems = [ - "x86_64-linux" - "aarch64-linux" - "aarch64-darwin" - ]; - perSystem = { pkgs, ... }@inputs': let - naersk-lib = pkgs.callPackage inputs.naersk { }; - in { - _module.args.pkgs = import inputs.nixpkgs { - inherit (inputs') system; - overlays = []; - }; - # https://numtide.github.io/devshell/intro.html - devshells.default = { - env = [{ - name = "RUST_SRC_PATH"; - value = pkgs.rustPlatform.rustLibSrc; - }]; - # These commands will be shown in the motd that users read - # upon entering the shell - commands = [{ - package = pkgs.cargo; - category = "languages"; - help = "The Cargo tool"; - } { - package = pkgs.rustc; - category = "languages"; - help = "The rust compiler"; - } { - package = pkgs.rustfmt; - category = "tools"; - help = "Formatting tool for Rust"; - } { - package = pkgs.pre-commit; - category = "tools"; - help = "Helps run certain checks"; - } { - package = pkgs.rustPackages.clippy; - category = "tools"; - help = "Standard Rust clippy tool"; - } { - package = pkgs.stdenv.cc; - category = "languages"; - help = "The C compiler, to help things out"; - }]; - }; + outputs = + { flake-parts, ... }@inputs: + flake-parts.lib.mkFlake { inherit inputs; } { + imports = [ + inputs.devshell.flakeModule + inputs.flake-root.flakeModule + #inputs.process-compose.flakeModule + ]; + flake = { + # Universal things + # final: prev: + overlays.default = _: _: { }; + }; + systems = [ + "x86_64-linux" + "aarch64-linux" + "aarch64-darwin" + ]; + perSystem = + { pkgs, ... }@inputs': + let + naersk-lib = pkgs.callPackage inputs.naersk { }; + in + { + _module.args.pkgs = import inputs.nixpkgs { + inherit (inputs') system; + overlays = [ ]; + }; + # https://numtide.github.io/devshell/intro.html + devshells.default = { + # These commands will be shown in the motd that users read + # upon entering the shell + commands = [ + { + package = pkgs.cargo; + category = "tools"; + help = "Rust build and package tool"; + } + { + package = pkgs.rustc; + category = "languages"; + help = "Rust compiler"; + } + { + package = pkgs.rustfmt; + category = "tools"; + help = "Standard Rust formatting tool"; + } + { + package = pkgs.clippy; + category = "tools"; + help = "Rust linter"; + } + { + package = pkgs.stdenv.cc; + category = "languages"; + help = "C compiler to help with building native code"; + } + { + package = pkgs.pre-commit; + category = "tools"; + help = "Tool to help enforce commits make sense"; + } + ]; + }; - # This is not special, this is just flakes - packages = { - default = naersk-lib.buildPackage ./.; - }; - }; - }; + checks = { + pre-commit-check = inputs.hooks.lib.${inputs'.system}.run { + src = ./.; + hooks = { + check-added-large-files.enable = true; + check-case-conflicts.enable = true; + check-merge-conflicts.enable = true; + check-symlinks.enable = true; + deadnix.enable = true; + end-of-file-fixer.enable = true; + fix-byte-order-marker.enable = true; + mixed-line-endings.enable = true; + nixfmt-rfc-style.enable = true; + trim-trailing-whitespace.enable = true; + # Rust hooks + cargo-check.enable = true; + clippy.enable = true; + rustfmt.enable = true; + }; + }; + }; + + # This is not special, this is just flakes + packages = { + rustpkg = naersk-lib.buildPackage ./.; + }; + }; + }; } diff --git a/src/lib.rs b/src/lib.rs index f53c119..c8b86da 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,4 +1,4 @@ -#[derive(Clone,Debug,Copy)] +#[derive(Clone, Debug, Copy)] pub enum CellValue { One, Two, @@ -8,20 +8,19 @@ pub enum CellValue { Six, Seven, Eight, - Nine + Nine, } pub struct Cell { value: Option, candidates: Vec, - } impl Default for Cell { fn default() -> Cell { Cell { - value : None, - candidates : vec![ + value: None, + candidates: vec![ CellValue::One, CellValue::Two, CellValue::Three, @@ -30,19 +29,19 @@ impl Default for Cell { CellValue::Six, CellValue::Seven, CellValue::Eight, - CellValue::Nine - ] + CellValue::Nine, + ], } } } #[derive(Default)] pub struct Board { - cells: [ [ Cell ; 9 ] ; 9 ] + cells: [[Cell; 9]; 9], } impl Board { - fn value(self, x: usize, y : usize) -> Option { + fn value(self, x: usize, y: usize) -> Option { self.cells[x][y].value } }