Skip to content

Commit d731a8f

Browse files
authored
Merge pull request #160 from pope/main
Use a Nix Flake for m8c
2 parents b956da8 + 9e6cbaf commit d731a8f

File tree

6 files changed

+220
-59
lines changed

6 files changed

+220
-59
lines changed

.github/workflows/nix-package.yml

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Update Version and Hash in default.nix
1+
name: Update Version and Hash in flake.nix
22

33
on:
44
push:
@@ -42,15 +42,15 @@ jobs:
4242
echo "valid=false" >> $GITHUB_OUTPUT
4343
fi
4444
45-
- name: Update version in default.nix
45+
- name: Update version in flake.nix
4646
if: steps.valid-tag.outputs.valid
4747
run: |
4848
latest_annotated_tag="${{ steps.newest-tag.outputs.latest_annotated_tag }}"
4949
latest_annotated_tag_without_v="${latest_annotated_tag#v}" # Remove 'v' prefix
50-
sed -i "s/version = \".*\";/version = \"$latest_annotated_tag_without_v\";/" default.nix
50+
sed -i "s/version = \".*\";/version = \"$latest_annotated_tag_without_v\";/" flake.nix
5151
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
52-
sed -i "s/hash = \".*\";/hash = \"sha256:$new_hash\";/" default.nix
52+
sed -i "s/hash = \".*\";/hash = \"sha256:$new_hash\";/" flake.nix
5353
git config user.email "[email protected]"
5454
git config user.name "GitHub Actions"
55-
git commit -am "Update version and hash in default.nix to $latest_annotated_tag_without_v"
55+
git commit -am "Update version and hash in flake.nix to $latest_annotated_tag_without_v"
5656
git push origin HEAD:main

README.md

