From d268c8c4edbd84212bbfeac7e0642222e6514723 Mon Sep 17 00:00:00 2001 From: saygo-png Date: Fri, 8 Nov 2024 00:11:47 +0100 Subject: [PATCH] dark era dont look Signed-off-by: saygo-png --- .editorconfig | 10 ++++ .envrc | 12 +---- ci/default.nix | 24 ++++++++++ ci/pinned-nixpkgs-for-nixshell.json | 14 ++++++ ci/update-shell-lock.sh | 54 ++++++++++++++++++++++ flake.nix | 72 +++++++++++++++-------------- shell.nix | 32 +++++++++++++ 7 files changed, 173 insertions(+), 45 deletions(-) create mode 100644 .editorconfig create mode 100644 ci/default.nix create mode 100644 ci/pinned-nixpkgs-for-nixshell.json create mode 100755 ci/update-shell-lock.sh create mode 100644 shell.nix diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..a56f2d2 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,10 @@ +# https://editorconfig.org +root = true + +[*] +indent_style = space +indent_size = 2 +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true diff --git a/.envrc b/.envrc index 6760199..a0818f4 100644 --- a/.envrc +++ b/.envrc @@ -1,12 +1,2 @@ # shellcheck disable=SC2148 - -if ! has nix_direnv_version || ! nix_direnv_version 2.2.1; then - source_url "https://raw.githubusercontent.com/nix-community/nix-direnv/2.2.1/direnvrc" "sha256-zelF0vLbEl5uaqrfIzbgNzJWGmLzCmYAkInj/LNxvKs=" -fi - -watch_file flake.nix -watch_file flake.lock - -if ! use flake . --impure; then - echo "devenv could not be built. The devenv environment was not loaded. Make the necessary changes to devenv.nix and hit enter to try again." >&2 -fi +use flake diff --git a/ci/default.nix b/ci/default.nix new file mode 100644 index 0000000..b607572 --- /dev/null +++ b/ci/default.nix @@ -0,0 +1,24 @@ +let + pinnedNixpkgs = builtins.fromJSON (builtins.readFile ./pinned-nixpkgs.json); +in + { + system ? builtins.currentSystem, + nixpkgs ? null, + }: let + nixpkgs' = + if nixpkgs == null + then + fetchTarball { + url = "https://github.com/NixOS/nixpkgs/archive/${pinnedNixpkgs.rev}.tar.gz"; + sha256 = pinnedNixpkgs.sha256; + } + else nixpkgs; + + pkgs = import nixpkgs' { + inherit system; + config = {}; + overlays = []; + }; + in { + inherit pkgs; + } diff --git a/ci/pinned-nixpkgs-for-nixshell.json b/ci/pinned-nixpkgs-for-nixshell.json new file mode 100644 index 0000000..5aa805f --- /dev/null +++ b/ci/pinned-nixpkgs-for-nixshell.json @@ -0,0 +1,14 @@ +{ + "nixpkgs": { + "rev": "9201b5ff357e781bf014d0330d18555695df7ba8", + "sha256": "sha256-x9Opq06rIiwdwGeK2Ykj69dNc2IvUH1fY55Wm7atwrE=" + }, + "nixpkgs-unstable": { + "rev": "4c2fcb090b1f3e5b47eaa7bd33913b574a11e0a0", + "sha256": "sha256-/uilDXvCIEs3C9l73JTACm4quuHUsIHcns1c+cHUJwA=" + }, + "devenv": { + "rev": "c5353d1a0483b8f0dc15933de91c6b1b9a892831", + "sha256": "sha256-ogmpmsPOlX4qeWVW4NZkTd0Lx8V4rvnjwlgOX7WnTZo=" + } +} diff --git a/ci/update-shell-lock.sh b/ci/update-shell-lock.sh new file mode 100755 index 0000000..dc8908c --- /dev/null +++ b/ci/update-shell-lock.sh @@ -0,0 +1,54 @@ +#!/usr/bin/env bash + +# Exit on error, undefined variables, and pipe failures +set -euo pipefail + +INPUT_FILE="../flake.lock" +OUTPUT_FILE="pinned-nixpkgs-for-nixshell.json" + +# Check if input file exists +if [[ ! -f "$INPUT_FILE" ]]; then + echo "Error: Input file '$INPUT_FILE' not found" >&2 + exit 1 +fi + +# Check if input file is readable +if [[ ! -r "$INPUT_FILE" ]]; then + echo "Error: Input file '$INPUT_FILE' is not readable" >&2 + exit 1 +fi + +# Check if output directory is writable +if [[ ! -w "$(dirname "$OUTPUT_FILE")" ]]; then + echo "Error: Directory '$(dirname "$OUTPUT_FILE")' is not writable" >&2 + exit 1 +fi + +# Check if the input file contains valid JSON +if ! jq empty "$INPUT_FILE" 2>/dev/null; then + echo "Error: Input file '$INPUT_FILE' is not valid JSON" >&2 + exit 1 +fi + +# If all checks pass, create the output file +jq ' + . as $root | + ["nixpkgs", "nixpkgs-unstable", "devenv"] as $packages | + reduce $packages[] as $pkg ({}; + . + { + ($pkg): { + rev: $root.nodes[$pkg].locked.rev, + sha256: $root.nodes[$pkg].locked.narHash + } + } + ) +' "$INPUT_FILE" >"$OUTPUT_FILE" + +# Verify the output is valid JSON +if ! jq empty "$OUTPUT_FILE" 2>/dev/null; then + echo "Error: Failed to create valid JSON output" >&2 + rm -f "$OUTPUT_FILE" # Clean up invalid output + exit 1 +fi + +echo "Successfully created $OUTPUT_FILE with pinned package information" diff --git a/flake.nix b/flake.nix index c904f77..761c683 100644 --- a/flake.nix +++ b/flake.nix @@ -93,40 +93,44 @@ }; devShells = inputs.nixpkgs.lib.genAttrs ["x86_64-linux"] (system: { - default = let - pkgs = inputs.nixpkgs.legacyPackages.${system}; - in - inputs.devenv.lib.mkShell { - inherit inputs pkgs; - modules = [ - (_: { - packages = [ - pkgs.cargo - ]; - - languages = { - nix.enable = true; - shell.enable = true; - }; - - pre-commit.hooks = { - commitlint-rs = { - enable = true; - entry = "commitlint --edit"; - language = "rust"; - package = pkgs-unstable.commitlint-rs; - pass_filenames = false; - stages = ["commit-msg"]; - }; - deadnix.enable = true; - shellcheck.enable = true; - shfmt.enable = true; - # statix.enable = true; - alejandra.enable = true; - }; - }) - ]; - }; + default = import ./shell.nix {inherit system;}; + # let + # pkgs = inputs.nixpkgs.legacyPackages.${system}; + # in + # inputs.devenv.lib.mkShell { + # inherit inputs pkgs; + # modules = [ + # (_: { + # # packages = [ + # # pkgs.cargo + # # ]; + # + # languages = { + # nix.enable = true; + # shell.enable = true; + # }; + # + # pre-commit.hooks = { + # commitlint-rs = { + # enable = true; + # entry = "commitlint --edit"; + # language = "rust"; + # package = pkgs-unstable.commitlint-rs; + # pass_filenames = false; + # fail_fast = true; + # stages = ["commit-msg"]; + # extraPackages = [pkgs.cargo]; + # }; + # deadnix.enable = true; + # shellcheck.enable = true; + # # statix.enable = true; + # treefmt.settings.formatters = [ + # pkgs.alejandra + # ]; + # }; + # }) + # ]; + # }; }); }; } diff --git a/shell.nix b/shell.nix new file mode 100644 index 0000000..36b991d --- /dev/null +++ b/shell.nix @@ -0,0 +1,32 @@ +# From nixpkgs shell.nix +# Note: We intentionally don't use Flakes here, +# because every time you change any file and do another `nix develop`, +# it would create another copy of the entire ~500MB tree in the store. +# See https://github.com/NixOS/nix/pull/6530 for the future +{ + system ? builtins.currentSystem, + nixpkgs ? null, +}: let + pinnedNixpkgs = builtins.fromJSON (builtins.readFile ./ci/pinned-nixpkgs-for-nixshell.json); + nixpkgs' = + if nixpkgs == null + then + fetchTarball { + url = "https://github.com/NixOS/nixpkgs/archive/${pinnedNixpkgs.nixpkgs.rev}.tar.gz"; + sha256 = pinnedNixpkgs.nixpkgs.sha256; + } + else nixpkgs; + + pkgs = import nixpkgs' { + inherit system; + config = {}; + overlays = []; + }; +in + pkgs.mkShell { + packages = [ + pkgs.devenv + pkgs.hello + pkgs.pridefetch + ]; + }