Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for NixOS #130

Merged
merged 1 commit into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,6 @@ pyramid-incorrect.dat

# macOS
.DS_Store

# Nix
result
78 changes: 78 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

47 changes: 47 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
description = "Open-source Star Tracker";

inputs = {
nixpkgs.url = "github:nixos/nixpkgs/release-24.05";
flake-utils.url = "github:numtide/flake-utils";

flake-compat = {
url = "github:edolstra/flake-compat";
flake = false;
};
};

outputs = inputs@{ self, nixpkgs, flake-utils, ... }:
let
overlays = [
(final: prev: rec { lost = prev.callPackage ./nix/package.nix { }; })
];
in flake-utils.lib.eachDefaultSystem (system:
let pkgs = import nixpkgs { inherit overlays system; };
in {
packages.default = pkgs.lost;
packages.lost = pkgs.lost;

devShells.default = pkgs.mkShell {
packages = with pkgs; [
gcc
clang-tools
gnumake
bear
gdb
valgrind
man
groff
imagemagick
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we have imagemagick, graphviz, clang-tools, and bear in here? I realize they may be useful for debugging LOST, does nix have a more idiomatic way of saying "create a development shell for this project, except also install these packages" rather than hardcoding potentially-useful dependencies into this flake file?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These all do go into the devShell. The actual binary is built using the nix/package.nix where we define nativeBuildInputs (dependencies for building) and buildInputs (runtime dependencies).

cpplint
doxygen
graphviz
unixtools.xxd
eigen
cairo
];
};

devShell = self.devShells.${system}.default;
});
}
29 changes: 29 additions & 0 deletions nix/package.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{ stdenv, pkgs, lib }:

stdenv.mkDerivation rec {
pname = "lost";
version = "0.1.0";

src = ./..;

nativeBuildInputs = with pkgs; [ gcc gnumake groff unixtools.xxd eigen ];

buildInputs = with pkgs; [ cairo ];

dontConfigure = true;

buildPhase = ''
make release
'';

installPhase = ''
mkdir -p $out/bin
mv lost $out/bin/
'';

meta = with lib; {
description = "Open-source Star Tracker";
homepage = "https://github.com/uwcubesat/lost";
license = licenses.mit;
};
}
12 changes: 12 additions & 0 deletions shell.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
(import
(
let
flake-compat = (builtins.fromJSON (builtins.readFile ./flake.lock)).nodes.flake-compat;
in
fetchTarball {
url = "https://github.com/edolstra/flake-compat/archive/${flake-compat.locked.rev}.tar.gz";
sha256 = flake-compat.locked.narHash;
}
)
{src = ./.;})
.shellNix
Loading