+6
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@ sudo dnf install m8c
4343
nix-env -iA m8c-stable -f https://github.com/laamaa/m8c/archive/refs/heads/main.tar.gz
4444
```
4545

46+
Or if you're using flakes and the nix command, you can run the app directly with:
47+
48+
```sh
49+
nix run github:laamaa/m8c
50+
```
51+
4652
### Building from source code
4753

4854
#### Install dependencies

default.nix

+17-46
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,18 @@
1-
{ pkgs ? import <nixpkgs> {} }:
2-
3-
with pkgs;
4-
5-
# HOWTO keep this package definition up-to-date:
6-
#
7-
# 1. NEW VERSION:
8-
# After the new version is tagged and pushed, update the `version` var to the
9-
# proper value and update the hash. You can use the following command to find
10-
# out the sha256, for example, with version 1.0.3:
11-
# `nix-prefetch-github --rev v1.0.3 laamaa m8c`
12-
#
13-
# 2. NEW DEPENDENCIES:
14-
# Make sure new dependencies are added. Runtime deps go to buildInputs and
15-
# compile-time deps go to nativeBuildInputs. Use the nixpkgs manual for help
16-
#
17-
let m8c-package =
18-
{ stdenv
19-
, gnumake
20-
, pkg-config
21-
, SDL2
22-
, libserialport
23-
, fetchFromGitHub
24-
}:
25-
26-
let
27-
pname = "m8c";
28-
version = "1.7.6";
29-
in
30-
stdenv.mkDerivation {
31-
inherit pname version;
32-
33-
src = fetchFromGitHub {
34-
owner = "laamaa";
35-
repo = pname;
36-
rev = "v${version}";
37-
hash = "sha256:1b2wg8zmxisn1kc3wkfzcij1707pz560yq8v6rwjirr0dd27a3n2";
38-
};
39-
40-
installFlags = [ "PREFIX=$(out)" ];
41-
nativeBuildInputs = [ gnumake pkg-config ];
42-
buildInputs = [ SDL2 libserialport ];
43-
};
44-
in {
45-
m8c-stable = pkgs.callPackage m8c-package {};
46-
m8c-dev = (pkgs.callPackage m8c-package {}).overrideAttrs (oldAttrs: {src = ./.;});
1+
let
2+
pkgs = (import
3+
(
4+
let
5+
lock = builtins.fromJSON (builtins.readFile ./flake.lock);
6+
in
7+
fetchTarball {
8+
url = "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz";
9+
sha256 = lock.nodes.flake-compat.locked.narHash;
10+
}
11+
)
12+
{
13+
src = ./.;
14+
}).defaultNix.packages.${builtins.currentSystem};
15+
in
16+
{
17+
inherit (pkgs) m8c-stable m8c-dev;
4718
}

flake.lock

+81
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

+98
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
{
2+
inputs = {
3+
nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.05";
4+
systems.url = "github:nix-systems/default";
5+
treefmt-nix = {
6+
url = "github:numtide/treefmt-nix";
7+
inputs.nixpkgs.follows = "nixpkgs";
8+
};
9+
flake-compat = {
10+
url = "github:edolstra/flake-compat";
11+
flake = false;
12+
};
13+
};
14+
15+
outputs = { self, nixpkgs, systems, treefmt-nix, ... }:
16+
let
17+
# HOWTO keep this package definition up-to-date:
18+
#
19+
# 1. NEW VERSION:
20+
# After the new version is tagged and pushed, update the `version` var to the
21+
# proper value and update the hash. You can use the following command to find
22+
# out the sha256, for example, with version 1.0.3:
23+
# `nix-prefetch-github --rev v1.0.3 laamaa m8c`
24+
#
25+
# 2. NEW DEPENDENCIES:
26+
# Make sure new dependencies are added. Runtime deps go to buildInputs and
27+
# compile-time deps go to nativeBuildInputs. Use the nixpkgs manual for help
28+
pname = "m8c";
29+
version = "1.7.6";
30+
m8c-package =
31+
{ stdenv
32+
, gnumake
33+
, pkg-config
34+
, SDL2
35+
, libserialport
36+
, fetchFromGitHub
37+
}:
38+
stdenv.mkDerivation {
39+
inherit pname version;
40+
41+
src = fetchFromGitHub {
42+
owner = "laamaa";
43+
repo = pname;
44+
rev = "v${version}";
45+
hash = "sha256:1b2wg8zmxisn1kc3wkfzcij1707pz560yq8v6rwjirr0dd27a3n2";
46+
};
47+
48+
installFlags = [ "PREFIX=$(out)" ];
49+
nativeBuildInputs = [ gnumake pkg-config ];
50+
buildInputs = [ SDL2 libserialport ];
51+
};
52+
eachSystem = f: nixpkgs.lib.genAttrs (import systems) (system: f
53+
(import nixpkgs { inherit system; })
54+
);
55+
treefmtEval = eachSystem (pkgs: treefmt-nix.lib.evalModule pkgs (_: {
56+
projectRootFile = "flake.nix";
57+
programs = {
58+
clang-format.enable = false; # TODO(pope): Enable and format C code
59+
deadnix.enable = true;
60+
nixpkgs-fmt.enable = true;
61+
statix.enable = true;
62+
};
63+
}));
64+
in
65+
{
66+
packages = eachSystem (pkgs: rec {
67+
m8c-stable = pkgs.callPackage m8c-package { };
68+
m8c-dev = (pkgs.callPackage m8c-package { }).overrideAttrs (_oldAttrs: {
69+
src = ./.;
70+
});
71+
default = m8c-stable;
72+
});
73+
74+
overlays.default = final: _prev: {
75+
inherit (self.packages.${final.system}) m8c-stable m8c-dev;
76+
};
77+
78+
apps = eachSystem (pkgs: rec {
79+
m8c = {
80+
type = "app";
81+
program = "${self.packages.${pkgs.system}.m8c-stable}/bin/m8c";
82+
};
83+
default = m8c;
84+
});
85+
86+
devShells = eachSystem (pkgs: with pkgs; {
87+
default = mkShell {
88+
packages = [
89+
nix-prefetch-github
90+
treefmtEval.${system}.config.build.wrapper
91+
];
92+
inputsFrom = [ self.packages.${system}.m8c-dev ];
93+
};
94+
});
95+
96+
formatter = eachSystem (pkgs: treefmtEval.${pkgs.system}.config.build.wrapper);
97+
};
98+
}

shell.nix

+13-8
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
1-
{ pkgs ? import <nixpkgs> {} }:
2-
3-
with pkgs;
4-
5-
mkShell {
6-
packages = with pkgs; [ nix-prefetch-github ];
7-
inputsFrom = [ (import ./default.nix {}).m8c-dev ];
8-
}
1+
(import
2+
(
3+
let
4+
lock = builtins.fromJSON (builtins.readFile ./flake.lock);
5+
in
6+
fetchTarball {
7+
url = "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz";
8+
sha256 = lock.nodes.flake-compat.locked.narHash;
9+
}
10+
)
11+
{
12+
src = ./.;
13+
}).shellNix

0 commit comments

Comments
 (0)