-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #160 from pope/main
Use a Nix Flake for m8c
- Loading branch information
Showing
6 changed files
with
220 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
name: Update Version and Hash in default.nix | ||
name: Update Version and Hash in flake.nix | ||
|
||
on: | ||
push: | ||
|
@@ -42,15 +42,15 @@ jobs: | |
echo "valid=false" >> $GITHUB_OUTPUT | ||
fi | ||
- name: Update version in default.nix | ||
- name: Update version in flake.nix | ||
if: steps.valid-tag.outputs.valid | ||
run: | | ||
latest_annotated_tag="${{ steps.newest-tag.outputs.latest_annotated_tag }}" | ||
latest_annotated_tag_without_v="${latest_annotated_tag#v}" # Remove 'v' prefix | ||
sed -i "s/version = \".*\";/version = \"$latest_annotated_tag_without_v\";/" default.nix | ||
sed -i "s/version = \".*\";/version = \"$latest_annotated_tag_without_v\";/" flake.nix | ||
new_hash=$(nix-prefetch-url --unpack --type sha256 "https://github.com/laamaa/m8c/archive/v$latest_annotated_tag_without_v.tar.gz") # Use updated variable name | ||
sed -i "s/hash = \".*\";/hash = \"sha256:$new_hash\";/" default.nix | ||
sed -i "s/hash = \".*\";/hash = \"sha256:$new_hash\";/" flake.nix | ||
git config user.email "[email protected]" | ||
git config user.name "GitHub Actions" | ||
git commit -am "Update version and hash in default.nix to $latest_annotated_tag_without_v" | ||
git commit -am "Update version and hash in flake.nix to $latest_annotated_tag_without_v" | ||
git push origin HEAD:main |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,18 @@ | ||
{ pkgs ? import <nixpkgs> {} }: | ||
|
||
with pkgs; | ||
|
||
# HOWTO keep this package definition up-to-date: | ||
# | ||
# 1. NEW VERSION: | ||
# After the new version is tagged and pushed, update the `version` var to the | ||
# proper value and update the hash. You can use the following command to find | ||
# out the sha256, for example, with version 1.0.3: | ||
# `nix-prefetch-github --rev v1.0.3 laamaa m8c` | ||
# | ||
# 2. NEW DEPENDENCIES: | ||
# Make sure new dependencies are added. Runtime deps go to buildInputs and | ||
# compile-time deps go to nativeBuildInputs. Use the nixpkgs manual for help | ||
# | ||
let m8c-package = | ||
{ stdenv | ||
, gnumake | ||
, pkg-config | ||
, SDL2 | ||
, libserialport | ||
, fetchFromGitHub | ||
}: | ||
|
||
let | ||
pname = "m8c"; | ||
version = "1.7.6"; | ||
in | ||
stdenv.mkDerivation { | ||
inherit pname version; | ||
|
||
src = fetchFromGitHub { | ||
owner = "laamaa"; | ||
repo = pname; | ||
rev = "v${version}"; | ||
hash = "sha256:1b2wg8zmxisn1kc3wkfzcij1707pz560yq8v6rwjirr0dd27a3n2"; | ||
}; | ||
|
||
installFlags = [ "PREFIX=$(out)" ]; | ||
nativeBuildInputs = [ gnumake pkg-config ]; | ||
buildInputs = [ SDL2 libserialport ]; | ||
}; | ||
in { | ||
m8c-stable = pkgs.callPackage m8c-package {}; | ||
m8c-dev = (pkgs.callPackage m8c-package {}).overrideAttrs (oldAttrs: {src = ./.;}); | ||
let | ||
pkgs = (import | ||
( | ||
let | ||
lock = builtins.fromJSON (builtins.readFile ./flake.lock); | ||
in | ||
fetchTarball { | ||
url = "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz"; | ||
sha256 = lock.nodes.flake-compat.locked.narHash; | ||
} | ||
) | ||
{ | ||
src = ./.; | ||
}).defaultNix.packages.${builtins.currentSystem}; | ||
in | ||
{ | ||
inherit (pkgs) m8c-stable m8c-dev; | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
{ | ||
inputs = { | ||
nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.05"; | ||
systems.url = "github:nix-systems/default"; | ||
treefmt-nix = { | ||
url = "github:numtide/treefmt-nix"; | ||
inputs.nixpkgs.follows = "nixpkgs"; | ||
}; | ||
flake-compat = { | ||
url = "github:edolstra/flake-compat"; | ||
flake = false; | ||
}; | ||
}; | ||
|
||
outputs = { self, nixpkgs, systems, treefmt-nix, ... }: | ||
let | ||
# HOWTO keep this package definition up-to-date: | ||
# | ||
# 1. NEW VERSION: | ||
# After the new version is tagged and pushed, update the `version` var to the | ||
# proper value and update the hash. You can use the following command to find | ||
# out the sha256, for example, with version 1.0.3: | ||
# `nix-prefetch-github --rev v1.0.3 laamaa m8c` | ||
# | ||
# 2. NEW DEPENDENCIES: | ||
# Make sure new dependencies are added. Runtime deps go to buildInputs and | ||
# compile-time deps go to nativeBuildInputs. Use the nixpkgs manual for help | ||
pname = "m8c"; | ||
version = "1.7.6"; | ||
m8c-package = | ||
{ stdenv | ||
, gnumake | ||
, pkg-config | ||
, SDL2 | ||
, libserialport | ||
, fetchFromGitHub | ||
}: | ||
stdenv.mkDerivation { | ||
inherit pname version; | ||
|
||
src = fetchFromGitHub { | ||
owner = "laamaa"; | ||
repo = pname; | ||
rev = "v${version}"; | ||
hash = "sha256:1b2wg8zmxisn1kc3wkfzcij1707pz560yq8v6rwjirr0dd27a3n2"; | ||
}; | ||
|
||
installFlags = [ "PREFIX=$(out)" ]; | ||
nativeBuildInputs = [ gnumake pkg-config ]; | ||
buildInputs = [ SDL2 libserialport ]; | ||
}; | ||
eachSystem = f: nixpkgs.lib.genAttrs (import systems) (system: f | ||
(import nixpkgs { inherit system; }) | ||
); | ||
treefmtEval = eachSystem (pkgs: treefmt-nix.lib.evalModule pkgs (_: { | ||
projectRootFile = "flake.nix"; | ||
programs = { | ||
clang-format.enable = false; # TODO(pope): Enable and format C code | ||
deadnix.enable = true; | ||
nixpkgs-fmt.enable = true; | ||
statix.enable = true; | ||
}; | ||
})); | ||
in | ||
{ | ||
packages = eachSystem (pkgs: rec { | ||
m8c-stable = pkgs.callPackage m8c-package { }; | ||
m8c-dev = (pkgs.callPackage m8c-package { }).overrideAttrs (_oldAttrs: { | ||
src = ./.; | ||
}); | ||
default = m8c-stable; | ||
}); | ||
|
||
overlays.default = final: _prev: { | ||
inherit (self.packages.${final.system}) m8c-stable m8c-dev; | ||
}; | ||
|
||
apps = eachSystem (pkgs: rec { | ||
m8c = { | ||
type = "app"; | ||
program = "${self.packages.${pkgs.system}.m8c-stable}/bin/m8c"; | ||
}; | ||
default = m8c; | ||
}); | ||
|
||
devShells = eachSystem (pkgs: with pkgs; { | ||
default = mkShell { | ||
packages = [ | ||
nix-prefetch-github | ||
treefmtEval.${system}.config.build.wrapper | ||
]; | ||
inputsFrom = [ self.packages.${system}.m8c-dev ]; | ||
}; | ||
}); | ||
|
||
formatter = eachSystem (pkgs: treefmtEval.${pkgs.system}.config.build.wrapper); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,13 @@ | ||
{ pkgs ? import <nixpkgs> {} }: | ||
|
||
with pkgs; | ||
|
||
mkShell { | ||
packages = with pkgs; [ nix-prefetch-github ]; | ||
inputsFrom = [ (import ./default.nix {}).m8c-dev ]; | ||
} | ||
(import | ||
( | ||
let | ||
lock = builtins.fromJSON (builtins.readFile ./flake.lock); | ||
in | ||
fetchTarball { | ||
url = "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz"; | ||
sha256 = lock.nodes.flake-compat.locked.narHash; | ||
} | ||
) | ||
{ | ||
src = ./.; | ||
}).shellNix |