Skip to content

flake: add package for Nix #600

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@ deb/usr
*.prof
*.db*
*.log
.direnv
result
72 changes: 66 additions & 6 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -1,19 +1,78 @@
{
description = "Gomuks development environment";
description = "Gomuks development environment & packages";

inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
};

outputs = { self, nixpkgs, flake-utils }:
(flake-utils.lib.eachDefaultSystem (system:
outputs =
{
self,
nixpkgs,
flake-utils,
...
}:
flake-utils.lib.eachDefaultSystem (
system:
let
pkgs = import nixpkgs {
inherit system;
config.permittedInsecurePackages = [ "olm-3.2.16" ];
config = {
permittedInsecurePackages = [ "olm-3.2.16" ];
};
};

outPackages = self.outputs.packages.${system};

# Extract version from version.go
versionContent = builtins.readFile ./version/version.go;
versionMatch = builtins.match ''^.*const StaticVersion = "([0-9\.]+)".*$'' versionContent;
version = builtins.elemAt versionMatch 0;
in
{
packages = {
gomuks = pkgs.buildGoModule {
pname = "gomuks";
inherit version;

src = ./.;

# Go dependency hash (should be updated when dependencies are)
Copy link
Contributor

Choose a reason for hiding this comment

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

The reason I didn't add a package to the flake was because of this. I don't want to have to make a PR every time we update dependencies.

Copy link
Author

Choose a reason for hiding this comment

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

I would say, small price to pay, or maybe it'd even be possible to update this in the same commit when updating dependencies (though, of course, that puts more work on Tulir). If that is unacceptable - a quick search lead me to gomod2nix, which might not have this requirement.(?)

Copy link
Contributor

Choose a reason for hiding this comment

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

Tulir doesn't use nix. I know from experience that it is very annoying to manage the vendor hash even when using nix. I forget to update the hash consistently on my own projects.

vendorHash = "sha256-oViJGEdep4vk38EwygkUXy51NRdvndJqlXZOxWYCbv4=";

buildInputs = with pkgs; [
outPackages.gomuks-web
olm
];

preBuild = ''
cp -r ${outPackages.gomuks-web}/dist web/dist
'';

# skip non-existant & broken pytest tests
pytestCheckPhase = '':'';

subPackages = [ "cmd/gomuks" ];
};
# Package for building web dist
gomuks-web = pkgs.buildNpmPackage rec {
pname = "gomuks-web";
inherit version;

src = ./web;

# Same as the Go dependency hash but for NPM packages
npmDepsHash = "sha256-tPRgzp6c9zXbHQIEPf4gEKkBWWzQAfUCNAijYPdONpM=";

installPhase = ''
mkdir -p $out/dist
cp -r dist/* $out/dist/
'';
};
default = outPackages.gomuks;
};
in {

devShells = {
default = pkgs.mkShell {
packages = with pkgs; [
Expand All @@ -37,5 +96,6 @@
];
};
};
}));
}
);
}